Impl SendTextMessage and SendImageMessage
This commit is contained in:
parent
95ce4578bf
commit
d6633c3aed
@ -156,6 +156,56 @@ bool func_get_db_tables(char *db, uint8_t *out, size_t *len)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool func_send_txt(TextMsg txt, uint8_t *out, size_t *len)
|
||||||
|
{
|
||||||
|
Response rsp = Response_init_default;
|
||||||
|
rsp.func = Functions_FUNC_SEND_TXT;
|
||||||
|
rsp.which_msg = Response_status_tag;
|
||||||
|
rsp.msg.status = 0;
|
||||||
|
|
||||||
|
if ((txt.msg == NULL) || (txt.receiver == NULL)) {
|
||||||
|
rsp.msg.status = -1; // Empty message or empty receiver
|
||||||
|
} else {
|
||||||
|
string msg(txt.msg);
|
||||||
|
string receiver(txt.receiver);
|
||||||
|
string aters(txt.aters ? txt.aters : "");
|
||||||
|
|
||||||
|
SendTextMessage(String2Wstring(receiver), String2Wstring(msg), String2Wstring(aters));
|
||||||
|
}
|
||||||
|
|
||||||
|
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
|
||||||
|
if (!pb_encode(&stream, Response_fields, &rsp)) {
|
||||||
|
LOG_ERROR("Encoding failed: {}", PB_GET_ERROR(&stream));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*len = stream.bytes_written;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool func_send_img(char *path, char *receiver, uint8_t *out, size_t *len)
|
||||||
|
{
|
||||||
|
Response rsp = Response_init_default;
|
||||||
|
rsp.func = Functions_FUNC_SEND_IMG;
|
||||||
|
rsp.which_msg = Response_status_tag;
|
||||||
|
rsp.msg.status = 0;
|
||||||
|
|
||||||
|
if ((path == NULL) || (receiver == NULL)) {
|
||||||
|
rsp.msg.status = -1;
|
||||||
|
} else {
|
||||||
|
SendImageMessage(String2Wstring(receiver), String2Wstring(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
|
||||||
|
if (!pb_encode(&stream, Response_fields, &rsp)) {
|
||||||
|
LOG_ERROR("Encoding failed: {}", PB_GET_ERROR(&stream));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*len = stream.bytes_written;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool func_exec_db_query(char *db, char *sql, uint8_t *out, size_t *len)
|
bool func_exec_db_query(char *db, char *sql, uint8_t *out, size_t *len)
|
||||||
{
|
{
|
||||||
Response rsp = Response_init_default;
|
Response rsp = Response_init_default;
|
||||||
@ -219,6 +269,16 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len
|
|||||||
ret = func_get_db_tables(req.msg.str, out, out_len);
|
ret = func_get_db_tables(req.msg.str, out, out_len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Functions_FUNC_SEND_TXT: {
|
||||||
|
LOG_INFO("[Functions_FUNC_SEND_TXT]");
|
||||||
|
ret = func_send_txt(req.msg.txt, out, out_len);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Functions_FUNC_SEND_IMG: {
|
||||||
|
LOG_INFO("[Functions_FUNC_SEND_IMG]");
|
||||||
|
ret = func_send_img(req.msg.img.path, req.msg.txt.receiver, out, out_len);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Functions_FUNC_EXEC_DB_QUERY: {
|
case Functions_FUNC_EXEC_DB_QUERY: {
|
||||||
LOG_INFO("[Functions_FUNC_EXEC_DB_QUERY]");
|
LOG_INFO("[Functions_FUNC_EXEC_DB_QUERY]");
|
||||||
ret = func_exec_db_query(req.msg.query.db, req.msg.query.sql, out, out_len);
|
ret = func_exec_db_query(req.msg.query.db, req.msg.query.sql, out, out_len);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "framework.h"
|
#include <sstream>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -10,15 +9,13 @@ extern HANDLE g_hEvent;
|
|||||||
extern WxCalls_t g_WxCalls;
|
extern WxCalls_t g_WxCalls;
|
||||||
extern DWORD g_WeChatWinDllAddr;
|
extern DWORD g_WeChatWinDllAddr;
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
typedef struct AtList {
|
typedef struct AtList {
|
||||||
DWORD start;
|
DWORD start;
|
||||||
DWORD end1;
|
DWORD end1;
|
||||||
DWORD end2;
|
DWORD end2;
|
||||||
} AtList_t;
|
} AtList_t;
|
||||||
|
|
||||||
void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atWxids)
|
void SendTextMessage(wstring wxid, wstring msg, wstring atWxids)
|
||||||
{
|
{
|
||||||
char buffer[0x3B0] = { 0 };
|
char buffer[0x3B0] = { 0 };
|
||||||
AtList_t atList = { 0 };
|
AtList_t atList = { 0 };
|
||||||
@ -26,19 +23,16 @@ void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atW
|
|||||||
TextStruct_t txtWxid = { 0 };
|
TextStruct_t txtWxid = { 0 };
|
||||||
TextStruct_t *tsArray = NULL;
|
TextStruct_t *tsArray = NULL;
|
||||||
|
|
||||||
wstring wsMsg = msg;
|
|
||||||
wstring wsWxid = wxid;
|
|
||||||
|
|
||||||
// 发送消息Call地址 = 微信基址 + 偏移
|
// 发送消息Call地址 = 微信基址 + 偏移
|
||||||
DWORD sendCallAddress = g_WeChatWinDllAddr + g_WxCalls.sendTextMsg;
|
DWORD sendCallAddress = g_WeChatWinDllAddr + g_WxCalls.sendTextMsg;
|
||||||
|
|
||||||
txtMsg.text = (wchar_t *)wsMsg.c_str();
|
txtMsg.text = (wchar_t *)msg.c_str();
|
||||||
txtMsg.size = wsMsg.size();
|
txtMsg.size = msg.size();
|
||||||
txtMsg.capacity = wsMsg.capacity();
|
txtMsg.capacity = msg.capacity();
|
||||||
|
|
||||||
txtWxid.text = (wchar_t *)wsWxid.c_str();
|
txtWxid.text = (wchar_t *)wxid.c_str();
|
||||||
txtWxid.size = wsWxid.size();
|
txtWxid.size = wxid.size();
|
||||||
txtWxid.capacity = wsWxid.capacity();
|
txtWxid.capacity = wxid.capacity();
|
||||||
|
|
||||||
wstring tmp = atWxids;
|
wstring tmp = atWxids;
|
||||||
if (!tmp.empty()) {
|
if (!tmp.empty()) {
|
||||||
@ -84,7 +78,7 @@ void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atW
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendImageMessage(const wchar_t *wxid, const wchar_t *path)
|
void SendImageMessage(wstring wxid, wstring path)
|
||||||
{
|
{
|
||||||
if (g_WeChatWinDllAddr == 0) {
|
if (g_WeChatWinDllAddr == 0) {
|
||||||
return;
|
return;
|
||||||
@ -95,16 +89,13 @@ void SendImageMessage(const wchar_t *wxid, const wchar_t *path)
|
|||||||
TextStruct_t imgWxid = { 0 };
|
TextStruct_t imgWxid = { 0 };
|
||||||
TextStruct_t imgPath = { 0 };
|
TextStruct_t imgPath = { 0 };
|
||||||
|
|
||||||
wstring wsWxid = wxid;
|
imgWxid.text = (wchar_t *)wxid.c_str();
|
||||||
wstring wsPath = path;
|
imgWxid.size = wxid.size();
|
||||||
|
imgWxid.capacity = wxid.capacity();
|
||||||
|
|
||||||
imgWxid.text = (wchar_t *)wsWxid.c_str();
|
imgPath.text = (wchar_t *)path.c_str();
|
||||||
imgWxid.size = wsWxid.size();
|
imgPath.size = path.size();
|
||||||
imgWxid.capacity = wsWxid.capacity();
|
imgPath.capacity = path.capacity();
|
||||||
|
|
||||||
imgPath.text = (wchar_t *)wsPath.c_str();
|
|
||||||
imgPath.size = wsPath.size();
|
|
||||||
imgPath.capacity = wsPath.capacity();
|
|
||||||
|
|
||||||
// 发送图片Call地址 = 微信基址 + 偏移
|
// 发送图片Call地址 = 微信基址 + 偏移
|
||||||
DWORD sendCall1 = g_WeChatWinDllAddr + g_WxCalls.sendImg.call1;
|
DWORD sendCall1 = g_WeChatWinDllAddr + g_WxCalls.sendImg.call1;
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atWxids);
|
#include "framework.h"
|
||||||
void SendImageMessage(const wchar_t *wxid, const wchar_t *path);
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void SendTextMessage(wstring wxid, wstring msg, wstring atWxids);
|
||||||
|
void SendImageMessage(wstring wxid, wstring path);
|
||||||
|
Loading…
Reference in New Issue
Block a user