commit 52de70e2a018a1a7c2d9512aee308280879ce493 Author: Changhua Date: Sun Sep 25 14:56:18 2022 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66adf46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.* +!.gitignore + +*pyc +__pycache__ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..91630e1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Changhua + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..ff55c18 --- /dev/null +++ b/README.MD @@ -0,0 +1,7 @@ +# WeChatRobot +A Robot based on WeChatFerry. + +## Quick Start +```sh +python main.py +``` diff --git a/main.py b/main.py new file mode 100644 index 0000000..38d80cf --- /dev/null +++ b/main.py @@ -0,0 +1,12 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sdk.wcferry as WxSDK + + +def main(): + print(dir(WxSDK)) + + +if __name__ == "__main__": + main() diff --git a/sdk/App.exe b/sdk/App.exe new file mode 100755 index 0000000..612c3a9 Binary files /dev/null and b/sdk/App.exe differ diff --git a/sdk/App.py b/sdk/App.py new file mode 100755 index 0000000..e2a39aa --- /dev/null +++ b/sdk/App.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +import time +import wcferry as sdk + + +def main(): + help(sdk) # 查看SDK支持的方法和属性 + + # 初始化SDK,如果成功,返回0;否则失败 + status = sdk.WxInitSDK() + if status != 0: + print("初始化失败") + exit(-1) + + print("初始化成功") + WxMsgTypes = sdk.WxGetMsgTypes() # 获取消息类型 + print(WxMsgTypes) # 查看消息类型 + + time.sleep(2) + print("打印通讯录......") + contacts = sdk.WxGetContacts() + for k, v in contacts.items(): + print(k, v.wxCode, v.wxName, v.wxCountry, v.wxProvince, v.wxCity, v.wxGender) + + time.sleep(2) + print("发送文本消息......") + sdk.WxSendTextMsg("filehelper", "message from WeChatFerry...") # 往文件传输助手发消息 + # sdk.WxSendTextMsg("xxxx@chatroom", "message from WeChatFerry...") # 往群里发消息(需要改成正确的 ID,下同) + # sdk.WxSendTextMsg("xxxx@chatroom", "message from WeChatFerry... @ ", "wxid_xxxxxxxxxxxx") # 往群里发消息,@某人 + # sdk.WxSendTextMsg("xxxx@chatroom", "message from WeChatFerry... @ ", "notify@all") # 往群里发消息,@所有人 + + time.sleep(2) + print("发送图片消息......") + sdk.WxSendImageMsg("filehelper", "test.jpg") + + dbs = sdk.WxGetDbNames() + for db in dbs: + print(db) + + tables = sdk.WxGetDbTables(dbs[0]) + for t in tables: + print(f"{t.table}\n{t.sql}\n\n") + + # 接收消息。先定义消息处理回调 + def OnTextMsg(msg: sdk.WxMessage): + def getName(id): + contact = contacts.get(id) + if contact is None: + return id + return contact.wxName + + s = "收到" + if msg.self == 1: # 忽略自己发的消息 + s += f"来自自己的消息" + print(f"\n{s}") + return 0 + + msgType = WxMsgTypes.get(msg.type, '未知类型') + nickName = getName(msg.wxId) + if msg.source == 1: + groupName = getName(msg.roomId) + s += f"来自群[{groupName}]的[{nickName}]的{msgType}消息:" + else: + s += f"来自[{nickName}]的{msgType}消息:" + + s += f"\r\n{msg.content}" + if msg.type != 0x01: + s += f"\r\n{msg.xml}" + + print(f"\n{s}") + + return 0 + + print("Message: 接收通知中......") + sdk.WxEnableRecvMsg(OnTextMsg) # 设置回调,接收消息 + + while True: + time.sleep(1) + + +if __name__ == '__main__': + main() diff --git a/sdk/SDK.dll b/sdk/SDK.dll new file mode 100755 index 0000000..5bc4987 Binary files /dev/null and b/sdk/SDK.dll differ diff --git a/sdk/Spy.dll b/sdk/Spy.dll new file mode 100755 index 0000000..aabdb14 Binary files /dev/null and b/sdk/Spy.dll differ diff --git a/sdk/test.jpg b/sdk/test.jpg new file mode 100755 index 0000000..14aa7a7 Binary files /dev/null and b/sdk/test.jpg differ diff --git a/sdk/wcferry.pyd b/sdk/wcferry.pyd new file mode 100755 index 0000000..fc4254b Binary files /dev/null and b/sdk/wcferry.pyd differ