-
Notifications
You must be signed in to change notification settings - Fork 6
/
bsgamesdk.py
91 lines (73 loc) · 5.96 KB
/
bsgamesdk.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
import json
import time
import hashlib
from . import rsacr
import urllib
from loguru import logger
import httpx
bililogin = "https://line1-sdk-center-login-sh.biligame.net/"
header = {"User-Agent": "Mozilla/5.0 BSGameSDK", "Content-Type": "application/x-www-form-urlencoded",
"Host": "line1-sdk-center-login-sh.biligame.net"}
async def sendpost(url, data):
async with httpx.AsyncClient() as client:
return (await client.post(url=url, data=data, headers=header, timeout=20)).json()
def setsign(data):
data["timestamp"] = int(time.time())
data["client_timestamp"] = int(time.time())
sign = ""
data2 = ""
for key in data:
if key == "pwd":
pwd = urllib.parse.quote(data["pwd"])
data2 += f"{key}={pwd}&"
data2 += f"{key}={data[key]}&"
for key in sorted(data):
sign += f"{data[key]}"
data = sign
sign = sign + "fe8aac4e02f845b8ad67c427d48bfaf1"
sign = hashlib.md5(sign.encode()).hexdigest()
data2 += "sign=" + sign
return data2
modolrsa = '{"operators":"5","merchant_id":"1","isRoot":"0","domain_switch_count":"0","sdk_type":"1","sdk_log_type":"1","timestamp":"1613035485639","support_abis":"x86,armeabi-v7a,armeabi","access_key":"","sdk_ver":"3.4.2","oaid":"","dp":"1280*720","original_domain":"","imei":"227656364311444","version":"1","udid":"KREhESMUIhUjFnJKNko2TDQFYlZkB3cdeQ==","apk_sign":"e89b158e4bcf988ebd09eb83f5378e87","platform_type":"3","old_buvid":"XZA2FA4AC240F665E2F27F603ABF98C615C29","android_id":"84567e2dda72d1d4","fingerprint":"","mac":"08:00:27:53:DD:12","server_id":"1592","domain":"line1-sdk-center-login-sh.biligame.net","app_id":"1370","version_code":"90","net":"4","pf_ver":"6.0.1","cur_buvid":"XZA2FA4AC240F665E2F27F603ABF98C615C29","c":"1","brand":"Android","client_timestamp":"1613035486888","channel_id":"1","uid":"","game_id":"1370","ver":"2.4.10","model":"MuMu"}'
modollogin = '{"operators":"5","merchant_id":"1","isRoot":"0","domain_switch_count":"0","sdk_type":"1","sdk_log_type":"1","timestamp":"1613035508188","support_abis":"x86,armeabi-v7a,armeabi","access_key":"","sdk_ver":"3.4.2","oaid":"","dp":"1280*720","original_domain":"","imei":"227656364311444","gt_user_id":"fac83ce4326d47e1ac277a4d552bd2af","seccode":"","version":"1","udid":"KREhESMUIhUjFnJKNko2TDQFYlZkB3cdeQ==","apk_sign":"e89b158e4bcf988ebd09eb83f5378e87","platform_type":"3","old_buvid":"XZA2FA4AC240F665E2F27F603ABF98C615C29","android_id":"84567e2dda72d1d4","fingerprint":"","validate":"84ec07cff0d9c30acb9fe46b8745e8df","mac":"08:00:27:53:DD:12","server_id":"1592","domain":"line1-sdk-center-login-sh.biligame.net","app_id":"1370","pwd":"rxwA8J+GcVdqa3qlvXFppusRg4Ss83tH6HqxcciVsTdwxSpsoz2WuAFFGgQKWM1+GtFovrLkpeMieEwOmQdzvDiLTtHeQNBOiqHDfJEKtLj7h1nvKZ1Op6vOgs6hxM6fPqFGQC2ncbAR5NNkESpSWeYTO4IT58ZIJcC0DdWQqh4=","version_code":"90","net":"4","pf_ver":"6.0.1","cur_buvid":"XZA2FA4AC240F665E2F27F603ABF98C615C29","c":"1","brand":"Android","client_timestamp":"1613035509437","channel_id":"1","uid":"","captcha_type":"1","game_id":"1370","challenge":"efc825eaaef2405c954a91ad9faf29a2","user_id":"doo349","ver":"2.4.10","model":"MuMu"}'
modolcaptch = '{"operators":"5","merchant_id":"1","isRoot":"0","domain_switch_count":"0","sdk_type":"1","sdk_log_type":"1","timestamp":"1613035486182","support_abis":"x86,armeabi-v7a,armeabi","access_key":"","sdk_ver":"3.4.2","oaid":"","dp":"1280*720","original_domain":"","imei":"227656364311444","version":"1","udid":"KREhESMUIhUjFnJKNko2TDQFYlZkB3cdeQ==","apk_sign":"e89b158e4bcf988ebd09eb83f5378e87","platform_type":"3","old_buvid":"XZA2FA4AC240F665E2F27F603ABF98C615C29","android_id":"84567e2dda72d1d4","fingerprint":"","mac":"08:00:27:53:DD:12","server_id":"1592","domain":"line1-sdk-center-login-sh.biligame.net","app_id":"1370","version_code":"90","net":"4","pf_ver":"6.0.1","cur_buvid":"XZA2FA4AC240F665E2F27F603ABF98C615C29","c":"1","brand":"Android","client_timestamp":"1613035487431","channel_id":"1","uid":"","game_id":"1370","ver":"2.4.10","model":"MuMu"}'
async def _login(account, password, challenge="", gt_user="", validate=""):
rsa = await sendpost(bililogin + "api/client/rsa", setsign(json.loads(modolrsa)))
data = json.loads(modollogin)
public_key = rsa['rsa_key']
data["access_key"] = ""
data["gt_user_id"] = gt_user
data["uid"] = ""
data["challenge"] = challenge
data["user_id"] = account
data["validate"] = validate
if validate:
data["seccode"] = validate + "|jordan"
data["pwd"] = rsacr.rsacreate(rsa['hash'] + password, public_key)
return await sendpost(bililogin + "api/client/login", setsign(data))
async def login(bili_account, bili_pwd, make_captch):
logger.info(f'logging in with acc={bili_account}, pwd={bili_pwd}')
login_sta = await _login(bili_account, bili_pwd)
if login_sta.get("message", "") == "用户名或密码错误":
raise Exception("用户名或密码错误")
if "access_key" in login_sta:
logger.info("无需验证码登录成功")
return login_sta
logger.info("触发验证码,尝试过码")
# start_captcha_input
cap = await sendpost(bililogin + "api/client/start_captcha", setsign(json.loads(modolcaptch)))
challenge, gt_user_id, validate_key = await make_captch(cap['gt'], cap['challenge'], cap['gt_user_id'])
return await _login(bili_account, bili_pwd, challenge, gt_user_id, validate_key)
class bsdkclient:
def __init__(self, acccountinfo: dict, captchaVerifier=None):
self.acccountinfo = acccountinfo
self.qudao = 0
self.platform = "2"
self.captchaVerifier = captchaVerifier
async def b_login(self):
if self.qudao == 0:
for i in range(3):
resp = await login(self.acccountinfo['account'], self.acccountinfo['password'], self.captchaVerifier)
if resp['code'] == 0:
logger.info("geetest or captcha succeed")
return resp['uid'], resp['access_key']