中国移动九天毕昇Python签到脚本(适用青龙面板)
中国移动九天毕昇Python签到脚本(适用青龙面板)
移动送GPU非常大方,但是每天签到太费劲了,写个脚本开心一下
安装Python依赖
pip install requests rsa
添加账号信息
手动方式
代码末尾main函数
中的username
、password
手动添加账号密码
青龙方式
青龙环境变量:JIUTIAN_USERNAME=xxx,JIUTIAN_PASSWORD=xxx
签到代码
import base64
import os
import requests
import uuid
import re
import rsa
headers = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"cache-control": "max-age=0",
"Content-type": "application/x-www-form-urlencoded",
"origin": "null",
"sec-ch-ua": "\"Microsoft Edge\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.1559.37 Safari/537.36 Edge/13.10586"
}
def get_login_url():
redirect_uri = "https://jiutian.10086.cn/auth/realms/TechnicalMiddlePlatform/protocol/openid-connect/auth?client_id=dlp-train-front&redirect_uri=https%3A%2F%2Fjiutian.10086.cn%2Fedu%2Fconsole%23%2Fhome%2Fcontrol&state={}&response_mode=fragment&response_type=code&scope=openid&nonce={}"
res = session.get(redirect_uri.format(str(uuid.uuid4()), str(uuid.uuid4())), headers=headers)
pattern = re.compile(r'action="(.*?)"')
return pattern.findall(res.text)[0].replace("&", "&")
def get_public_key():
public_key_url = 'https://jiutian.10086.cn/auth/realms/TechnicalMiddlePlatform/themeapi/getKey'
response = session.get(public_key_url, headers=headers)
return response.json()['body']
def encrypt(public_key, text):
public_key = '''-----BEGIN PUBLIC KEY-----
{}
-----END PUBLIC KEY-----'''.format(public_key)
public_key = rsa.PublicKey.load_pkcs1_openssl_pem(public_key.encode())
return base64.b64encode(rsa.encrypt(text.encode(), public_key)).decode()
def login(username, password):
login_url = get_login_url()
public_key = get_public_key()
data = {"rememberMe": "true", "loginType": "password",
'username': encrypt(public_key, username),
"password": encrypt(public_key, password)}
response = session.post(login_url, headers=headers, data=data)
return response.url
def get_code(code_url):
try:
return code_url.split("code=")[1].split("&")[0]
except Exception as e:
print(e)
raise Exception("获取code失败,请检查账号密码是否正确")
def get_access_token(code):
token_url = 'https://jiutian.10086.cn/auth/realms/TechnicalMiddlePlatform/protocol/openid-connect/token'
data = {
'code': code,
'grant_type': 'authorization_code',
'client_id': 'dlp-train-front',
'redirect_uri': 'https://jiutian.10086.cn/edu/console#/home/control'
}
response = session.post(token_url, headers=headers, data=data)
return response.json()['access_token']
def get_userinfo():
userinfo_url = 'https://jiutian.10086.cn/edu/keycloak/web/user/getuserinfo'
return session.get(userinfo_url, headers=headers).json()
def checkin():
checkin_url = 'https://jiutian.10086.cn/edu/marketing/web/checkin/set'
response = session.get(checkin_url, headers=headers)
return response.json()
if __name__ == '__main__':
session = requests.session()
username = ''
password = ''
username = username if username else os.getenv('JIUTIAN_USERNAME', username)
password = password if password else os.getenv('JIUTIAN_PASSWORD', password)
if not username or not password:
raise Exception('未设置用户名或密码')
url = login(username, password) # 登录
code = get_code(url) # 获取code
access_token = get_access_token(code) # 获取access_token
headers['Authorization'] = 'Bearer ' + access_token # 设置请求头
print(f'登录用户: {get_userinfo()["body"]["userName"]}')
checkin_info = checkin() # 签到
result = checkin_info["state"]
if result == 'OK':
print(f'签到成功, 签到信息: {checkin_info["body"]}')
else:
print(f'签到失败, 签到信息: {checkin_info["errorMessage"]}')
作者:Eucaly_Z