Commit a4be63c 1 parent 61aa8ed commit a4be63c Copy full SHA for a4be63c
File tree 3 files changed +94
-0
lines changed
3 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 16
16
## 支持的微信版本下载
17
17
- [ WeChatSetup3.6.0.18.exe] ( https://webcdn.m.qq.com/spcmgr/download/WeChat3.6.0.18.exe )
18
18
19
+ ## 帮助文档
20
+ [ 常见问题] ( docs/FAQ.md )
21
+
19
22
## 安装
20
23
21
24
``` bash
Original file line number Diff line number Diff line change
1
+ ## 如何多开
2
+
3
+ 新建多个ntchat.WeChat实例,然后调用open方法:
4
+ ``` python
5
+ import ntchat
6
+
7
+ # 多开3个微信
8
+ for i in range (3 ):
9
+ wechat = ntchat.WeChat()
10
+ wechat.open(smart = False )
11
+ ```
12
+ 更完善的多实例管理查看[ fastapi_example例子] ( ./fastapi_example )
13
+
14
+ ## 如何监听输出所有的消息
15
+ ``` python
16
+ # 注册监听所有消息回调
17
+ @wechat.msg_register (ntchat.MT_ALL )
18
+ def on_recv_text_msg (wechat_instance : ntchat.WeChat, message ):
19
+ print (" ########################" )
20
+ print (message)
21
+ ```
22
+ 完全例子查看[ examples/msg_register_all.py] ( ../examples/msg_register_all.py )
23
+
24
+ ## 如何关闭NtChat的日志
25
+
26
+ ` os.environ['NTCHAT_LOG'] = "ERROR" ` 要在` import ntchat ` 前执行
27
+ ``` python
28
+ # -*- coding: utf-8 -*-
29
+ import os
30
+ import sys
31
+ import time
32
+ os.environ[' NTCHAT_LOG' ] = " ERROR"
33
+
34
+ import ntchat
35
+ ```
36
+
37
+ ## 如何正常的关闭Cmd窗口
38
+
39
+ 先使用` pip install pywin32 ` 安装pywin32模块, 然后在代码中添加以下代码, 完整例子查看[ examples/cmd_close_event.py] ( ../examples/cmd_close_event.py )
40
+ ``` python
41
+ import sys
42
+ import ntchat
43
+ import win32api
44
+
45
+ def on_exit (sig , func = None ):
46
+ ntchat.exit_()
47
+ sys.exit()
48
+
49
+
50
+ # 当关闭cmd窗口时
51
+ win32api.SetConsoleCtrlHandler(on_exit, True )
52
+ ```
53
+
54
+
55
+ ## pyinstaller打包exe
56
+ 使用pyinstaller打包NtChat项目,需要添加` --collect-data=ntchat ` 选项
57
+
58
+ 打包成单个exe程序
59
+ ``` bash
60
+ pyinstaller -F --collect-data=ntchat main.py
61
+ ```
62
+
63
+ 将所有的依赖文件打包到一个目录中
64
+ ``` bash
65
+ pyinstaller -y --collect-data=ntchat main.py
66
+ ```
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ import sys
3
+ import time
4
+ import ntchat
5
+
6
+ wechat = ntchat .WeChat ()
7
+
8
+ # 打开pc微信, smart: 是否管理已经登录的微信
9
+ wechat .open (smart = True )
10
+
11
+
12
+ # 注册监听所有消息回调
13
+ @wechat .msg_register (ntchat .MT_ALL )
14
+ def on_recv_text_msg (wechat_instance : ntchat .WeChat , message ):
15
+ print ("########################" )
16
+ print (message )
17
+
18
+
19
+ # 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
20
+ try :
21
+ while True :
22
+ time .sleep (0.5 )
23
+ except KeyboardInterrupt :
24
+ ntchat .exit_ ()
25
+ sys .exit ()
You can’t perform that action at this time.
0 commit comments