0%

glados每日签到并发送微信通知

通过Github Action自动定时运行checkin.py脚本,每日进行GLaDOS的签到,并发送通知到自己的微信上。

1. 准备工作

1.1 github action

  • 通过Github Action自动定时运行checkin.py脚本。

  • 登录GLaDOS后获取cookies。(简单获取方法:浏览器快捷键F12,打开调试窗口,点击“network”获取)

  • 然后通过“Server酱”(http://sc.ftqq.com/3.version),自动发通知到微信上。

  • 可以发送到自己的企业微信

1.2 企业微信

Wecom酱是通过企业微信推送消息到微信的消息推送函数和在线服务方案,开源免费,可自己搭建。支持多语言。

优点:

  1. 一次配置,持续使用
  2. 配置好以后,只需要微信就能收消息,不再需要安装企业微信客户端
  3. 消息接口无需认证即可使用,个人用微信就可以注册
1.2.1 操作流程
  • 用电脑打开企业微信官网,注册一个企业
  • 注册成功后,点「管理企业」进入管理界面,选择「应用管理」 → 「自建」 → 「创建应用」
  • 创建完成后进入应用详情页,可以得到应用ID( agentid )①,应用Secret( secret )②。注意:secret推送到手机端时,只能在企业微信客户端中查看。
  • 进入「我的企业」页面,拉到最下边,可以看到企业ID③,复制并填到上方。
  • 进入「我的企业」 → 「微信插件」,拉到下边扫描二维码,关注以后即可收到推送的消息。
  • 进入「我的企业」 → 「微信插件」,拉到最下方,勾选 “允许成员在微信插件中接收和回复聊天消息”
  • 在企业微信客户端 「我」 → 「设置」 → 「新消息通知」中关闭 “仅在企业微信中接受消息” 限制条件

2. workflow

2.1 checkin.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
name: glados-checkin

on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: 0 10,16 * * *
#
# https://tool.lu/crontab/
# https://datetime360.com/cn/utc-cst-china-time/
#watch:
# types: started

jobs:
checkin:
runs-on: ubuntu-latest
#if: github.event.repository.owner.id == github.event.sender.id
# https://p3terx.com/archives/github-actions-manual-trigger.html

steps:
- uses: actions/checkout@v2

- name: Install Python
run: |
sudo apt update && \
sudo apt install python3

- name: requirements
run: |
pip3 install -r requirements.txt
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Checkin
run: |
python3 checkin.py
env:
WECHAT_SECRET: ${{ secrets.WECHAT_SECRET }}
SERVE: ${{ secrets.SERVE }}
SCKEY: ${{ secrets.SCKEY }}
COOKIE: ${{ secrets.COOKIE }}

2.2 checkin.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import json,requests,json,os

# server酱开关,填off不开启(默认),填on同时开启cookie失效通知和签到成功通知
sever = os.environ["SERVE"]
# 填写server酱sckey,不开启server酱则不用填
sckey = os.environ["SCKEY"]
# 填入glados账号对应cookie
cookie = os.environ["COOKIE"]
# 企业微信的密钥
wsecret = os.environ["WECHAT_SECRET"]


def send_to_wecom(text,wecom_cid,wecom_aid,wecom_secret,wecom_touid='@all'):
get_token_url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={wecom_cid}&corpsecret={wecom_secret}"
response = requests.get(get_token_url).content
access_token = json.loads(response).get('access_token')
if access_token and len(access_token) > 0:
send_msg_url = f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}'
data = {
"touser":wecom_touid,
"agentid":wecom_aid,
"msgtype":"text",
"text":{
"content":text
},
"duplicate_check_interval":600
}
response = requests.post(send_msg_url,data=json.dumps(data)).content
return response
else:
return False

def send_to_wecom_image(base64_content,wecom_cid,wecom_aid,wecom_secret,wecom_touid='@all'):
get_token_url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={wecom_cid}&corpsecret={wecom_secret}"
response = requests.get(get_token_url).content
access_token = json.loads(response).get('access_token')
if access_token and len(access_token) > 0:
upload_url = f'https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={access_token}&type=image'
upload_response = requests.post(upload_url, files={
"picture": base64.b64decode(base64_content)
}).json()
if "media_id" in upload_response:
media_id = upload_response['media_id']
else:
return False

send_msg_url = f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}'
data = {
"touser":wecom_touid,
"agentid":wecom_aid,
"msgtype":"image",
"image":{
"media_id": media_id
},
"duplicate_check_interval":600
}
response = requests.post(send_msg_url,data=json.dumps(data)).content
return response
else:
return False

def send_to_wecom_markdown(text,wecom_cid,wecom_aid,wecom_secret,wecom_touid='@all'):
get_token_url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={wecom_cid}&corpsecret={wecom_secret}"
response = requests.get(get_token_url).content
access_token = json.loads(response).get('access_token')
if access_token and len(access_token) > 0:
send_msg_url = f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}'
data = {
"touser":wecom_touid,
"agentid":wecom_aid,
"msgtype":"markdown",
"markdown":{
"content":text
},
"duplicate_check_interval":600
}
response = requests.post(send_msg_url,data=json.dumps(data)).content
return response
else:
return False


def start():
url= "https://glados.rocks/api/user/checkin"
url2= "https://glados.rocks/api/user/status"
url3= "https://glados.rocks/api/user/traffic"
referer = 'https://glados.rocks/console/checkin'
origin = "https://glados.rocks"
useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"
payload={
'token': 'glados_network'
}
checkin = requests.post(url,headers={'cookie': cookie ,'referer': referer,'origin':origin,'user-agent':useragent,'content-type':'application/json;charset=UTF-8'},data=json.dumps(payload))
state = requests.get(url2,headers={'cookie': cookie ,'referer': referer,'origin':origin,'user-agent':useragent})
traffic = requests.get(url3,headers={'cookie': cookie ,'referer': referer,'origin':origin,'user-agent':useragent})
today = traffic.json()['data']['today']
str = "cookie过期"
if 'message' in checkin.text:
mess = checkin.json()['message']
time = state.json()['data']['leftDays']
time = time.split('.')[0]
str = '[pro] %s , you have %s days left. use: %.3f G' % (mess, time,today/1024/1024/1024)
if sever == '1' or sever == 'on':
requests.get('https://sc.ftqq.com/' + sckey + '.send?text='+str)
else:
requests.get('https://sc.ftqq.com/' + sckey + '.send?text='+str)

ret = send_to_wecom(str, "wwc216d22335b2bb48", "1000002", wsecret) # 换成自己的企业微信id
print(str, ret)

def main_handler(event, context):
return start()

if __name__ == '__main__':
start()

2.3 设置仓库私有变量

image-20220210222931325
  • COOKIE(Glados的cookie, 必填)
  • SERVE(server酱开关,默认是off,填on的话,会同时开启cookie失效通知和签到成功通知)
  • SCKEY(填写server酱sckey,不开启server酱则不用填)
  • WECHAT_SECRET(自己企业微信的密钥)

3. 参考资料

给作者打赏,可以加首页微信,咨询作者相关问题!