├── .github
└── workflows
│ └── pythonapp.yml
├── .idea
├── .gitignore
├── inspectionProfiles
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── vcs.xml
└── weixin.iml
├── README.md
├── image
├── dalog.jpg
├── dalog2.jpg
├── lan.jpg
└── wechat.jpg
└── wechat.py
/.github/workflows/pythonapp.yml:
--------------------------------------------------------------------------------
1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3 |
4 | name: Python application
5 |
6 | on:
7 | push:
8 | branches: [ master ]
9 | pull_request:
10 | branches: [ master ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 | - name: Set up Python 3.8
20 | uses: actions/setup-python@v1
21 | with:
22 | python-version: 3.8
23 |
24 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/weixin.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # weixin
2 | 因为现在网页版微信不能使用,所以iChat的使用受到限制
3 | (python) 使用window微信客服端向指定用户/群发送信息
4 | 代码用到了,OpenCV和操作模拟(用来模拟人为的操作)
5 | 初始化class时,传入本地微信客服端所在的目录
6 | eg:wechat = wechat('C:\Program Files (x86)\Tencent\WeChat')
7 | #打开微信
8 | wechat.open_wechat()
9 | #寻找需要发送信息的用户/群
10 | wechat.send_msg_obj('测试目标人')
11 | #需要发送的文本
12 | wechat.send_msg('测试一下')
13 | #微信客服端格式控制(换行)
14 | wechat.huang_hang()
15 | #信息发送
16 | wechat.send()
17 |
--------------------------------------------------------------------------------
/image/dalog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ztrxRestful/weixin/8a7fb673c51872a06fa5ea021593e159b348c100/image/dalog.jpg
--------------------------------------------------------------------------------
/image/dalog2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ztrxRestful/weixin/8a7fb673c51872a06fa5ea021593e159b348c100/image/dalog2.jpg
--------------------------------------------------------------------------------
/image/lan.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ztrxRestful/weixin/8a7fb673c51872a06fa5ea021593e159b348c100/image/lan.jpg
--------------------------------------------------------------------------------
/image/wechat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ztrxRestful/weixin/8a7fb673c51872a06fa5ea021593e159b348c100/image/wechat.jpg
--------------------------------------------------------------------------------
/wechat.py:
--------------------------------------------------------------------------------
1 | import cv2 as cv
2 | import pyautogui
3 | import pyperclip
4 | import os
5 | import time
6 |
7 | from PIL import ImageGrab
8 |
9 | class wechat():
10 | def __init__(self,wechat_path):
11 | self.wechat_path = wechat_path
12 |
13 | path = os.getcwd().replace('\\', '/')
14 | def scanner_img(self,name):
15 | clip = ImageGrab.grab()
16 | # clip = ImageGrab.grabclipboard()
17 |
18 | if (clip != None):
19 |
20 | clip.save(self.path+"/image/" + name + ".jpg")
21 | return self.path+"/image/" + name + ".jpg"
22 | return "err"
23 |
24 | def find_image(self,obj_path, src_path):
25 | source = cv.imread(src_path)
26 | template = cv.imread(obj_path)
27 | result = cv.matchTemplate(source, template, cv.TM_CCOEFF_NORMED)
28 |
29 | pos_start = cv.minMaxLoc(result)[3]
30 |
31 | x = int(pos_start[0]) + int(template.shape[1] / 2)
32 | y = int(pos_start[1]) + int(template.shape[0] / 2)
33 | similarity = cv.minMaxLoc(result)[1]
34 | if similarity < 0.85:
35 | return (-1, -1)
36 | else:
37 | return (x, y)
38 |
39 | def check_img(self,obj_path, src_path):
40 | x = -1
41 | y = -1
42 | while x == -1:
43 | x, y = self.find_image(obj_path, src_path)
44 | #print(x,y)
45 | return (x, y)
46 |
47 | '''
48 | 打开微信(需要用户自己截取屏幕上的微信图片,已jpg形式放在image文件夹下)
49 | '''
50 | def open_wechat_cv(self):
51 | pyautogui.hotkey('win', 'd')
52 | # res_name = gitBigImg.git_src_img("temp")
53 | res_name = self.scanner_img("temp")
54 | src_path = res_name
55 | #print(src_path)
56 | obj_path = self.path+'/image/wechat.jpg'
57 | x, y = self.check_img(obj_path, src_path)
58 |
59 | # pyautogui.hotkey('win','d')
60 | time.sleep(1)
61 | # pyautogui.moveTo(res[0][0],res[0][1],duration=2)
62 | pyautogui.doubleClick(x, y)
63 |
64 | def open_wechat(self):
65 | pyautogui.hotkey('win', 'd')
66 | cmd = self.wechat_path+''
67 | file = os.popen(cmd)
68 | #print(file)
69 | file.close()
70 | time.sleep(2)
71 |
72 | def send_msg_obj(self,name):
73 | # res_name = gitBigImg.git_src_img("temp2")
74 | res_name = self.scanner_img("temp2")
75 |
76 | src_path = res_name
77 | # 寻找搜索图片
78 | obj_path = self.path+'/image/lan.jpg'
79 | x, y = self.find_image(obj_path, src_path)
80 | pyautogui.click(x, y)
81 | time.sleep(1)
82 |
83 | pyperclip.copy(name)
84 |
85 | pyautogui.hotkey('ctrl', 'v')
86 | time.sleep(1)
87 | #print(x,y)
88 | pyautogui.hotkey('enter')
89 |
90 | '''
91 | 需要发送的信息文本
92 | '''
93 | def send_msg(self,text):
94 | pyperclip.copy(text)
95 | pyautogui.hotkey('ctrl', 'v')
96 |
97 | '''
98 | 微信换行
99 | '''
100 | def huang_hang(self):
101 | pyautogui.hotkey('shift', 'enter')
102 | '''
103 | 信息发送
104 | '''
105 | def send(self):
106 | pyautogui.hotkey('enter')
107 |
108 | if __name__ == '__main__':
109 | #使用class时,需要初始化微信的所在位置
110 | wechat = wechat('C:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe')
111 | wechat.open_wechat()
112 | wechat.send_msg_obj('测试目标')
113 | wechat.send_msg('测试一下')
114 | wechat.huang_hang()
115 | wechat.send_msg('再来一遍')
116 | wechat.send()
117 |
--------------------------------------------------------------------------------