发送@消息

This commit is contained in:
hugy 2023-03-02 11:38:47 +08:00
parent 7e89c6ef2d
commit b8dc032525
5 changed files with 128 additions and 1 deletions

View File

@ -259,6 +259,47 @@ vcpkg
#### 3.发送@文本消息**
###### 接口功能
> 发送@文本消息
###### 接口地址
> [/api/?type=3](/api/?type=3)
###### HTTP请求方式
> POST JSON
###### 请求参数
|参数|必选|类型|说明|
|---|---|---|---|
|chatRoomId |true |string| 群id |
|msg|true |string|消息文本内容|
|wxids |true |string| @的用户微信id用,号分隔, @所有人 传 notify@all ,区分大小写 |
###### 返回字段
|返回字段|字段类型|说明 |
|---|---|---|
|code|int|返回状态,不为0成功, 0失败|
|result|string|成功提示|
###### 接口示例
入参:
``` javascript
{
"chatRoomId": "123333@chatroom",
"wxids":"notify@all,wxid_122221",
"msg": "12333"
}
```
响应:
``` javascript
{"code":345686720,"result":"OK"}
```
#### 5.发送图片消息**
###### 接口功能
> 发送图片消息

View File

@ -240,6 +240,16 @@ void api_handle(mg_http_message *hm, struct mg_connection *c, string &ret) {
break;
}
case WECHAT_MSG_SEND_AT: {
wstring chat_room_id = get_http_req_param(hm, j_param, "chatRoomId", is_post);
vector<wstring> wxids = get_http_param_array(hm, j_param, "wxids", is_post);
wstring msg = get_http_req_param(hm, j_param, "msg", is_post);
vector<wchar_t *> wxid_list;
for (unsigned int i = 0; i < wxids.size(); i++){
wxid_list.push_back(WS2LW(wxids[i]));
}
int success = SendAtText(WS2LW(chat_room_id), wxid_list.data(), wxid_list.size(),WS2LW(msg));
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_MSG_SEND_CARD: {

View File

@ -4,12 +4,14 @@
#include "common.h"
#include "wechat_data.h"
#include "contact.h"
#define WX_SEND_TEXT_OFFSET 0xc71a60
#define WX_SEND_MESSAGE_MGR_OFFSET 0x706d30
#define WX_FREE_CHAT_MSG_OFFSET 0x6f4ea0
using namespace std;
/// @brief 发生文本消息
/// @param wxid wxid
/// @param msg 文本消息
@ -46,3 +48,71 @@ int SendText(wchar_t* wxid, wchar_t* msg) {
}
return success;
}
int SendAtText(wchar_t* chat_room_id,wchar_t** wxids,int len,wchar_t* msg){
int success = -1;
WeChatString * at_users = new WeChatString[len+1];
wstring at_msg = L"";
int number =0;
for (int i = 0; i < len; i++) {
wstring nickname;
if (!lstrcmpiW((wchar_t *)wxids[i], (wchar_t *)L"notify@all")) {
nickname = L"ËùÓÐÈË";
} else {
nickname = GetContactOrChatRoomNickname(wxids[i]);
}
if (nickname.length() == 0) {
continue;
}
WeChatString temp = {0};
temp.ptr = (wchar_t *)wxids[i];
temp.length = wcslen((wchar_t *)wxids[i]);
temp.max_length = wcslen((wchar_t *)wxids[i]) * 2;
memcpy(&at_users[number], &temp, sizeof(WeChatString));
at_msg = at_msg + L"@" + nickname + L" ";
number++;
}
if (number < 1){
return success;
}
wstring origin(msg);
at_msg += origin;
AtInner at_list = {0};
at_list.start = (DWORD)at_users;
at_list.finsh = (DWORD)&at_users[number];
at_list.end = (DWORD)&at_users[number];
WeChatString to_user(chat_room_id);
WeChatString text_msg((wchar_t *)at_msg.c_str());
wchar_t **msg_pptr = &text_msg.ptr;
DWORD base = GetWeChatWinBase();
DWORD send_message_mgr_addr = base + WX_SEND_MESSAGE_MGR_OFFSET;
DWORD send_text_msg_addr = base + WX_SEND_TEXT_OFFSET;
DWORD free_chat_msg_addr = base + WX_FREE_CHAT_MSG_OFFSET;
char chat_msg[0x2C4] ={0};
__asm{
PUSHAD
CALL send_message_mgr_addr
PUSH 0x0
PUSH 0x0
PUSH 0x0
PUSH 0x1
LEA EAX,at_list
PUSH EAX
MOV EAX,msg_pptr
PUSH EAX
LEA EDX,to_user
LEA ECX,chat_msg
CALL send_text_msg_addr
MOV success,EAX
ADD ESP,0x18
LEA ECX,chat_msg
CALL free_chat_msg_addr
POPAD
}
return success;
}

View File

@ -2,5 +2,5 @@
#define SEND_TEXT_H_
int SendText(wchar_t* wxid, wchar_t* msg);
int SendAtText(wchar_t* chat_room_id,wchar_t** wxids,int len,wchar_t* msg);
#endif

View File

@ -180,4 +180,10 @@ struct UserInfo {
DWORD sex;
BOOL over;
};
struct AtInner{
DWORD start;
DWORD finsh;
DWORD end;
};
#endif