├── README.md ├── check_in.py └── sendNotify.py /README.md: -------------------------------------------------------------------------------- 1 | # 拉库指令 2 | ### 国外机直接用以下面命令: 3 | ``` 4 | ql repo https://github.com/akinlau/glados_checkin.git "check_in.py" "backUp|README.md" "sendNotify.py" 5 | ``` 6 | 7 | # 使用流程 8 | ### 1、青龙部署。 9 | 10 | ### 2、修改青龙config.sh配置,添加企业微信信息保存 11 | 12 | ### 3、新建拉库任务,并执行,刷新浏览器即可看到添加的任务。 13 | 14 | ### 4、添加GR_COOKIE环境变量(登录https://glados.rocks/,按f12--网络--标头--请求标头--cookie,复制cookie后面的值) 15 | 16 | ### 5、添加GR_TOKEN环境变量(登录https://glados.rocks/,按f12--网络--负载--token,复制token后面的值) 17 | 18 | ### 6、依赖管理选python新建依赖安装requests 19 | -------------------------------------------------------------------------------- /check_in.py: -------------------------------------------------------------------------------- 1 | import requests,json,os,sys 2 | 3 | 4 | # 在青龙面板环境变量添加GR_COOKIE,并登录https://glados.rocks,按f12--网络--标头--请求标头--cookie,复制cookie后面的值 5 | try: 6 | if "GR_COOKIE" in os.environ: 7 | if len(os.environ["GR_COOKIE"]) > 10: 8 | cookie = os.environ["GR_COOKIE"] 9 | print(f"\n当前从环境变量获取CK\n") 10 | except Exception as e: 11 | print(f"获取cookie失败:{e}") 12 | 13 | # 在青龙面板环境变量添加GR_TOKEN,并登录https://glados.rocks,按f12--网络--负载--token,复制token后面的值 14 | try: 15 | if "GR_TOKEN" in os.environ: 16 | if len(os.environ["GR_TOKEN"]) > 6: 17 | token = os.environ["GR_TOKEN"] 18 | print(f"\n当前从环境变量获取TOKEN\n") 19 | except Exception as e: 20 | print(f"获取TOKEN失败:{e}") 21 | 22 | 23 | def load_send(): 24 | global send 25 | cur_path = os.path.abspath(os.path.dirname(__file__)) 26 | sys.path.append(cur_path) 27 | if os.path.exists(cur_path + "/sendNotify.py"): 28 | try: 29 | from sendNotify import send 30 | except: 31 | send=False 32 | print("加载通知服务失败~") 33 | else: 34 | send=False 35 | print("加载通知服务失败~") 36 | 37 | 38 | def checkin(): 39 | url= "https://glados.rocks/api/user/checkin" 40 | url2= "https://glados.rocks/api/user/status" 41 | referer = 'https://glados.rocks/console/checkin' 42 | origin = "https://glados.rocks" 43 | useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36" 44 | payload={ 45 | 'token': token 46 | } 47 | 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)) 48 | state = requests.get(url2,headers={'cookie': cookie ,'referer': referer,'origin':origin,'user-agent':useragent}) 49 | mess = checkin.json()['message'] 50 | time = state.json()['data']['leftDays'] 51 | time = time.split('.')[0] 52 | return mess,time 53 | 54 | 55 | if __name__ == '__main__': 56 | title = "GlaDOS签到通知" 57 | ret,remain = checkin() 58 | newline = "\n" 59 | content = f"签到结果:{ret}{newline}剩余天数:{remain}" 60 | load_send() 61 | send(title,content) 62 | -------------------------------------------------------------------------------- /sendNotify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # _*_ coding:utf-8 _*_ 3 | 4 | #Modify: Kirin 5 | 6 | import sys 7 | import os, re 8 | import requests 9 | import json 10 | import time 11 | import hmac 12 | import hashlib 13 | import base64 14 | import urllib.parse 15 | from requests.adapters import HTTPAdapter 16 | from urllib3.util import Retry 17 | 18 | cur_path = os.path.abspath(os.path.dirname(__file__)) 19 | root_path = os.path.split(cur_path)[0] 20 | sys.path.append(root_path) 21 | 22 | # 通知服务 23 | BARK = '' # bark服务,自行搜索; secrets可填; 24 | BARK_PUSH='' # bark自建服务器,要填完整链接,结尾的/不要 25 | PUSH_KEY = '' # Server酱的PUSH_KEY; secrets可填 26 | TG_BOT_TOKEN = '' # tg机器人的TG_BOT_TOKEN; secrets可填1407203283:AAG9rt-6RDaaX0HBLZQq0laNOh898iFYaRQ 27 | TG_USER_ID = '' # tg机器人的TG_USER_ID; secrets可填 1434078534 28 | TG_API_HOST='' # tg 代理api 29 | TG_PROXY_IP = '' # tg机器人的TG_PROXY_IP; secrets可填 30 | TG_PROXY_PORT = '' # tg机器人的TG_PROXY_PORT; secrets可填 31 | DD_BOT_TOKEN = '' # 钉钉机器人的DD_BOT_TOKEN; secrets可填 32 | DD_BOT_SECRET = '' # 钉钉机器人的DD_BOT_SECRET; secrets可填 33 | QQ_SKEY = '' # qq机器人的QQ_SKEY; secrets可填 34 | QQ_MODE = '' # qq机器人的QQ_MODE; secrets可填 35 | QYWX_AM = '' # 企业微信 36 | QYWX_KEY = '' # 企业微信BOT 37 | PUSH_PLUS_TOKEN = '' # 微信推送Plus+ 38 | 39 | notify_mode = [] 40 | 41 | message_info = '''''' 42 | 43 | # GitHub action运行需要填写对应的secrets 44 | if "BARK" in os.environ and os.environ["BARK"]: 45 | BARK = os.environ["BARK"] 46 | if "BARK_PUSH" in os.environ and os.environ["BARK_PUSH"]: 47 | BARK_PUSH = os.environ["BARK_PUSH"] 48 | if "PUSH_KEY" in os.environ and os.environ["PUSH_KEY"]: 49 | PUSH_KEY = os.environ["PUSH_KEY"] 50 | if "TG_BOT_TOKEN" in os.environ and os.environ["TG_BOT_TOKEN"] and "TG_USER_ID" in os.environ and os.environ["TG_USER_ID"]: 51 | TG_BOT_TOKEN = os.environ["TG_BOT_TOKEN"] 52 | TG_USER_ID = os.environ["TG_USER_ID"] 53 | if "TG_API_HOST" in os.environ and os.environ["TG_API_HOST"]: 54 | TG_API_HOST = os.environ["TG_API_HOST"] 55 | if "DD_BOT_TOKEN" in os.environ and os.environ["DD_BOT_TOKEN"] and "DD_BOT_SECRET" in os.environ and os.environ["DD_BOT_SECRET"]: 56 | DD_BOT_TOKEN = os.environ["DD_BOT_TOKEN"] 57 | DD_BOT_SECRET = os.environ["DD_BOT_SECRET"] 58 | if "QQ_SKEY" in os.environ and os.environ["QQ_SKEY"] and "QQ_MODE" in os.environ and os.environ["QQ_MODE"]: 59 | QQ_SKEY = os.environ["QQ_SKEY"] 60 | QQ_MODE = os.environ["QQ_MODE"] 61 | # 获取pushplus+ PUSH_PLUS_TOKEN 62 | if "PUSH_PLUS_TOKEN" in os.environ: 63 | if len(os.environ["PUSH_PLUS_TOKEN"]) > 1: 64 | PUSH_PLUS_TOKEN = os.environ["PUSH_PLUS_TOKEN"] 65 | # print("已获取并使用Env环境 PUSH_PLUS_TOKEN") 66 | # 获取企业微信应用推送 QYWX_AM 67 | if "QYWX_AM" in os.environ: 68 | if len(os.environ["QYWX_AM"]) > 1: 69 | QYWX_AM = os.environ["QYWX_AM"] 70 | 71 | 72 | if "QYWX_KEY" in os.environ: 73 | if len(os.environ["QYWX_KEY"]) > 1: 74 | QYWX_KEY = os.environ["QYWX_KEY"] 75 | # print("已获取并使用Env环境 QYWX_AM") 76 | 77 | if BARK: 78 | notify_mode.append('bark') 79 | # print("BARK 推送打开") 80 | if BARK_PUSH: 81 | notify_mode.append('bark') 82 | # print("BARK 推送打开") 83 | if PUSH_KEY: 84 | notify_mode.append('sc_key') 85 | # print("Server酱 推送打开") 86 | if TG_BOT_TOKEN and TG_USER_ID: 87 | notify_mode.append('telegram_bot') 88 | # print("Telegram 推送打开") 89 | if DD_BOT_TOKEN and DD_BOT_SECRET: 90 | notify_mode.append('dingding_bot') 91 | # print("钉钉机器人 推送打开") 92 | if QQ_SKEY and QQ_MODE: 93 | notify_mode.append('coolpush_bot') 94 | # print("QQ机器人 推送打开") 95 | 96 | if PUSH_PLUS_TOKEN: 97 | notify_mode.append('pushplus_bot') 98 | # print("微信推送Plus机器人 推送打开") 99 | if QYWX_AM: 100 | notify_mode.append('wecom_app') 101 | # print("企业微信机器人 推送打开") 102 | 103 | if QYWX_KEY: 104 | notify_mode.append('wecom_key') 105 | # print("企业微信机器人 推送打开") 106 | 107 | 108 | def message(str_msg): 109 | global message_info 110 | print(str_msg) 111 | message_info = "{}\n{}".format(message_info, str_msg) 112 | sys.stdout.flush() 113 | 114 | def bark(title, content): 115 | print("\n") 116 | if BARK: 117 | try: 118 | response = requests.get( 119 | f"""https://api.day.app/{BARK}/{title}/{urllib.parse.quote_plus(content)}""").json() 120 | if response['code'] == 200: 121 | print('推送成功!') 122 | else: 123 | print('推送失败!') 124 | except: 125 | print('推送失败!') 126 | if BARK_PUSH: 127 | try: 128 | response = requests.get( 129 | f"""{BARK_PUSH}/{title}/{urllib.parse.quote_plus(content)}""").json() 130 | if response['code'] == 200: 131 | print('推送成功!') 132 | else: 133 | print('推送失败!') 134 | except: 135 | print('推送失败!') 136 | print("bark服务启动") 137 | if BARK=='' and BARK_PUSH=='': 138 | print("bark服务的bark_token未设置!!\n取消推送") 139 | return 140 | 141 | def serverJ(title, content): 142 | print("\n") 143 | if not PUSH_KEY: 144 | print("server酱服务的PUSH_KEY未设置!!\n取消推送") 145 | return 146 | print("serverJ服务启动") 147 | data = { 148 | "text": title, 149 | "desp": content.replace("\n", "\n\n") 150 | } 151 | response = requests.post(f"https://sc.ftqq.com/{PUSH_KEY}.send", data=data).json() 152 | if response['errno'] == 0: 153 | print('推送成功!') 154 | else: 155 | print('推送失败!') 156 | 157 | # tg通知 158 | def telegram_bot(title, content): 159 | try: 160 | print("\n") 161 | bot_token = TG_BOT_TOKEN 162 | user_id = TG_USER_ID 163 | if not bot_token or not user_id: 164 | print("tg服务的bot_token或者user_id未设置!!\n取消推送") 165 | return 166 | print("tg服务启动") 167 | if TG_API_HOST: 168 | if 'http' in TG_API_HOST: 169 | url = f"{TG_API_HOST}/bot{TG_BOT_TOKEN}/sendMessage" 170 | else: 171 | url = f"https://{TG_API_HOST}/bot{TG_BOT_TOKEN}/sendMessage" 172 | else: 173 | url = f"https://api.telegram.org/bot{TG_BOT_TOKEN}/sendMessage" 174 | 175 | headers = {'Content-Type': 'application/x-www-form-urlencoded'} 176 | payload = {'chat_id': str(TG_USER_ID), 'text': f'{title}\n\n{content}', 'disable_web_page_preview': 'true'} 177 | proxies = None 178 | if TG_PROXY_IP and TG_PROXY_PORT: 179 | proxyStr = "http://{}:{}".format(TG_PROXY_IP, TG_PROXY_PORT) 180 | proxies = {"http": proxyStr, "https": proxyStr} 181 | try: 182 | response = requests.post(url=url, headers=headers, params=payload, proxies=proxies).json() 183 | except: 184 | print('推送失败!') 185 | if response['ok']: 186 | print('推送成功!') 187 | else: 188 | print('推送失败!') 189 | except Exception as e: 190 | print(e) 191 | 192 | def dingding_bot(title, content): 193 | timestamp = str(round(time.time() * 1000)) # 时间戳 194 | secret_enc = DD_BOT_SECRET.encode('utf-8') 195 | string_to_sign = '{}\n{}'.format(timestamp, DD_BOT_SECRET) 196 | string_to_sign_enc = string_to_sign.encode('utf-8') 197 | hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() 198 | sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) # 签名 199 | print('开始使用 钉钉机器人 推送消息...', end='') 200 | url = f'https://oapi.dingtalk.com/robot/send?access_token={DD_BOT_TOKEN}×tamp={timestamp}&sign={sign}' 201 | headers = {'Content-Type': 'application/json;charset=utf-8'} 202 | data = { 203 | 'msgtype': 'text', 204 | 'text': {'content': f'{title}\n\n{content}'} 205 | } 206 | response = requests.post(url=url, data=json.dumps(data), headers=headers, timeout=15).json() 207 | if not response['errcode']: 208 | print('推送成功!') 209 | else: 210 | print('推送失败!') 211 | 212 | def coolpush_bot(title, content): 213 | print("\n") 214 | if not QQ_SKEY or not QQ_MODE: 215 | print("qq服务的QQ_SKEY或者QQ_MODE未设置!!\n取消推送") 216 | return 217 | print("qq服务启动") 218 | url=f"https://qmsg.zendee.cn/{QQ_MODE}/{QQ_SKEY}" 219 | payload = {'msg': f"{title}\n\n{content}".encode('utf-8')} 220 | response = requests.post(url=url, params=payload).json() 221 | if response['code'] == 0: 222 | print('推送成功!') 223 | else: 224 | print('推送失败!') 225 | # push推送 226 | def pushplus_bot(title, content): 227 | try: 228 | print("\n") 229 | if not PUSH_PLUS_TOKEN: 230 | print("PUSHPLUS服务的token未设置!!\n取消推送") 231 | return 232 | print("PUSHPLUS服务启动") 233 | url = 'http://www.pushplus.plus/send' 234 | data = { 235 | "token": PUSH_PLUS_TOKEN, 236 | "title": title, 237 | "content": content 238 | } 239 | body = json.dumps(data).encode(encoding='utf-8') 240 | headers = {'Content-Type': 'application/json'} 241 | response = requests.post(url=url, data=body, headers=headers).json() 242 | if response['code'] == 200: 243 | print('推送成功!') 244 | else: 245 | print('推送失败!') 246 | except Exception as e: 247 | print(e) 248 | 249 | def wecom_key(title, content): 250 | print("\n") 251 | if not QYWX_KEY: 252 | print("QYWX_KEY未设置!!\n取消推送") 253 | return 254 | print("QYWX_KEY服务启动") 255 | print("content"+content) 256 | headers = {'Content-Type': 'application/json'} 257 | data = { 258 | "msgtype":"text", 259 | "text":{ 260 | "content":title+"\n"+content.replace("\n", "\n\n") 261 | } 262 | } 263 | 264 | print(f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={QYWX_KEY}") 265 | response = requests.post(f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={QYWX_KEY}", json=data,headers=headers).json() 266 | print(response) 267 | 268 | 269 | # 企业微信 APP 推送 270 | def wecom_app(title, content): 271 | try: 272 | if not QYWX_AM: 273 | print("QYWX_AM 并未设置!!\n取消推送") 274 | return 275 | QYWX_AM_AY = re.split(',', QYWX_AM) 276 | if 4 < len(QYWX_AM_AY) > 5: 277 | print("QYWX_AM 设置错误!!\n取消推送") 278 | return 279 | corpid = QYWX_AM_AY[0] 280 | corpsecret = QYWX_AM_AY[1] 281 | touser = QYWX_AM_AY[2] 282 | agentid = QYWX_AM_AY[3] 283 | try: 284 | media_id = QYWX_AM_AY[4] 285 | except: 286 | media_id = '' 287 | wx = WeCom(corpid, corpsecret, agentid) 288 | # 如果没有配置 media_id 默认就以 text 方式发送 289 | if media_id == '1': 290 | message = title + '\n\n' + content 291 | response = wx.send_text(message, touser) 292 | else: 293 | response = wx.send_mpnews(title, content, media_id, touser) 294 | if response == 'ok': 295 | print('推送成功!') 296 | else: 297 | print('推送失败!错误信息如下:\n', response) 298 | except Exception as e: 299 | print(e) 300 | 301 | class WeCom: 302 | def __init__(self, corpid, corpsecret, agentid): 303 | self.CORPID = corpid 304 | self.CORPSECRET = corpsecret 305 | self.AGENTID = agentid 306 | 307 | def get_access_token(self): 308 | url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken' 309 | values = {'corpid': self.CORPID, 310 | 'corpsecret': self.CORPSECRET, 311 | } 312 | req = requests.post(url, params=values) 313 | data = json.loads(req.text) 314 | return data["access_token"] 315 | 316 | def send_text(self, message, touser="@all"): 317 | send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + self.get_access_token() 318 | send_values = { 319 | "touser": touser, 320 | "msgtype": "text", 321 | "agentid": self.AGENTID, 322 | "text": { 323 | "content": message 324 | }, 325 | "safe": "0" 326 | } 327 | send_msges = (bytes(json.dumps(send_values), 'utf-8')) 328 | respone = requests.post(send_url, send_msges) 329 | respone = respone.json() 330 | return respone["errmsg"] 331 | 332 | def send_mpnews(self, title, message, media_id, touser="@all"): 333 | send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + self.get_access_token() 334 | send_values = { 335 | "touser": touser, 336 | "msgtype": "mpnews", 337 | "agentid": self.AGENTID, 338 | "mpnews": { 339 | "articles": [ 340 | { 341 | "title": title, 342 | "thumb_media_id": media_id, 343 | "author": "Author", 344 | "content_source_url": "", 345 | "content": message.replace('\n', '
'), 346 | "digest": message 347 | } 348 | ] 349 | } 350 | } 351 | send_msges = (bytes(json.dumps(send_values), 'utf-8')) 352 | respone = requests.post(send_url, send_msges) 353 | respone = respone.json() 354 | return respone["errmsg"] 355 | 356 | def send(title, content): 357 | """ 358 | 使用 bark, telegram bot, dingding bot, serverJ 发送手机推送 359 | :param title: 360 | :param content: 361 | :return: 362 | """ 363 | 364 | for i in notify_mode: 365 | if i == 'bark': 366 | if BARK or BARK_PUSH: 367 | bark(title=title, content=content) 368 | else: 369 | print('未启用 bark') 370 | continue 371 | if i == 'sc_key': 372 | if PUSH_KEY: 373 | serverJ(title=title, content=content) 374 | else: 375 | print('未启用 Server酱') 376 | continue 377 | elif i == 'dingding_bot': 378 | if DD_BOT_TOKEN and DD_BOT_SECRET: 379 | dingding_bot(title=title, content=content) 380 | else: 381 | print('未启用 钉钉机器人') 382 | continue 383 | elif i == 'telegram_bot': 384 | if TG_BOT_TOKEN and TG_USER_ID: 385 | telegram_bot(title=title, content=content) 386 | else: 387 | print('未启用 telegram机器人') 388 | continue 389 | elif i == 'coolpush_bot': 390 | if QQ_SKEY and QQ_MODE: 391 | coolpush_bot(title=title, content=content) 392 | else: 393 | print('未启用 QQ机器人') 394 | continue 395 | elif i == 'pushplus_bot': 396 | if PUSH_PLUS_TOKEN: 397 | pushplus_bot(title=title, content=content) 398 | else: 399 | print('未启用 PUSHPLUS机器人') 400 | continue 401 | elif i == 'wecom_app': 402 | if QYWX_AM: 403 | wecom_app(title=title, content=content) 404 | else: 405 | print('未启用企业微信应用消息推送') 406 | continue 407 | elif i == 'wecom_key': 408 | if QYWX_KEY: 409 | 410 | for i in range(int(len(content)/2000)+1): 411 | wecom_key(title=title, content=content[i*2000:(i+1)*2000]) 412 | 413 | 414 | else: 415 | print('未启用企业微信应用消息推送') 416 | continue 417 | else: 418 | print('此类推送方式不存在') 419 | 420 | 421 | def main(): 422 | send('title', 'content') 423 | 424 | 425 | if __name__ == '__main__': 426 | main() 427 | --------------------------------------------------------------------------------