WeChatFerry/App/App.cpp

79 lines
2.3 KiB
C++
Raw Normal View History

2022-08-06 21:44:26 +08:00
#include <fcntl.h>
2021-02-12 23:21:57 +08:00
#include <io.h>
#include <iostream>
#include <process.h>
#include <windows.h>
#include "sdk.h"
/*
#pragma comment(lib, "SDK.lib")
*/
2021-08-28 08:33:24 +08:00
void printContacts(ContactMap_t contacts)
{
2022-08-07 08:43:28 +08:00
wprintf(L"contacts number: %ld\n", contacts.size());
2021-08-28 08:33:24 +08:00
for (auto it = contacts.begin(); it != contacts.end(); ++it) {
2022-08-07 08:43:28 +08:00
wprintf(L"%s\t%s\t%s\t%s\t%s\t%s\t%s\r\n", it->second.wxId.c_str(), it->second.wxCode.c_str(),
it->second.wxName.c_str(), it->second.wxGender.c_str(), it->second.wxCountry.c_str(),
it->second.wxProvince.c_str(), it->second.wxCity.c_str());
2021-08-28 08:33:24 +08:00
}
}
2021-02-12 23:21:57 +08:00
int onTextMsg(WxMessage_t msg)
{
2022-08-07 08:43:28 +08:00
wprintf(L"%s msgType: %d, msgSource: %d, isSelf: %d\n", msg.id.c_str(), msg.type, msg.source, msg.self);
wprintf(L"%s[%s] >> %s\n", msg.wxId.c_str(), msg.roomId.c_str(), msg.content.c_str());
wprintf(L"msgSourceXml: %s\n", msg.xml.c_str());
2021-02-12 23:21:57 +08:00
return 0;
}
int main()
{
2021-08-22 21:57:16 +08:00
DWORD status = 0;
wstring wxid = L"filehelper"; // 微信ID
wstring at_wxid = L"";
wstring content = L"这里填写消息内容";
wstring img_path = L"test.jpg";
2021-02-12 23:21:57 +08:00
_wsetlocale(LC_ALL, L"chs"); // 这是个大坑,不设置中文直接不见了。。。
2022-08-07 08:43:28 +08:00
wprintf(L"WxInitSDK: ");
2021-02-12 23:21:57 +08:00
status = WxInitSDK();
2022-08-07 08:43:28 +08:00
wcout << status << endl;
wprintf(L"%d\n", status);
2021-02-12 23:21:57 +08:00
if (status != 0) {
return 0;
2022-08-07 20:08:54 +08:00
}
// 获取消息类型
wprintf(L"获取消息类型\n");
const MsgTypesMap_t WxMsgTypes = WxGetMsgTypes();
for (auto it = WxMsgTypes.begin(); it != WxMsgTypes.end(); ++it) {
wprintf(L"%d: %s\n", it->first, it->second.c_str());
}
2022-08-06 17:26:32 +08:00
2022-08-07 08:43:28 +08:00
wprintf(L"Message: 接收通知中......\n");
2021-02-12 23:21:57 +08:00
WxSetTextMsgCb(onTextMsg);
2022-08-07 21:29:08 +08:00
Sleep(1000); // 等待1秒
2022-08-06 17:29:37 +08:00
2022-08-07 08:43:28 +08:00
// 测试发送消息
wprintf(L"测试发送消息\n");
WxSendTextMsg(wxid, at_wxid, content);
2022-08-07 21:29:08 +08:00
Sleep(1000); // 等待1秒
2021-02-12 23:21:57 +08:00
2022-08-07 08:43:28 +08:00
// 测试发送照片
wprintf(L"测试发送照片\n");
2022-08-06 21:44:26 +08:00
WxSendImageMsg(wxid, img_path);
2022-08-07 21:29:08 +08:00
Sleep(1000); // 等待1秒
2022-08-07 08:43:28 +08:00
// 测试获取联系人
2021-08-28 08:33:24 +08:00
auto mContact = WxGetContacts();
printContacts(mContact);
2022-08-07 08:43:28 +08:00
2021-02-12 23:21:57 +08:00
while (1) {
Sleep(10000); // 休眠释放CPU
}
}