From b996a9d91ce6a15b51cec21eadda2a0793f16a5c Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Sat, 22 Jul 2023 09:13:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BE=A4=E6=B6=88=E6=81=AF=E7=BD=AE?= =?UTF-8?q?=E9=A1=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/3.9.5.81.md | 90 +++++++++++++++++++++++++++++++++++++ src/db.cc | 1 + src/http_server_callback.cc | 17 +++++++ src/manager.cc | 30 +++++++++++++ src/manager.h | 2 + src/wechat_function.h | 6 +++ 6 files changed, 146 insertions(+) diff --git a/doc/3.9.5.81.md b/doc/3.9.5.81.md index fa053a0..5c6899a 100644 --- a/doc/3.9.5.81.md +++ b/doc/3.9.5.81.md @@ -736,4 +736,94 @@ enableHttp=0时,使用ip,port的tcp服务回传消息。 }, "msg": "success" } +``` + +#### 14.置顶群消息** +###### 接口功能 +> 置顶群消息,需要群主权限 + +###### 接口地址 +> [/api/topMsg](/api/topMsg) + +###### HTTP请求方式 +> POST JSON + +###### 请求参数 +|参数|必选|类型|说明| +|---|---|---|---| +|msgId |true |string| 消息id | + + + +###### 返回字段 +|返回字段|字段类型|说明 | +|---|---|---| +|code|int|返回状态,1成功, -1失败| +|msg|string|成功提示| +|data|object|null| + + +###### 接口示例 + +入参: +``` javascript + + +{ + "msgId":8005736725060623215 +} +``` +响应: +``` javascript +{ + "code": 1, + "data": null, + "msg": "success" +} +``` + + +#### 15.移除置顶群消息** +###### 接口功能 +> 移除置顶群消息,需要群主权限 + +###### 接口地址 +> [/api/removeTopMsg](/api/removeTopMsg) + +###### HTTP请求方式 +> POST JSON + +###### 请求参数 +|参数|必选|类型|说明| +|---|---|---|---| +|msgId |true |string| 消息id | +|chatRoomId |true |string| 群id | + + +###### 返回字段 +|返回字段|字段类型|说明 | +|---|---|---| +|code|int|返回状态,1成功, -1失败| +|msg|string|成功提示| +|data|object|null| + + +###### 接口示例 + +入参: +``` javascript + + +{ + "msgId":8005736725060623215, + "chatRoomId":"12345678@chatroom" +} +``` +响应: +``` javascript +{ + "code": 1, + "data": null, + "msg": "success" +} ``` \ No newline at end of file diff --git a/src/db.cc b/src/db.cc index bee18c0..b667d6c 100644 --- a/src/db.cc +++ b/src/db.cc @@ -344,6 +344,7 @@ std::vector DB::GetDbHandles() { msg0_db.db_name = (wchar_t *)(*(UINT64 *)(db_addr)); msg0_db.db_name_len = *(DWORD *)(db_addr + 0x8); msg0_db.handle = msg0_db_addr; + msg0_db.extrainfo = *(UINT64 *)(*(UINT64 *)(db_addr + 0x28) + 0x1E8); ExecuteSQL(msg0_db_addr, "select * from sqlite_master where type=\"table\";", (UINT64)GetDbInfo, &msg0_db); diff --git a/src/http_server_callback.cc b/src/http_server_callback.cc index 0caf487..9b4dd4b 100644 --- a/src/http_server_callback.cc +++ b/src/http_server_callback.cc @@ -341,6 +341,23 @@ std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) { } ret = ret_data.dump(); return ret; + } else if (mg_http_match_uri(hm, "/api/topMsg")) { + INT64 msg_id = GetINT64Param(j_param, "msgId"); + INT64 success = + wxhelper::GlobalContext::GetInstance().mgr->SetTopMsg(msg_id); + nlohmann::json ret_data = { + {"code", success}, {"msg", "success"}, {"data", {}}}; + ret = ret_data.dump(); + return ret; + } else if (mg_http_match_uri(hm, "/api/removeTopMsg")) { + std::wstring room_id = GetWStringParam(j_param, "chatRoomId"); + INT64 msg_id = GetINT64Param(j_param, "msgId"); + INT64 success = + wxhelper::GlobalContext::GetInstance().mgr->RemoveTopMsg(room_id,msg_id); + nlohmann::json ret_data = { + {"code", success}, {"msg", "success"}, {"data", {}}}; + ret = ret_data.dump(); + return ret; } else { nlohmann::json ret_data = { {"code", 200}, {"data", {}}, {"msg", "not support url"}}; diff --git a/src/manager.cc b/src/manager.cc index 9e516f9..19a285d 100644 --- a/src/manager.cc +++ b/src/manager.cc @@ -3,6 +3,7 @@ #include "export.h" #include "wechat_function.h" +#include "db.h" namespace offset = wxhelper::V3_9_5_81::offset; namespace prototype = wxhelper::V3_9_5_81::prototype; @@ -500,4 +501,33 @@ INT64 Manager::GetMemberFromChatRoom(const std::wstring &room_id, free_chat_room(addr); return success; } +INT64 Manager::SetTopMsg(ULONG64 msg_id) { + INT64 success = -1; + UINT64 top_addr = base_addr_ + offset::kTopMsg; + func::__DoTopMsg top_msg = (func::__DoTopMsg)top_addr; + INT64 index = 0; + INT64 local_id = DB::GetInstance().GetLocalIdByMsgId(msg_id, index); + if (local_id <= 0 || index >> 32 == 0) { + success = -2; + return success; + } + LARGE_INTEGER l; + l.HighPart = index >> 32; + l.LowPart = (DWORD)local_id; + UINT64 ptr = reinterpret_cast(&l); + success = top_msg(ptr, 1); + + return success; +} + +INT64 Manager::RemoveTopMsg(const std::wstring &room_id, ULONG64 msg_id) { + INT64 success = -1; + UINT64 remove_addr = base_addr_ + offset::kRemoveTopMsg; + func::__RemoveTopMsg remove_top_msg = (func::__RemoveTopMsg)remove_addr; + prototype::WeChatString *chat_room_id = BuildWechatString(room_id); + const wchar_t *w_room = room_id.c_str(); + success = remove_top_msg(reinterpret_cast(w_room), msg_id, + reinterpret_cast(chat_room_id)); + return success; +} } // namespace wxhelper \ No newline at end of file diff --git a/src/manager.h b/src/manager.h index e7aeadd..2dba73d 100644 --- a/src/manager.h +++ b/src/manager.h @@ -25,6 +25,8 @@ class Manager { const std::vector& members); INT64 GetMemberFromChatRoom(const std::wstring& room_id, common::ChatRoomMemberInner& member); + INT64 SetTopMsg(ULONG64 msg_id); + INT64 RemoveTopMsg(const std::wstring& room_id,ULONG64 msg_id); private: UINT64 base_addr_; diff --git a/src/wechat_function.h b/src/wechat_function.h index 9d96751..26ee6b3 100644 --- a/src/wechat_function.h +++ b/src/wechat_function.h @@ -233,6 +233,8 @@ typedef UINT64 (*__GetMemberFromChatRoom)(UINT64,UINT64,UINT64); typedef UINT64 (*__NewChatRoom)(UINT64); typedef UINT64 (*__FreeChatRoom)(UINT64); +typedef UINT64 (*__DoTopMsg)(UINT64,UINT64); +typedef UINT64 (*__RemoveTopMsg)(UINT64,UINT64,UINT64); } // namespace function namespace prototype { @@ -329,6 +331,10 @@ const UINT64 kDelMemberFromChatRoom = 0xe64290; const UINT64 kGetMemberFromChatRoom = 0xe74de0; const UINT64 kNewChatRoom = 0x11fde50; const UINT64 kFreeChatRoom = 0x11fe030; + +const UINT64 kTopMsg = 0xa5e4f0; +const UINT64 kRemoveTopMsg = 0xe787b0; + } // namespace offset } // namespace V3_9_5_81