From ae4443466289cf9ebabee4084c9370eb30374a6a Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Sat, 29 Jul 2023 17:11:36 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=88=A0=E9=99=A4=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/3.9.5.81.md | 2 +- python/3.9.5.81/http_client.py | 280 +++++++++++++++++++++++++++++++++ src/http_server_callback.cc | 22 ++- 3 files changed, 301 insertions(+), 3 deletions(-) create mode 100644 python/3.9.5.81/http_client.py diff --git a/doc/3.9.5.81.md b/doc/3.9.5.81.md index 8f3b8c6..b0fcce6 100644 --- a/doc/3.9.5.81.md +++ b/doc/3.9.5.81.md @@ -215,7 +215,7 @@ enableHttp=0时,使用ip,port的tcp服务回传消息。 入参: ``` javascript { - "port": "19099" + "port": "19099", "ip":"127.0.0.1", "url":"http://localhost:8080", "timeout":"3000", diff --git a/python/3.9.5.81/http_client.py b/python/3.9.5.81/http_client.py new file mode 100644 index 0000000..df84819 --- /dev/null +++ b/python/3.9.5.81/http_client.py @@ -0,0 +1,280 @@ +import requests +import json + + +def checkLogin(): + url = "127.0.0.1:19088/api/checkLogin" + payload = {} + headers = {} + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def userInfo(): + url = "127.0.0.1:19088/api/userInfo" + payload = {} + headers = {} + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def sendTextMsg(): + url = "127.0.0.1:19088/api/sendTextMsg" + payload = json.dumps({ + "wxid": "filehelper", + "msg": "12www" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def sendImagesMsg(): + url = "127.0.0.1:19088/api/sendImagesMsg" + print("modify imagePath") + raise RuntimeError("modify imagePath then deleted me") + payload = json.dumps({ + "wxid": "filehelper", + "imagePath": "C:\\pic.png" + }) + headers = { + 'Content-Type': 'application/json' + } + + response = requests.request("POST", url, headers=headers, data=payload) + + print(response.text) + + +def sendFileMsg(): + url = "127.0.0.1:19088/api/sendFileMsg" + print("modify filePath") + raise RuntimeError("modify filePath then deleted me") + payload = json.dumps({ + "wxid": "filehelper", + "filePath": "C:\\test.zip" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def hookSyncMsg(): + url = "127.0.0.1:19088/api/hookSyncMsg" + print("modify ip port url ") + raise RuntimeError("modify ip port url then deleted me") + payload = json.dumps({ + "port": "19099", + "ip": "127.0.0.1", + "url": "http://localhost:8080", + "timeout": "3000", + "enableHttp": "0" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def unhookSyncMsg(): + url = "127.0.0.1:19088/api/unhookSyncMsg" + payload = {} + headers = {} + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def getContactList(): + url = "127.0.0.1:19088/api/getContactList" + payload = {} + headers = {} + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def getDBInfo(): + url = "127.0.0.1:19088/api/getDBInfo" + payload = {} + headers = {} + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def execSql(): + url = "127.0.0.1:19088/api/execSql" + print("modify dbHandle ") + raise RuntimeError("modify dbHandle then deleted me") + payload = json.dumps({ + "dbHandle": 1713425147584, + "sql": "select * from MSG where localId =100;" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def getChatRoomDetailInfo(): + url = "127.0.0.1:19088/api/getChatRoomDetailInfo" + print("modify chatRoomId ") + raise RuntimeError("modify chatRoomId then deleted me") + payload = json.dumps({ + "chatRoomId": "123333@chatroom" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def addMemberToChatRoom(): + url = "127.0.0.1:19088/api/addMemberToChatRoom" + print("modify chatRoomId memberIds ") + raise RuntimeError("modify chatRoomId memberIds then deleted me") + payload = json.dumps({ + "chatRoomId": "123@chatroom", + "memberIds": "wxid_123" + }) + headers = { + 'Content-Type': 'application/json' + } + + response = requests.request("POST", url, headers=headers, data=payload) + + print(response.text) + + +def delMemberFromChatRoom(): + url = "127.0.0.1:19088/api/delMemberFromChatRoom" + print("modify chatRoomId memberIds ") + raise RuntimeError("modify chatRoomId memberIds then deleted me") + payload = json.dumps({ + "chatRoomId": "21363231004@chatroom", + "memberIds": "wxid_123" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def modifyNickname(): + url = "127.0.0.1:19088/api/modifyNickname" + print("modify chatRoomId wxid nickName") + raise RuntimeError("modify chatRoomId wxid nickName then deleted me") + payload = json.dumps({ + "chatRoomId": "123@chatroom", + "wxid": "wxid_123", + "nickName": "test" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def getMemberFromChatRoom(): + print("modify chatRoomId ") + raise RuntimeError("modify chatRoomId then deleted me") + url = "127.0.0.1:19088/api/getMemberFromChatRoom" + payload = json.dumps({ + "chatRoomId": "123@chatroom" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def topMsg(): + print("modify msgId ") + raise RuntimeError("modify msgId then deleted me") + url = "127.0.0.1:19088/api/topMsg" + payload = json.dumps({ + "msgId": 1222222 + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def removeTopMsg(): + print("modify msgId chatRoomId ") + raise RuntimeError("modify msgId chatRoomId then deleted me") + + url = "127.0.0.1:19088/api/removeTopMsg" + + payload = json.dumps({ + "chatRoomId": "123@chatroom", + "msgId": 123 + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def InviteMemberToChatRoom(): + print("modify memberIds chatRoomId ") + raise RuntimeError("modify memberIds chatRoomId then deleted me") + + url = "127.0.0.1:19088/api/InviteMemberToChatRoom" + + payload = json.dumps({ + "chatRoomId": "123@chatroom", + "memberIds": "wxid_123" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def hookLog(): + url = "127.0.0.1:19088/api/hookLog" + payload = {} + headers = {} + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def unhookLog(): + url = "127.0.0.1:19088/api/unhookLog" + payload = {} + headers = {} + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +def createChatRoom(): + print("modify memberIds ") + raise RuntimeError("modify memberIds then deleted me") + url = "127.0.0.1:19088/api/createChatRoom" + + payload = json.dumps({ + "memberIds": "wxid_8yn4k908tdqp22,wxid_oyb662qhop4422" + }) + headers = { + 'Content-Type': 'application/json' + } + response = requests.request("POST", url, headers=headers, data=payload) + print(response.text) + + +if __name__ == '__main__': + checkLogin() + # userInfo() diff --git a/src/http_server_callback.cc b/src/http_server_callback.cc index 7694606..4bafe5a 100644 --- a/src/http_server_callback.cc +++ b/src/http_server_callback.cc @@ -7,9 +7,18 @@ #include "db.h" #define STR2LL(str) (wxhelper::Utils::IsDigit(str) ? stoll(str) : 0) +#define STR2I(str) (wxhelper::Utils::IsDigit(str) ? stoi(str) : 0) namespace common = wxhelper::common; - +int GetIntParam(nlohmann::json data, std::string key) { + int result; + try { + result = data[key].get(); + } catch (nlohmann::json::exception) { + result = STR2I(data[key].get()); + } + return result; +} INT64 GetINT64Param(nlohmann::json data, std::string key) { INT64 result; @@ -164,8 +173,17 @@ std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) { ret = ret_data.dump(); return ret; } else if (mg_http_match_uri(hm, "/api/hookSyncMsg")) { + int port = GetIntParam(j_param, "port"); + std::string ip = GetStringParam(j_param, "ip"); + int enable = GetIntParam(j_param, "enableHttp"); + std::string url = ""; + int timeout = 0; + if (enable) { + url = GetStringParam(j_param, "url"); + timeout = GetIntParam(j_param, "timeout"); + } INT64 success = - wxhelper::hooks::HookSyncMsg("127.0.0.1", 19099, "", 3000, false); + wxhelper::hooks::HookSyncMsg(ip, port, url, timeout, false); nlohmann::json ret_data = { {"code", success}, {"data", {}}, {"msg", "success"}}; ret = ret_data.dump();