WeChatRobot.cpp 7.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// WeChatRobot.cpp: CWeChatRobot 的实现

#include "pch.h"
#include "WeChatRobot.h"


// CWeChatRobot
/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CStartRobotService(int* __result) {
    *__result = StartRobotService();
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CStopRobotService(int* __result) {
    *__result = StopRobotService();
    return S_OK;
}

/*
* 参数1:接收人wxid
* 参数2:文本消息内容
* 参数3:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CSendText(BSTR wxid, BSTR wxmsg, int* __result) {
    *__result = SendText(wxid, wxmsg);
    return S_OK;
}

L
ljc545w 已提交
34 35 36 37 38 39
/*
* 参数1:群聊id
* 参数2:艾特的人wxid
* 参数3:文本消息内容
* 参数4:预返回的值,调用时无需提供
*/
40 41 42 43 44 45 46 47 48
STDMETHODIMP CWeChatRobot::CSendAtText(BSTR chatroomid, VARIANT* wxid, BSTR wxmsg, int* __result) {
    *__result = 0;
    if (wxid->vt == VT_BSTR) {
        *__result = SendAtText(chatroomid,wxid->bstrVal, wxmsg);
    }
    else if(wxid->vt == (VT_ARRAY | VT_VARIANT)) {
        SAFEARRAY* psaValue = wxid->parray;
        *__result = SendAtText(chatroomid, psaValue, wxmsg);
    }
L
ljc545w 已提交
49 50 51
    return S_OK;
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
/*
* 参数1:接收人wxid
* 参数2:图片绝对路径
* 参数3:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CSendImage(BSTR wxid, BSTR imagepath, int* __result) {
    *__result = SendImage(wxid, imagepath);
    return S_OK;
}

/*
* 参数1:接收人wxid
* 参数2:文件绝对路径
* 参数3:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CSendFile(BSTR wxid, BSTR filepath, int* __result) {
    *__result = SendFile(wxid, filepath);
    return S_OK;
}

/*
* 参数1:接收人wxid
* 参数2:文章标题
* 参数3:文章摘要
* 参数4:文章链接
* 参数5:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CSendArticle(BSTR wxid, BSTR title,BSTR abstract,BSTR url, int* __result) {
    *__result = SendArticle(wxid, title,abstract,url);
    return S_OK;
}

/*
* 参数1:接收人wxid
* 参数2:被分享人wxid
* 参数3:显示的名字
* 参数4:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CSendCard(BSTR receiver, BSTR sharedwxid, BSTR nickname, int* __result) {
    *__result = SendCard(receiver, sharedwxid, nickname);
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
L
ljc545w 已提交
97
* 返回一个三维数组,python的comtypes包会将其解析为元组
98
*/
L
ljc545w 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
STDMETHODIMP CWeChatRobot::CGetFriendList(VARIANT* __result) {
    VARIANT vsaValue;
    vsaValue.vt = VT_ARRAY | VT_VARIANT;
    V_ARRAY(&vsaValue) = GetFriendList();
    *__result = vsaValue;
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
  返回构造好的json串,在反序列化时需考虑好友信息中是否存在json字符
  (考虑到从SAFEARRAY转换到适当变量可能较为繁琐,故保留此接口)
*/
STDMETHODIMP CWeChatRobot::CGetFriendListString(BSTR* __result) {
    string smessage = _com_util::ConvertBSTRToString((BSTR)(GetFriendListString().c_str()));
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    *__result = _com_util::ConvertStringToBSTR(smessage.c_str());
    return S_OK;
}

/*
* 参数1:要查询的wxid
* 参数2:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CGetWxUserInfo(BSTR wxid,BSTR* __result) {
    string smessage = _com_util::ConvertBSTRToString((BSTR)(GetWxUserInfo(wxid).c_str()));
    *__result = _com_util::ConvertStringToBSTR(smessage.c_str());
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CGetSelfInfo(BSTR* __result) {
    string smessage = _com_util::ConvertBSTRToString((BSTR)(GetSelfInfo().c_str()));
    *__result = _com_util::ConvertStringToBSTR(smessage.c_str());
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CCheckFriendStatusInit(int* __result) {
    *__result = CheckFriendStatusInit();
    return S_OK;
}

/*
* 参数1:查询的wxid
* 参数2:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CCheckFriendStatus(BSTR wxid,int* __result) {
    *__result = CheckFriendStatus((wchar_t*)wxid);
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CCheckFriendStatusFinish(int* __result) {
    *__result = CheckFriendStatusFinish();
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CGetComWorkPath(BSTR* __result) {
    string path = _com_util::ConvertBSTRToString((BSTR)(GetComWorkPath().c_str()));
    *__result = _com_util::ConvertStringToBSTR(path.c_str());
    return S_OK;
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CStartReceiveMessage(int* __result) {
    *__result = StartReceiveMessage();
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CReceiveMessage(VARIANT* __result) {
    VARIANT vsaValue;
    vsaValue.vt = VT_ARRAY | VT_VARIANT;
    V_ARRAY(&vsaValue) = ReceiveMessage();
    *__result = vsaValue;
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CStopReceiveMessage(int* __result) {
    *__result = StopReceiveMessage();
    return S_OK;
L
ljc545w 已提交
196 197 198 199 200 201 202 203 204 205 206 207
}

/*
* 参数1:群聊ID
* 参数2:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CGetChatRoomMembers(BSTR chatroomid,VARIANT* __result) {
    VARIANT vsaValue;
    vsaValue.vt = VT_ARRAY | VT_VARIANT;
    V_ARRAY(&vsaValue) = GetChatRoomMembers(chatroomid);
    *__result = vsaValue;
    return S_OK;
L
ljc545w 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CGetDbHandles(VARIANT* __result) {
    VARIANT vsaValue;
    vsaValue.vt = VT_ARRAY | VT_VARIANT;
    V_ARRAY(&vsaValue) = GetDbHandles();
    *__result = vsaValue;
    return S_OK;
}

/*
* 参数1:数据库句柄
* 参数2:要执行的SQL语句
* 参数3:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CExecuteSQL(DWORD DbHandle,BSTR sql,VARIANT* __result) {
    VARIANT vsaValue;
    vsaValue.vt = VT_ARRAY | VT_VARIANT;
    vsaValue.intVal = 0;
    V_ARRAY(&vsaValue) = ExecuteSQL(DbHandle, sql);
    *__result = vsaValue;
    return S_OK;
}

/*
* 参数1:数据库句柄
* 参数2:备份保存路径
* 参数3:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CBackupSQLiteDB(DWORD DbHandle, BSTR savepath, int* __result) {
    *__result = BackupSQLiteDB(DbHandle, savepath);
    return S_OK;
L
ljc545w 已提交
243 244 245 246 247 248 249 250 251 252
}

/*
* 参数1:v3数据
* 参数2:v4数据
* 参数3:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CVerifyFriendApply(BSTR v3, BSTR v4, int* __result) {
    *__result = VerifyFriendApply(v3, v4);
    return S_OK;
L
ljc545w 已提交
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
}

/*
* 参数1:wxid
* 参数2:附加信息
* 参数3:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CAddFriendByWxid(BSTR wxid, BSTR message, int* __result) {
    *__result = AddFriendByWxid(wxid, message);
    return S_OK;
}

/*
* 参数1:v3数据
* 参数2:附加信息
* 参数3:添加方式
* 参数4:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CAddFriendByV3(BSTR v3, BSTR message,int AddType, int* __result) {
    *__result = AddFriendByV3(v3, message,AddType);
    return S_OK;
L
ljc545w 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CGetWeChatVer(BSTR* __result) {
    string path = _com_util::ConvertBSTRToString((BSTR)(GetWeChatVerStr().c_str()));
    *__result = _com_util::ConvertStringToBSTR(path.c_str());
    return S_OK;
}

/*
* 参数1:预返回的值,调用时无需提供
*/
STDMETHODIMP CWeChatRobot::CStartWeChat(int* __result) {
    StartWeChat();
    *__result = 0;
    return S_OK;
L
ljc545w 已提交
292
}