├── README.md
├── WeChat API.md
└── WeChatAPI.html
/README.md:
--------------------------------------------------------------------------------
1 | # 微信Api/WeChatApi
2 |
3 | 狗子微信Api、微信机器人、微信api、微信发卡机器人、微信聊天机器人。
4 |
5 | 基于Windows平台开发的微信Api,仅支持2.9.0.122版本。
6 |
7 | 仅供学习,禁止非法用途!
8 |
9 | # 文件
10 |
11 | `WeChat2.dll`:客户端
12 |
13 | `WeChatclient.ini`:填写服务端地址,如:127.0.0.1:2222/192.168.1.2:2222
14 |
15 | `WeChatServer.exe`:服务端(默认2222端口)
16 |
17 | ## 下载
18 |
19 | `WeChatSetup (2.9.0.112).exe`麻烦进群下载
20 |
21 | 依赖: [点此下载Api.rar](https://github.com/FRz2one/WeChatApi/blob/master/Api.rar)
22 |
23 | # Http通信
24 |
25 | 用户(调用HTTP api)>`WeChatServer.exe`>微信
26 |
27 | > 以下内容基于`WeChatServer.exe`通信
28 | ## [文档](https://github.com/FRz2one/WeChatApi/blob/master/WeChat%20API.md)
29 | [文档](https://github.com/FRz2one/WeChatApi/blob/master/WeChat%20API.md)
30 | ## Demo
31 |
32 | ### Java
33 |
34 | 感谢静夜思贡献[Java客户端代码](https://gitee.com/sglmsn/wechat-api)
35 |
36 | ### Python
37 |
38 | > 自动同意好友并且回复内容,关键词拉人进群demo
39 |
40 | ```python
41 | import requests
42 | import json
43 | #import qrcode
44 | import random
45 | import threading
46 | import time
47 | import websocket
48 | # -*- coding: utf-8 -*-
49 |
50 | x="""回复12300邀请进狗子微信Api交流群"""#同意好友回复内容
51 | dict0={"12300":"12312312388@chatroom"}#关键词邀请字典
52 | #接口
53 | def WeChatPost(dict):
54 | url = "http://127.0.0.1:2222/"
55 | header = {"Content-Type": "application/json"}
56 | body_1 =dict
57 | body_1 = str(body_1)
58 | body_1 = bytes(body_1, encoding="utf-8")
59 | response_1 = requests.post(url, data=body_1, headers=header)
60 | return response_1.content.decode('utf-8')
61 | pass
62 | def Agreed(message):
63 | message0=message["content"]
64 | print(message0)
65 | WeChatPost({"funid": 51, "WeChatID": message["WeChatID"], "v1": message0[message0.find("encryptusername=") + 17:message0.find("fromnickname") - 2],"v4": message0[message0.find("ticket=") + 8:message0.find("opcode=") - 2]})
66 | time.sleep(2)
67 | WeChatPost({"funid":20,"WeChatID":message["WeChatID"],"wxid":message0[message0.find("fromusername") + 14:message0.find("fromusername") + 33],"content":x}) #发送同意好友回复
68 | pass
69 | def msg(message):
70 | if message["wxid"].find("wxid") != -1 :
71 | for (key, value) in dict0.items():
72 | if key==message["content"] :
73 | WeChatPost({"funid": 32, "WeChatID": message["WeChatID"], "wxid": value,"wxidlist": [message["wxid"]]})
74 | pass
75 | pass
76 | pass
77 | pass
78 |
79 | #Websocket回调和连接
80 | def on_message(ws, message): #处理逻辑
81 | message_0 = json.loads(message)
82 | if message_0["type"]==1:
83 | threading.Thread(target=msg, args=(message_0,)).start() # 线程执行消息处理函数
84 |
85 | if message_0["type"]==37: #好友申请
86 | print("好友申请")
87 | threading.Thread(target=Agreed, args=(message_0,)).start() #线程执行同意好友并回复消息函数
88 | pass
89 |
90 | def on_error(ws, error):
91 | print(ws)
92 | print(error)
93 | def on_close(ws):
94 | print(ws)
95 | print("### closed ###")
96 | websocket.enableTrace(True)
97 | ws = websocket.WebSocketApp("ws://127.0.0.1:2222/",on_message=on_message,on_error=on_error,on_close=on_close)
98 | ws.run_forever()
99 | ```
100 | # WebSocket通信
101 |
102 | 用户搭建服务端直接跟微信通信
103 |
104 | > 自己搭建一个WebSocket服务端,微信客户端数据以json的格式发送给服务端,优点:多端群控更方便
105 | >
106 | > 服务端丢给客户端的数据应包含[Http文档](https://github.com/FRz2one/WeChatApi/blob/master/WeChat%20API.md)中JSON对应的Name字段(除`WeChatID`外)
107 | >
108 | > WeChat2.dll给你的JSON数据Name解释:
109 | >
110 | > > `funid:10001`:微信客户端信息(微信登录二维码;登录后会发送微信号、wxid等json数据)
111 | > > `funid:10002`:微信客户端接收到的消息
112 | >
113 | > `robot_wxid`:微信客户端的账号wxid(未登录则没有或为空)
114 | >
115 | > `dwid`:标识符,如果服务端发送的json给客户端有dwid,客户端也会返回对应的dwid(否则dwid:0)
116 | >
117 | > `code`:为1为执行成功(不代表发送成功),否则有问题
118 | # 更新日志
119 | 停止项目
120 |
121 | # 交流
122 |
123 |
--------------------------------------------------------------------------------
/WeChat API.md:
--------------------------------------------------------------------------------
1 | [toc]
2 |
3 | # 微信机器人 `WebApi`
4 |
5 | > 服务端端口默认2222,header为:Content-Type:application/json
6 | >
7 | > 本文档需启动`WeChatServer.exe`
8 |
9 | | 名称 | 类型 | *说明* |
10 | | :--------: | :--: | :----------------------------------------------------------: |
11 | | `funid` | int | 函数的ID |
12 | | `WeChatID` | int | 进程微信的标识符ID |
13 | | `wxid` | str | 微信原始ID/群ID,如:**wxid_cxkcxkcxkcxkSB**/**12345678937@chatroom** |
14 |
15 | > > 返回`{"code":0}`多指参数错误;返回`{"code":1}`代表代码执行成功,不代表发送成功,需要自行鉴定参数值是否正确
16 |
17 | # `0x1`登录
18 |
19 | ## 初始化
20 |
21 | `打开WeChatServer.exe`
22 |
23 | ## 获取当前启动微信数目和登录信息
24 |
25 | ```json
26 | {"funid":10}
27 | ```
28 |
29 | > 如果未登录,会返回二维码地址,生成二维码微信扫码即可登录
30 |
31 | ## 创建微信
32 |
33 | ```
34 | {"funid":11}
35 | ```
36 |
37 | > 无返回值,调用**获取当前启动微信数目和登录信息**查看
38 |
39 | ## 退出登录
40 |
41 | ```
42 | {"funid":12,"WeChatID":1}
43 | ```
44 |
45 | # `0x2`消息
46 |
47 | ## 发送文本消息
48 |
49 | ```
50 | {"funid":20,"WeChatID":1,"wxid":"filehelper","content":"你好[耶]"}
51 | ```
52 |
53 | | *名称* | 类型 | *说明* |
54 | | :--------: | :--: | :----------------------------------------------------------: |
55 | | `wxidlist` | str | 可选,群艾特的wxid数组,文本内容需带@名字,可用`查询信息`获取名字 |
56 |
57 | ```
58 | {"funid":20,"WeChatID":1,"wxid":"filehelper","content":"@cxx 你好[耶]","wxidlist":["wxid_cxkcxkcxkcxkSB"]}
59 | ```
60 |
61 | ## 发送xml数据(小程序/链接)
62 |
63 | | *名称* | 类型 | *说明* |
64 | | :-------: | :--: | :-------------------------------------------------: |
65 | | `type` | int | 5为链接,21为小程序 |
66 | | `content` | str | xml数据/附加数据,注意转义!!!只需要把content转义 |
67 |
68 | ```
69 | {"funid":21,"WeChatID":1,"wxid":"filehelper","content":"
微信机器人 WebApi
0x1
登录初始化获取当前启动微信数目和登录信息创建微信退出登录0x2
消息发送文本消息发送xml数据(小程序/链接)发送名片发送图片发送文件消息回调0x3
群相关群创建群邀请/大群邀请获取群成员列表修改群昵称群公告移除群成员退出群聊0x4
好友相关获取好友列表添加好友删除好友查询信息0x5
其他功能收款同意好友请求打开浏览器浏览器当前URL解密图片从网络获取图片/视频/文件
WebApi
服务端端口默认2222,header为:Content-Type:application/json
本文档需启动
WeChatServer.exe
名称 | 类型 | 说明 |
---|---|---|
funid | int | 函数的ID |
WeChatID | int | 进程微信的标识符ID |
wxid | str | 微信原始ID/群ID,如:wxid_cxkcxkcxkcxkSB/12345678937@chatroom |
返回
{"code":0}
多指参数错误;返回{"code":1}
代表代码执行成功,不代表发送成功,需要自行鉴定参数值是否正确
0x1
登录打开WeChatServer.exe
{"funid":10}
如果未登录,会返回二维码地址,生成二维码微信扫码即可登录
xxxxxxxxxx
{"funid":11}
无返回值,调用获取当前启动微信数目和登录信息查看
xxxxxxxxxx
{"funid":12,"WeChatID":1}
0x2
消息xxxxxxxxxx
{"funid":20,"WeChatID":1,"wxid":"filehelper","content":"你好[耶]"}
名称 | 类型 | 说明 |
---|---|---|
wxidlist | str | 可选,群艾特的wxid数组,文本内容需带@名字,可用查询信息 获取名字 |
xxxxxxxxxx
{"funid":20,"WeChatID":1,"wxid":"filehelper","content":"@cxx 你好[耶]","wxidlist":["wxid_cxkcxkcxkcxkSB"]}
名称 | 类型 | 说明 |
---|---|---|
type | int | 5为链接,21为小程序 |
content | str | xml数据/附加数据,注意转义!!!只需要把content转义 |
x{"funid":21,"WeChatID":1,"wxid":"filehelper","content":"<msg><fromusername>wxid_g68tncvydroh22</fromusername><scene>0</scene><commenturl></commenturl><appmsg appid=\"\" sdkver=\"0\"><title>m4v</title><des>https://m.baidu.com/s?from=1000539d&word=m4v</des><action>view</action><type>5</type><showtype>0</showtype><content></content><url>https://m.baidu.com/s?from=1000539d&word=m4v</url><dataurl></dataurl><lowurl></lowurl><thumburl></thumburl><messageaction></messageaction><recorditem><![CDATA[]]></recorditem><weappinfo><pagepath></pagepath><username></username><appid></appid><appservicetype>0</appservicetype></weappinfo><extinfo></extinfo><sourceusername></sourceusername><sourcedisplayname></sourcedisplayname><commenturl></commenturl><appattach><totallen>0</totallen><attachid></attachid><emoticonmd5></emoticonmd5><fileext></fileext><cdnthumburl>3054020100044d304b02010002046b55e22802032f57260204ce51277702045e95bcc10426777869645f673638746e63767964726f683232315f6d73655f313538363837313438383837370204010800050201000400</cdnthumburl><aeskey>456e10bba42c4ba0242e5ff39de8d646</aeskey><cdnthumbaeskey>456e10bba42c4ba0242e5ff39de8d646</cdnthumbaeskey><cdnthumblength>5154</cdnthumblength><cdnthumbheight>234</cdnthumbheight><cdnthumbwidth>234</cdnthumbwidth></appattach><websearch /></appmsg><appinfo><version>1</version><appname>Window wechat</appname></appinfo></msg>","type":5}
小程序:
xxxxxxxxxx
{"funid":21,"WeChatID":1,"wxid":"filehelper","content":"","type":21}
x{"funid":22,"WeChatID":1,"wxid":"filehelper","content":"<?xml version=\"1.0\"?><msg bigheadimgurl=\"http://wx.qlogo.cn/mmhead/ver_1/JGSU7YZiaAdhyALl6UftpJBLHfbwIHfUhmmcR9LW3OZvctLLFNic43aK4aPU8nN3MNeK6qyU7NImeVhiaiamDYOsalLYyyOrcA3S7NvLGtmHzZE/0\" smallheadimgurl=\"http://wx.qlogo.cn/mmhead/ver_1/JGSU7YZiaAdhyALl6UftpJBLHfbwIHfUhmmcR9LW3OZvctLLFNic43aK4aPU8nN3MNeK6qyU7NImeVhiaiamDYOsalLYyyOrcA3S7NvLGtmHzZE/132\" username=\"填写WXID\" nickname=\"蔡徐坤\" fullpy=\"aoliao\" shortpy=\"\" alias=\"19991203\" imagestatus=\"2\" scene=\"17\" province=\"福建\" city=\"中国\" sign=\"\" sex=\"1\" certflag=\"0\" certinfo=\"\" brandIconUrl=\"\" brandHomeUrl=\"\" brandSubscriptConfigUrl= \"\" brandFlags=\"0\" regionCode=\"CN_Fujian_Sanming\" />
"}
x{"funid":24,"WeChatID":1,"wxid":"filehelper","content":"写路径,如C:\\Users\\1\\Desktop\\1.png"}
x{"funid":24,"WeChatID":1,"wxid":"filehelper","content":"写路径,如C:\\Users\\1\\Desktop\\1.mp4"}
Socket连接,接收消息会发送到客户端
格式为 :
xxxxxxxxxx
{wxid: "91213123123@chatroom", content: "你好", attach: "wxid_1234560swv12", type: 1, WeChatID: 1}
0x3
群相关xxxxxxxxxx
{"funid":30,"WeChatID":1,"wxidlist":["filehelper","filehelper"]}
注明:群创建至少选择两个人,为了不必要的问题发生,不提供群ID返回值,请执行前备份好友列表对比创建后的好友列表
xxxxxxxxxx
{"funid":31/32,"WeChatID":1,"wxid":"12345678937@chatroom",wxidlist":["filehelper","filehelper"]}
注明:大群邀请("funid":32),为发送xml邀请,需要用户同意
xxxxxxxxxx
{"funid":33,"WeChatID":1,"wxid":"12345678937@chatroom"}
注明:返回的wxid为群主wxid,wxidlist数组为群成员列表wxid
xxxxxxxxxx
{"funid":34,"WeChatID":1,"wxid":"12345678937@chatroom","content":"写昵称,如我爱蔡徐坤"}
xxxxxxxxxx
{"funid":35,"WeChatID":1,"wxid":"12345678937@chatroom","content":"这是群公告"}
xxxxxxxxxx
{"funid":36,"WeChatID":1,"wxid":"12345678937@chatroom","wxidlist":["filehelper"]}
xxxxxxxxxx
{"funid":37,"WeChatID":1,"wxid":"12345678937@chatroom"}
0x4
好友相关xxxxxxxxxx
{"funid":40,"WeChatID":1}
包含微信、微信群、公众号等列表信息
xxxxxxxxxx
{"funid":41,"WeChatID":1,"wxid":"wxid_cxkcxkcxkcxkSB","content":"发送添加好友内容","type":14}
注明:群添加的type为14
xxxxxxxxxx
{"funid":42,"WeChatID":1,"wxid":"wxid_cxkcxkcxkcxkSB"}
xxxxxxxxxx
{"funid":43,"WeChatID":1,"wxid":"wxid_cxkcxkcxkcxkSB"}
0x5
其他功能xxxxxxxxxx
{"funid":50,"WeChatID":1,"wxid":"wxid_cxkcxkcxkcxkSB","transferid":"cxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxk"}
xxxxxxxxxx
{"funid":51,"WeChatID":1,"v1":"cxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxk","v4":"cxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxkcxk"}
xxxxxxxxxx
{"funid":52,"WeChatID":1,"url":"http://baidu.com"}
xxxxxxxxxx
{"funid":54,"WeChatID":1}
x{"funid":53,"path":"C:\1.dat"}
返回解密后的路径地址,后缀不一定
x{"code":1,"path":"C:\1.dat.jpg"}
暂未开放