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")
|
|
|
|
|
等效为在属性,链接,输入中添加该依赖
|
|
|
|
|
*/
|
|
|
|
|
|
2022-08-20 22:10:11 +08:00
|
|
|
|
typedef map<int, wstring> sqlTypes_t;
|
|
|
|
|
static sqlTypes_t sqlTypes
|
|
|
|
|
= sqlTypes_t { { 1, L"INTEGER" }, { 2, L"FLOAT" }, { 3, L"TEXT" }, { 4, L"BLOB" }, { 5, L"NULL" } };
|
|
|
|
|
|
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());
|
2022-08-07 23:49:37 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-07 23:32:25 +08:00
|
|
|
|
void printDbNames(vector<wstring> vDbs)
|
|
|
|
|
{
|
|
|
|
|
wprintf(L"db numbers: %ld\n", vDbs.size());
|
2022-08-07 23:49:37 +08:00
|
|
|
|
for (auto it = vDbs.begin(); it != vDbs.end(); it++) {
|
2022-08-07 23:32:25 +08:00
|
|
|
|
wprintf(L"%s\n", (*it).c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-07 23:49:37 +08:00
|
|
|
|
void printDbTables(DbTableVector_t tables)
|
|
|
|
|
{
|
|
|
|
|
wprintf(L"table numbers: %ld\n", tables.size());
|
|
|
|
|
for (auto it = tables.begin(); it != tables.end(); it++) {
|
|
|
|
|
wprintf(L"%s\n%s\n\n", (it->table).c_str(), (it->sql).c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-20 22:10:11 +08:00
|
|
|
|
void printDbResults(SqlRetVector_t vvResults)
|
|
|
|
|
{
|
|
|
|
|
int rows = vvResults.size();
|
|
|
|
|
printf("vvResults.size: %d\n", rows);
|
|
|
|
|
rows = 0;
|
|
|
|
|
for (auto vv = vvResults.begin(); vv != vvResults.end(); vv++) {
|
|
|
|
|
printf("Row %d\n", rows++);
|
|
|
|
|
for (auto v = vv->begin(); v != vv->end(); v++) {
|
|
|
|
|
wprintf(L"%s[%s]: ", v->column.c_str(), sqlTypes[v->type].c_str());
|
|
|
|
|
switch (v->type) {
|
|
|
|
|
case 1: {
|
|
|
|
|
printf("%d\n", stoi(v->content.c_str()));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2: {
|
|
|
|
|
printf("%f\n", stof(v->content.c_str()));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3: {
|
|
|
|
|
printf("%s\n", v->content.c_str());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4: {
|
|
|
|
|
byte *p = (byte *)(v->content.c_str());
|
|
|
|
|
for (unsigned int i = 0; i < v->content.size(); i++) {
|
|
|
|
|
printf("%02X ", p[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
printf("\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2022-08-20 22:10:11 +08:00
|
|
|
|
setlocale(LC_ALL, "chs"); // 这是个大坑,不设置中文直接不见了。。。
|
2021-02-12 23:21:57 +08:00
|
|
|
|
|
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
|
|
|
|
wprintf(L"%d\n", status);
|
2021-02-12 23:21:57 +08:00
|
|
|
|
if (status != 0) {
|
|
|
|
|
return 0;
|
2022-08-07 23:32:25 +08:00
|
|
|
|
}
|
2022-08-12 22:23:45 +08:00
|
|
|
|
|
2022-08-07 23:32:25 +08:00
|
|
|
|
// 获取消息类型
|
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-07 23:32:25 +08:00
|
|
|
|
}
|
2022-08-20 17:39:21 +08:00
|
|
|
|
Sleep(1000); // 等待1秒
|
2022-08-06 17:26:32 +08:00
|
|
|
|
|
2022-08-07 08:43:28 +08:00
|
|
|
|
wprintf(L"Message: 接收通知中......\n");
|
2022-08-20 15:15:04 +08:00
|
|
|
|
WxEnableRecvMsg(onTextMsg);
|
2022-08-07 21:29:08 +08:00
|
|
|
|
Sleep(1000); // 等待1秒
|
2022-08-12 22:30:35 +08:00
|
|
|
|
|
2022-08-07 08:43:28 +08:00
|
|
|
|
// 测试发送消息
|
|
|
|
|
wprintf(L"测试发送消息\n");
|
2022-08-20 17:39:21 +08:00
|
|
|
|
WxSendTextMsg(wxid, content, at_wxid);
|
2022-08-07 21:29:08 +08:00
|
|
|
|
Sleep(1000); // 等待1秒
|
2022-08-12 22:33:16 +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-12 23:01:24 +08:00
|
|
|
|
|
2022-08-07 08:43:28 +08:00
|
|
|
|
// 测试获取联系人
|
2021-08-28 08:33:24 +08:00
|
|
|
|
auto mContact = WxGetContacts();
|
|
|
|
|
printContacts(mContact);
|
2022-08-07 23:32:25 +08:00
|
|
|
|
Sleep(1000); // 等待1秒
|
2022-08-12 23:12:01 +08:00
|
|
|
|
|
2022-08-07 23:32:25 +08:00
|
|
|
|
// 测试获取数据库名
|
|
|
|
|
auto vDbNames = WxGetDbNames();
|
|
|
|
|
printDbNames(vDbNames);
|
2022-08-07 23:49:37 +08:00
|
|
|
|
Sleep(1000); // 等待1秒
|
|
|
|
|
|
|
|
|
|
// 测试获取数据库中的表
|
2022-08-20 22:10:11 +08:00
|
|
|
|
auto vDbTables = WxGetDbTables(L"MicroMsg.db");
|
2022-08-07 23:49:37 +08:00
|
|
|
|
printDbTables(vDbTables);
|
2022-08-20 22:10:11 +08:00
|
|
|
|
Sleep(1000); // 等待1秒
|
|
|
|
|
|
|
|
|
|
// 测试执行 SQL
|
|
|
|
|
auto vvResults = WxExecDbQuery(L"MicroMsg.db", L"SELECT * FROM Contact LIMIT 1;");
|
|
|
|
|
printDbResults(vvResults);
|
2022-08-12 23:12:01 +08:00
|
|
|
|
|
2021-02-12 23:21:57 +08:00
|
|
|
|
while (1) {
|
|
|
|
|
Sleep(10000); // 休眠,释放CPU
|
|
|
|
|
}
|
|
|
|
|
}
|