From 2ed409e7b0bca6ff3a5af4920396a9dec3841e67 Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Fri, 14 Jul 2023 22:25:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BE=A4=E5=8A=9F=E8=83=BD=E7=9B=B8?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/3.9.5.81.md | 95 +++++++++++++++++++++++++++++++++++++ src/http_server_callback.cc | 34 +++++++++++++ src/manager.cc | 58 +++++++++++++++++++++- src/manager.h | 4 ++ src/wechat_function.h | 22 +++++++++ 5 files changed, 212 insertions(+), 1 deletion(-) diff --git a/doc/3.9.5.81.md b/doc/3.9.5.81.md index 72785f1..fa053a0 100644 --- a/doc/3.9.5.81.md +++ b/doc/3.9.5.81.md @@ -641,4 +641,99 @@ enableHttp=0时,使用ip,port的tcp服务回传消息。 响应: ``` javascript {"code":1,"msg":"success","data":null} +``` + +#### 12.删除群成员** +###### 接口功能 +> 删除群成员 + +###### 接口地址 +> [/api/delMemberFromChatRoom](/api/delMemberFromChatRoom) + +###### HTTP请求方式 +> POST JSON + +###### 请求参数 +|参数|必选|类型|说明| +|---|---|---|---| +|chatRoomId |true |string| 群id | +|memberIds |true |string| 成员id,用,分隔 | + + + +###### 返回字段 +|返回字段|字段类型|说明 | +|---|---|---| +|code|int|返回状态,1成功, -1失败| +|msg|string|成功提示| +|data|object|null| + + +###### 接口示例 + +入参: +``` javascript + +{ + "chatRoomId":"1234@chatroom", + "memberIds":"wxid_123" +} +``` +响应: +``` javascript +{"code":1,"msg":"success","data":null} +``` + + +#### 13.获取群成员** +###### 接口功能 +> 获取群成员 + +###### 接口地址 +> [/api/getMemberFromChatRoom](/api/getMemberFromChatRoom) + +###### HTTP请求方式 +> POST JSON + +###### 请求参数 +|参数|必选|类型|说明| +|---|---|---|---| +|chatRoomId |true |string| 群id | + + + +###### 返回字段 +|返回字段|字段类型|说明 | +|---|---|---| +|code|int|返回状态,1成功, -1失败| +|msg|string|成功提示| +|data|object|null| +|  chatRoomId|string|群id| +|  members|string|成员id| +|  memberNickname|string|成员昵称| +|  admin|string|群管理| +|  adminNickname|string|管理昵称| + +###### 接口示例 + +入参: +``` javascript + +{ + "chatRoomId":"1234@chatroom" +} +``` +响应: +``` javascript +{ + "code": 1, + "data": { + "admin": "wxid_2222", + "adminNickname": "123", + "chatRoomId": "22224@chatroom", + "memberNickname": "^G123^G^G", + "members": "wxid_2222^Gwxid_333" + }, + "msg": "success" +} ``` \ No newline at end of file diff --git a/src/http_server_callback.cc b/src/http_server_callback.cc index 367355b..0caf487 100644 --- a/src/http_server_callback.cc +++ b/src/http_server_callback.cc @@ -307,6 +307,40 @@ std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) { {"code", success}, {"msg", "success"}, {"data", {}}}; ret = ret_data.dump(); return ret; + } else if (mg_http_match_uri(hm, "/api/delMemberFromChatRoom")) { + std::wstring room_id = GetWStringParam(j_param, "chatRoomId"); + std::vector wxids = GetArrayParam(j_param, "memberIds"); + std::vector wxid_list; + for (unsigned int i = 0; i < wxids.size(); i++) { + wxid_list.push_back(wxids[i]); + } + INT64 success = + wxhelper::GlobalContext::GetInstance().mgr->DelMemberFromChatRoom( + room_id, wxid_list); + nlohmann::json ret_data = { + {"code", success}, {"msg", "success"}, {"data", {}}}; + ret = ret_data.dump(); + return ret; + } else if (mg_http_match_uri(hm, "/api/getMemberFromChatRoom")) { + std::wstring room_id = GetWStringParam(j_param, "chatRoomId"); + common::ChatRoomMemberInner member; + INT64 success = + wxhelper::GlobalContext::GetInstance().mgr->GetMemberFromChatRoom( + room_id, member); + nlohmann::json ret_data = { + {"code", success}, {"msg", "success"}, {"data", {}}}; + if (success >= 0) { + nlohmann::json member_info = { + {"admin", member.admin}, + {"chatRoomId", member.chat_room_id}, + {"members", member.member}, + {"adminNickname", member.admin_nickname}, + {"memberNickname", member.member_nickname}, + }; + ret_data["data"] = member_info; + } + 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 a7383a3..9e516f9 100644 --- a/src/manager.cc +++ b/src/manager.cc @@ -444,4 +444,60 @@ INT64 Manager::ModChatRoomMemberNickName(const std::wstring &room_id, reinterpret_cast(self_id), reinterpret_cast(name)); return success; } -} // namespace wxhelper` \ No newline at end of file + +INT64 Manager::DelMemberFromChatRoom(const std::wstring &room_id, + const std::vector &members) { + INT64 success = -1; + UINT64 get_chat_room_mgr_addr = base_addr_ + offset::kChatRoomMgr; + UINT64 del_members_addr = base_addr_ + offset::kDelMemberFromChatRoom; + func::__GetChatRoomMgr get_chat_room_mgr = + (func::__GetChatRoomMgr)get_chat_room_mgr_addr; + func::__DoDelMemberFromChatRoom del_members = + (func::__DoDelMemberFromChatRoom)del_members_addr; + + prototype::WeChatString *chat_room_id = BuildWechatString(room_id); + std::vector member_list; + UINT64 temp[2] = {0}; + common::VectorInner *list = (common::VectorInner *)&member_list; + INT64 members_ptr = (INT64)&list->start; + for (int i = 0; i < members.size(); i++) { + prototype::WeChatString member(members[i]); + member_list.push_back(member); + } + UINT64 mgr = get_chat_room_mgr(); + success = + del_members(mgr, members_ptr, reinterpret_cast(chat_room_id)); + return success; +} + +INT64 Manager::GetMemberFromChatRoom(const std::wstring &room_id, + common::ChatRoomMemberInner &member) { + INT64 success = -1; + UINT64 get_chat_room_mgr_addr = base_addr_ + offset::kChatRoomMgr; + UINT64 get_members_addr = base_addr_ + offset::kGetMemberFromChatRoom; + UINT64 new_chat_room_addr = base_addr_ + offset::kNewChatRoom; + UINT64 free_chat_room_addr = base_addr_ + offset::kFreeChatRoom; + func::__GetChatRoomMgr get_chat_room_mgr = + (func::__GetChatRoomMgr)get_chat_room_mgr_addr; + func::__GetMemberFromChatRoom get_members = + (func::__GetMemberFromChatRoom)get_members_addr; + func::__NewChatRoom new_chat_room = (func::__NewChatRoom)new_chat_room_addr; + func::__FreeChatRoom free_chat_room = + (func::__FreeChatRoom)free_chat_room_addr; + + prototype::WeChatString chat_room_id(room_id); + char chat_room_info[0x2E0] = {0}; + UINT64 addr = reinterpret_cast(&chat_room_info); + new_chat_room(addr); + + UINT64 mgr = get_chat_room_mgr(); + success = get_members(mgr, reinterpret_cast(&chat_room_id), addr); + member.chat_room_id = Utils::ReadWstringThenConvert(addr + 0x10); + member.admin = Utils::ReadWstringThenConvert(addr + 0x78); + member.member_nickname = Utils::ReadWstringThenConvert(addr + 0x50); + member.admin_nickname = Utils::ReadWstringThenConvert(addr + 0xA0); + member.member = Utils::ReadWeChatStr(addr + 0x30); + free_chat_room(addr); + return success; +} +} // namespace wxhelper \ No newline at end of file diff --git a/src/manager.h b/src/manager.h index 24ff368..e7aeadd 100644 --- a/src/manager.h +++ b/src/manager.h @@ -21,6 +21,10 @@ class Manager { INT64 ModChatRoomMemberNickName(const std::wstring& room_id, const std::wstring& wxid, const std::wstring& nickname); + INT64 DelMemberFromChatRoom(const std::wstring& room_id, + const std::vector& members); + INT64 GetMemberFromChatRoom(const std::wstring& room_id, + common::ChatRoomMemberInner& member); private: UINT64 base_addr_; diff --git a/src/wechat_function.h b/src/wechat_function.h index 4a70d68..9d96751 100644 --- a/src/wechat_function.h +++ b/src/wechat_function.h @@ -184,6 +184,20 @@ struct VectorInner { INT64 end; }; +struct ChatRoomMemberInner { + std::string chat_room_id; + std::string admin; + std::string admin_nickname; + std::string member_nickname; + std::string member; + ChatRoomMemberInner() + : chat_room_id(""), + admin(""), + admin_nickname(""), + member_nickname(""), + member("") {} +}; + } // namespace common namespace V3_9_5_81 { namespace function { @@ -214,6 +228,10 @@ typedef UINT64 (*__GetChatRoomDetailInfo)(UINT64,UINT64,UINT64,UINT64); typedef UINT64 (*__DoAddMemberToChatRoom)(UINT64,UINT64,UINT64,UINT64); typedef UINT64 (*__DoModChatRoomMemberNickName)(UINT64,UINT64,UINT64,UINT64); +typedef UINT64 (*__DoDelMemberFromChatRoom)(UINT64,UINT64,UINT64); +typedef UINT64 (*__GetMemberFromChatRoom)(UINT64,UINT64,UINT64); +typedef UINT64 (*__NewChatRoom)(UINT64); +typedef UINT64 (*__FreeChatRoom)(UINT64); } // namespace function @@ -307,6 +325,10 @@ const UINT64 kNewChatRoomInfo = 0x12006b0; const UINT64 kFreeChatRoomInfo = 0x1200890; const UINT64 kDoAddMemberToChatRoom = 0xe63c70; const UINT64 kDoModChatRoomMemberNickName = 0xe6db00; +const UINT64 kDelMemberFromChatRoom = 0xe64290; +const UINT64 kGetMemberFromChatRoom = 0xe74de0; +const UINT64 kNewChatRoom = 0x11fde50; +const UINT64 kFreeChatRoom = 0x11fe030; } // namespace offset } // namespace V3_9_5_81