企微hook源码已经在QQ群内开源。速度进群下载,避免和谐。
QQ群:649480745
//pc端发送消息回调
void RecvPcMsgRes(DWORD eax)
{
// OutputDebugStringA("pc发送消息");
PWX_STRING pMsgPb = (PWX_STRING)(eax);//消息pb结构体
string pbData = WxStringToString(pMsgPb);//消息pb
// OutputDebugStringA(StringToHex(pbData).c_str());
ResMessageData pmd;
pmd.ParseFromString(pbData);
sessiondata sd = pmd.sessiondata();
BaseResponse brs = pmd.baseresponse();
for (int i = 0; i < sd.msg_size(); i++) {
nlohmann::json root;
root["errcode"] = brs.ret();
if (brs.errmsg().size() > 0) {
root["errmsg"] = brs.errmsg();
}
msgdata md = sd.msg(i);
// OutputDebugStringA(md.appinfo().c_str());
string syncKey = "";
string file = "";
long source = 0L;
//同步发送消息
//for (auto it = SsenMsgQueue.begin(); it != SsenMsgQueue.end(); ++it)
//{
// map<string, string> resVal = *it;
// if (resVal.count(md.appinfo())>0) {
// syncKey = resVal[md.appinfo()];
// SsenMsgQueue.erase(it);
// break;
// }
//}
//OutputDebugStringA("当前消息队列长度");
//OutputDebugStringA(to_string(SsenMsgQueue.size()).c_str());
if (SsenMsgQueue.count(md.appinfo()) > 0)
{
string json = SsenMsgQueue[md.appinfo()];
auto j3 = json::parse(json);
syncKey = j3["syncKey"];
file = j3["file"];
if (!j3["data"]["source"].is_null() && j3["data"]["source"].is_number() == TRUE) {
// 存在字段进行校验
source = j3["data"]["source"];
}
SsenMsgQueueDel(md.appinfo());
}
nlohmann::json item;
item["is_pc_send"] = 1;
item["synckey"] = syncKey;
item["source"] = source;
item["msg_id"] = md.id();
item["server_id"] = md.seq();
msgMap[md.appinfo()] = "val";
item["sender"] = to_string(md.sender());
item["receiver"] = to_string(md.receiver());
item["sendtime"] = md.sendtime();
item["msgtype"] = md.contenttype();
if (md.messagetype() == 1) {
string strRoomId = to_string(md.roomid());
item["room_conversation_id"] = ("R:" + strRoomId);
item["is_room"] = 1;
}
else if (md.messagetype() == 4) {
item["receiver"] = "FILEASSIST";
item["is_room"] = 0;
}
else {
item["is_room"] = 0;
}
string msgPb = md.content();
switch (md.contenttype())
{
case 0: //文本消息
//root["type"] = SEND_MSG_TEXT;
ThisPcTestMsg(msgPb, item, root);
break;
case 2: //文本消息
//root["type"] = SEND_MSG_TEXT;
ThisPcTestMsg(msgPb, item, root);
break;
case 6://位置消息
root["type"] = SEND_LOCATION_MSG;
RecvPositionMsg(msgPb, item, root);
break;
case 29://gif消息
root["type"] = SEND_MSG_GIF;
ExpressionMsg(msgPb, item, root);
break;
case 78://小程序
root["type"] = SEND_MSG_APPLETS;
AppletsPcMsg(msgPb, item, root);
break;
case 141://视频号
root["type"] = SEND_WECHAT_SPH_FEED;
WechatSphFeedMeg(msgPb, item, root);
break;
case 13://链接
root["type"] = SEND_LINK_MSG;
LinkPcMsg(msgPb, item, root);
break;
case 0x29://名片消息
root["type"] = SEND_BUSSINESS_CARD;
BusinessCardMsg(msgPb, item, root);
break;
case 14://图片消息
root["type"] = SEND_MSG_IMG;
item["file"] = file;
ImgMsg(msgPb, item, root);
break;
case 15://文件消息
root["type"] = SEND_FILE_MSG;
item["file"] = file;
FileMsg(msgPb, item, root);
break;
case 16://语音消息
root["type"] = SEND_VOICE_MSG;
VoiceMsg(msgPb, item, root);
break;
case 23://视频消息
root["type"] = SEND_VIDEO_MSG;
item["file"] = file;
VideoMsg(msgPb, item, root);
break;
default:
break;
}
}
}