Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ba4c78b

Browse files
committed
微信公众号自动回复
1 parent 057795b commit ba4c78b

File tree

15 files changed

+518
-4
lines changed

15 files changed

+518
-4
lines changed

.idea/dataSources.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deployment.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tkinter_learn/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @Time : 2019/11/11 18:53
22
# @Author : Libuda
3-
# @FileName: test.py
3+
# @FileName: mytest.py
44
# @Software: PyCharm
55
# coding:utf-8
66
import requests

图片过滤脚本/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @Time : 2019/11/28 16:26
22
# @Author : Libuda
3-
# @FileName: test.py
3+
# @FileName: mytest.py
44
# @Software: PyCharm
55

66
# 删除

微信公众号/check_link.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# @Time : 2019/12/4 18:31
2+
# @Author : Libuda
3+
# @FileName: check_link.py
4+
# @Software: PyCharm
5+
import time
6+
from selenium import webdriver
7+
import xlrd
8+
from xlutils.copy import copy
9+
10+
11+
def get_keywords_data(tables, row, col):
12+
actual_data = tables.cell_value(row, col)
13+
return actual_data
14+
15+
16+
def write_to_excel(file_path, row, col, value):
17+
work_book = xlrd.open_workbook(file_path, formatting_info=False)
18+
write_to_work = copy(work_book)
19+
sheet_data = write_to_work.get_sheet(0)
20+
sheet_data.write(row, col, str(value))
21+
write_to_work.save(file_path)
22+
23+
24+
def get_links():
25+
res = []
26+
count = 0
27+
link_data = [get_keywords_data(link_tables, i, link_get_col) for i in range(1, link_tables.nrows)]
28+
for index, link in enumerate(link_data):
29+
driver.get(link)
30+
time.sleep(wait_time)
31+
try:
32+
text = driver.find_element_by_xpath("/html/body/div[1]/div[1]/p[1]")
33+
if text.text == "开卡失败":
34+
write_to_excel(link_file_path, index + 1, link_write_col, "已使用")
35+
print("该卡已经被使用..{}".format(link))
36+
except Exception as e:
37+
count += 1
38+
res.append(link)
39+
print("该卡可以使用:{}".format(link))
40+
print("当前可使用链接个数为:{}".format(count))
41+
return res
42+
43+
44+
if __name__ == '__main__':
45+
wait_time = 3
46+
driver = webdriver.Chrome(r"C:\Users\lenovo\PycharmProjects\Spider\chromedriver.exe")
47+
link_file_path = r"C:\Users\lenovo\PycharmProjects\leetcode-python-\微信公众号\link.xls"
48+
link_ecel = xlrd.open_workbook(link_file_path)
49+
link_tables = link_ecel.sheet_by_index(0)
50+
link_get_col = 2
51+
link_write_col = 3
52+
link_can_use_index = 1
53+
54+
res = get_links()
55+
print(res)

微信公众号/link.xls

29 KB
Binary file not shown.

微信公众号/mytest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# @Time : 2019/12/10 12:56
2+
# @Author : Libuda
3+
# @FileName: mytest.py
4+
# @Software: PyCharm
5+
6+
# coding:utf-8
7+
# Filename:hello_world.py
8+
# 验证服务器,并且收到的所有消息都回复'Hello World!'
9+
10+
import werobot
11+
12+
robot = werobot.WeRoBot(token='asdfghgfdsaasdfggfdsasdf')
13+
14+
15+
# @robot.handler 处理所有消息
16+
@robot.handler
17+
def hello(message):
18+
return '我是你爸爸!'
19+
20+
21+
# 让服务器监听在 0.0.0.0:80
22+
robot.config['HOST'] = '0.0.0.0'
23+
robot.config['PORT'] = 80
24+
robot.run()

微信公众号/openid

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
orPluv_D_73q9o1NiEy01swBqlkU
2+
orPluv7QZKHA6HDkdLXjt6mpJU7g
3+
orPluv_EMnOamfiacy7FOiNzE8Eg
4+
orPluv03oZHNS8iNM0jzBehDOmtI

微信公众号/phone_number.xls

24 KB
Binary file not shown.

微信公众号/webot.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# @Time : 2019/12/10 12:00
2+
# @Author : Libuda
3+
# @FileName: webot.py
4+
# @Software: PyCharm
5+
import requests
6+
from werobot import WeRoBot
7+
import xlrd
8+
9+
from check_link import get_keywords_data
10+
11+
appID = 'wxf74f52d6e57f9e0e'
12+
appsecret = 'c63f351e9a9041d03da9370948de1f16'
13+
token = 'asdfghgfdsaasdfggfdsasdf'
14+
robot = WeRoBot(token=token)
15+
16+
link_file_path = r"C:\Users\lenovo\PycharmProjects\leetcode-python-\微信公众号\link.xls"
17+
link_ecel = xlrd.open_workbook(link_file_path)
18+
link_tables = link_ecel.sheet_by_index(0)
19+
link_get_col = 2
20+
link_write_col = 3
21+
link_data = [get_keywords_data(link_tables, i, link_get_col) for i in range(1, link_tables.nrows)]
22+
23+
openid_file_path = r'C:\Users\lenovo\PycharmProjects\leetcode-python-\微信公众号\openid'
24+
25+
26+
def get_access_token():
27+
"""
28+
获取accestoken
29+
:return:
30+
"""
31+
get_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}'.format(appID,
32+
appsecret)
33+
response = requests.get(get_url).json()
34+
if 'errcode' in response:
35+
return False
36+
elif 'access_token' in response:
37+
return response['access_token']
38+
39+
40+
def get_user_list():
41+
"""
42+
获取关注者的openid
43+
:return:
44+
"""
45+
openid_lis = []
46+
acces_token = get_access_token()
47+
get_url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token={}&next_openid='.format(acces_token)
48+
# print(get_url)
49+
response = requests.get(get_url).json()
50+
# print(response)
51+
if 'errcode' in response:
52+
return openid_lis
53+
elif 'data' in response:
54+
openid_lis = response['data']['openid']
55+
56+
return openid_lis
57+
58+
59+
# 被关注
60+
@robot.subscribe
61+
def subscribe(message):
62+
data = "回复数字“14”,公众号自动发送一条14天卡链接给客户(每个微信号限领取一个链接)"
63+
return data
64+
65+
66+
def check_user(openid_lis):
67+
with open(openid_file_path, 'r') as f:
68+
data = f.readlines()
69+
if len(data) == 0:
70+
for one in openid_lis:
71+
with open(openid_file_path, 'a') as f:
72+
f.write(one + "\n")
73+
return True
74+
else:
75+
res = []
76+
for one in data:
77+
res.append(one.replace('\n', ''))
78+
print(res)
79+
for one in openid_lis:
80+
if one not in res:
81+
with open(openid_file_path, 'a') as f:
82+
f.write(one + "\n")
83+
return True
84+
return False
85+
86+
87+
@robot.filter('14')
88+
def joke():
89+
openid_lis = get_user_list()
90+
if check_user(openid_lis):
91+
data = link_data.pop()
92+
else:
93+
data = '温馨提示:每个用户限领一次14天VIP会员,你已领取。如需帮助,请咨询客服微信:95499954'
94+
return data
95+
96+
97+
# 其他消息返回
98+
@robot.handler
99+
def hello(message):
100+
return '(O_o)??'
101+
102+
103+
if __name__ == '__main__':
104+
robot.config['HOST'] = '0.0.0.0'
105+
robot.config['PORT'] = 80
106+
robot.run()

0 commit comments

Comments
 (0)