[Python] 纯文本查看 复制代码
import requests
import time
import execjs
import urllib3
import re
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64
import json
from urllib.parse import quote
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
proxies = {"http": None, "https": None}
global_cookies = {}
def get_token_key():
headers = {
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Referer": "https://duiba.ioutu.cn/projectx/p009ae4a7/index.html?appID=96109&from=login&spm=96109.1.1.1",
"Sec-Fetch-Dest": "script",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36",
"sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
"sec-ch-ua-platform": "\"Android\""
}
url = "https://duiba.ioutu.cn/projectx/p009ae4a7/getTokenKey"
params = {"_t": int(time.time() * 1000)}
try:
response = requests.get(url, headers=headers, cookies=global_cookies, params=params, proxies=proxies,
verify=False)
return response.text
except Exception as e:
print('get_token_key', e)
return False
def get_token():
headers = {
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Referer": "https://duiba.ioutu.cn/projectx/p009ae4a7/index.html?appID=96109&from=login&spm=96109.1.1.1",
"Sec-Fetch-Dest": "script",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36",
"sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
"sec-ch-ua-platform": "\"Android\""
}
url = "https://duiba.ioutu.cn/projectx/p009ae4a7/getToken"
params = {"_t": int(time.time() * 1000)}
try:
response = requests.get(url, headers=headers, cookies=global_cookies, params=params, proxies=proxies,
verify=False)
return response.json()
except Exception as e:
print('get_token', e)
return False
def get_token_value(key):
# 获取token
ret = get_token()
if not ret:
return False
JavaScriptText = ret['data']
context = execjs.compile(f'var window = {{}}; {JavaScriptText}')
token = context.eval(f'window.{key}')
if token:
return token
else:
return False
def game_start(token):
url = "https://duiba.ioutu.cn/projectx/p009ae4a7/game/start.do"
t = int(time.time() * 1000)
querystring = {"_t": t}
payload = f"gameType=sword&token={token}&user_type=1&is_from_share=1&_t={t}"
headers = {
"Host": "duiba.ioutu.cn",
"Connection": "keep-alive",
"Content-Length": "74",
"User-Agent": "Mozilla/5.0 (Linux; Android 11; M2002J9E Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/126.0.6478.187 Mobile Safari/537.36 XWEB/1260075 MMWEBSDK/20231201 MMWEBID/4339 MicroMessenger/8.0.45.2521(0x28002D3D) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64 miniProgram/wxaf5dbe4074f72919",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "*/*",
"Origin": "https://duiba.ioutu.cn",
"X-Requested-With": "com.tencent.mm",
"Referer": "https://duiba.ioutu.cn/projectx/p009ae4a7/index.html?appID=96109&from=login&spm=96109.1.1.1",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"
}
try:
response = requests.request("POST", url, data=payload, headers=headers, params=querystring,
cookies=global_cookies, proxies=proxies)
return response.json()
except Exception as e:
print('game_start', e)
return False
def game_submit(token, param, t):
url = "https://duiba.ioutu.cn/projectx/p009ae4a7/game/submit.do"
querystring = {"_t": t}
payload = f"param={quote(param)}&token={token}&user_type=1&is_from_share=1&_t={t}"
headers = {
"Host": "duiba.ioutu.cn",
"Connection": "keep-alive",
"Content-Length": "186",
"User-Agent": "Mozilla/5.0 (Linux; Android 11; M2002J9E Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/126.0.6478.187 Mobile Safari/537.36 XWEB/1260075 MMWEBSDK/20231201 MMWEBID/4339 MicroMessenger/8.0.45.2521(0x28002D3D) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64 miniProgram/wxaf5dbe4074f72919",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "*/*",
"Origin": "https://duiba.ioutu.cn",
"X-Requested-With": "com.tencent.mm",
"Referer": "https://duiba.ioutu.cn/projectx/p009ae4a7/index.html?appID=96109&from=login&spm=96109.1.1.1",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"
}
try:
response = requests.request("POST", url, data=payload, headers=headers, params=querystring,
cookies=global_cookies, proxies=proxies)
return response.json()
except Exception as e:
print('game_submit', e)
return False
def decrypt(data: str, key: bytes, iv: bytes) -> bytes:
aes = AES.new(key, AES.MODE_CBC, iv)
res = aes.decrypt(base64.b64decode(data)) # 解密操作
res = res.rstrip(b'\x00') # 去除填充
return res
def encrypt(data: dict, key: bytes, iv: bytes) -> str:
dataByte = pad(json.dumps(data, separators=(',', ':')).encode('utf-8'), AES.block_size)
aes = AES.new(key, AES.MODE_CBC, iv)
encrypt_data_byte = aes.encrypt(dataByte)
result = base64.b64encode(encrypt_data_byte)
return result
def process():
score = 300 # 游戏分数
iv = b'cDOiBC1n2QrkAY2P'
aeskey = b'1696BD3E5BB915A0'
# 获取key
JavaScriptText = get_token_key()
context = execjs.compile(JavaScriptText)
FunctionString = context.eval('ohjaiohdf.toString()')
match = re.search(r"var key = '([^']+)';", FunctionString)
if match:
key = match.group(1)
print(key)
else:
print('匹配失败')
return False
# 开始游戏
token = get_token_value(key)
res = game_start(token)
if not res or not res['success']:
print('开始游戏失败', res)
return False
print('开始游戏成功')
# 解密返回
dataByte = decrypt(res['data'], aeskey, iv)
recordId = json.loads(dataByte)['recordId']
# 提交延迟
time.sleep(30)
# 构造参数
token = get_token_value(key)
t = int(time.time() * 1000)
payload = {"recordId": recordId, "timestamp": t, "score": score, "gameType": "sword"}
# 加密
param = encrypt(payload, aeskey, iv)
# 提交游戏
ret = game_submit(token, param, t)
print('结束游戏', ret)
if __name__ == '__main__':
process()