main
KingRan 2023-09-10 11:16:31 +08:00
parent b4eb28fcdf
commit d107e53ab2
1 changed files with 211 additions and 58 deletions

View File

@ -16,6 +16,7 @@ from urllib.parse import unquote
""" """
new Env('wskey本地转换'); new Env('wskey本地转换');
cron 57 21,9 * * * cron 57 21,9 * * *
by:lonesomexz
""" """
hadsend=True hadsend=True
UserAgent="" UserAgent=""
@ -39,6 +40,29 @@ def randomuserAgent():
lat='26.1187118976'+str(random.randint(100,999)) lat='26.1187118976'+str(random.randint(100,999))
UserAgent=f'jdapp;iPhone;10.0.4;{iosVer};{uuid};network/wifi;ADID/{ADID};model/iPhone{iPhone},1;addressid/{addressid};appBuild/167707;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS {iosV} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/null;supportJDSHWK/1' UserAgent=f'jdapp;iPhone;10.0.4;{iosVer};{uuid};network/wifi;ADID/{ADID};model/iPhone{iPhone},1;addressid/{addressid};appBuild/167707;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS {iosV} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/null;supportJDSHWK/1'
def get_proxy_api(proxy_url, max_retries=5, timeout=60, retry_delay=1):
for retry in range(max_retries):
res = get(url=proxy_url)
printf(f"本次获取到的代理:{res.text}")
proxy_ip_port = res.text.strip()
proxy_address = f"http://{proxy_ip_port}"
try:
response = get("https://jd.com", proxies={"http": proxy_address, "https": proxy_address}, timeout=timeout)
if response.status_code == 200:
return proxy_address
except Exception as e:
print(f"代理检测失败,错误信息:{e}")
print("代理检测失败,重新获取...")
time.sleep(retry_delay)
print("无法获取可用的代理IP尝试次数已达上限。")
return None
def load_send(): def load_send():
global send global send
global hadsend global hadsend
@ -179,10 +203,15 @@ def get_sign(functionId, body, client : str="android", clientVersion : str='11.2
return convertUrl return convertUrl
def getcookie_wskey(key): def getcookie_wskey(key):
proxys = proxy_url
if os.environ.get("WSKEY_PROXY_URL") is not None:
proxys = get_proxy_api(proxy_url)
body = "body=%7B%22to%22%3A%22https%3A//plogin.m.jd.com/jd-mlogin/static/html/appjmp_blank.html%22%7D" body = "body=%7B%22to%22%3A%22https%3A//plogin.m.jd.com/jd-mlogin/static/html/appjmp_blank.html%22%7D"
pin = findall("pin=([^;]*);", key)[0] pin = findall("pin=([^;]*);", key)[0]
for num in range(0,20):
for num in range(0,5):
sign = get_sign("genToken",{"url": "https://plogin.m.jd.com/jd-mlogin/static/html/appjmp_blank.html"},"android","11.2.8") sign = get_sign("genToken",{"url": "https://plogin.m.jd.com/jd-mlogin/static/html/appjmp_blank.html"},"android","11.2.8")
url = f"https://api.m.jd.com/client.action?functionId=genToken&{sign}" url = f"https://api.m.jd.com/client.action?functionId=genToken&{sign}"
headers = { headers = {
@ -192,20 +221,33 @@ def getcookie_wskey(key):
'content-type': 'application/x-www-form-urlencoded;' 'content-type': 'application/x-www-form-urlencoded;'
} }
try: try:
token = post(url=url, headers=headers, data=body, verify=False).json() token = post(url=url, headers=headers, data=body, verify=False, proxies={"http": proxys, "https": proxys}).json()
token=token['tokenKey'] token=token['tokenKey']
except Exception as error: except Exception as error:
printf(f"【错误】{unquote(pin)}在获取token时\n{error}") print(f"【警告】{unquote(pin)}在获取token时失败等待5秒后重试")
time.sleep(5)
if num == 4:
print(f"【错误】{unquote(pin)}在获取token时\n{error}")
return pin, "False" return pin, "False"
randomuserAgent()
if os.environ.get("WSKEY_PROXY_URL") is not None:
proxys = get_proxy_api(proxy_url)
continue
if token!="xxx": if token!="xxx":
break break
else: else:
printf(f"【警告】{unquote(pin)}在获取token时失败等待5秒后重试") printf(f"【警告】{unquote(pin)}在获取token时失败等待5秒后重试")
time.sleep(5) time.sleep(5)
randomuserAgent()
if os.environ.get("WSKEY_PROXY_URL") is not None:
proxys = get_proxy_api(proxy_url)
if token=="xxx": if token=="xxx":
printf(f"【错误】{unquote(pin)}在获取token时失败跳过") printf(f"【错误】{unquote(pin)}在获取token时失败跳过")
return "Error" return "Error"
for num in range(0, 5):
url = 'https://un.m.jd.com/cgi-bin/app/appjmp' url = 'https://un.m.jd.com/cgi-bin/app/appjmp'
params = { params = {
'tokenKey': token, 'tokenKey': token,
@ -216,10 +258,18 @@ def getcookie_wskey(key):
} }
try: try:
res = get(url=url, params=params, verify=False, res = get(url=url, params=params, verify=False,
allow_redirects=False).cookies.get_dict() allow_redirects=False, proxies={"http": proxys, "https": proxys}).cookies.get_dict()
except Exception as error: except Exception as error:
printf(f"【错误】{unquote(pin)}在获取cookie时\n{error}") print(f"【警告】{unquote(pin)}在获取cookie时失败等待5秒后重试")
time.sleep(5)
if num == 4:
# 最后一次重试时输出错误消息并返回 "Error"
print(f"【错误】{unquote(pin)}在获取cookie时\n{error}")
return "Error" return "Error"
randomuserAgent()
if os.environ.get("WSKEY_PROXY_URL") is not None:
proxys = get_proxy_api(proxy_url)
continue
try: try:
if "app_open" in res['pt_key']: if "app_open" in res['pt_key']:
@ -231,6 +281,35 @@ def getcookie_wskey(key):
printf(f"【错误】{unquote(pin)}在获取cookie时\n{str(res)}") printf(f"【错误】{unquote(pin)}在获取cookie时\n{str(res)}")
return "Error" return "Error"
def arcadia_getwskey():
possible_paths = ['/arcadia/config/account.json', '/jd/config/account.json']
for wskey_file in possible_paths:
if os.path.isfile(wskey_file):
with open(wskey_file, 'r') as f:
data = json.load(f)
json_data = []
for item in data:
# 跳过空的 pt_pin 或 ws_key
if not item['pt_pin'] or not item['ws_key']:
continue
pt_pin = item['pt_pin']
ws_key = item['ws_key']
remarks = item['remarks'][0] if item['remarks'] else ''
json_item = f"pin={pt_pin};wskey={ws_key};"
json_data.append((json_item, remarks))
return json_data
return []
def arcadia_subcookie(cookie, token):
url = 'http://127.0.0.1:5678/openApi/updateCookie'
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ', 'api-token': f'{token}'}
data = {
"cookie": cookie
}
res = post(url, data=json.dumps(data), headers=headers).json()
return res
def subcookie(pt_pin, cookie, token): def subcookie(pt_pin, cookie, token):
if True: if True:
@ -308,15 +387,33 @@ def getRemark(pt_pin,token):
def main(): def main():
printf("版本: 20230602") printf("版本: 20230602")
printf("说明: 如果用Wxpusher通知需配置WP_APP_TOKEN_ONE和WP_APP_MAIN_UID其中WP_APP_MAIN_UID是你的Wxpusher UID") printf("说明: 如果用Wxpusher通知需配置WP_APP_TOKEN_ONE和WP_APP_MAIN_UID其中WP_APP_MAIN_UID是你的Wxpusher UID")
printf("隧道型代理池接口:export WSKEY_PROXY_TUNNRL='http://127.0.0.1:123456'")
printf("拉取型代理API接口(数据格式:txt;提取数量:每次一个):export WSKEY_PROXY_URL='http://xxx.com/apiUrl'")
printf("没有代理可以自行注册比如携趣巨量每日免费1000IP完全够用")
printf("====================================") printf("====================================")
config="" config=""
envtype=""
global proxy_url
proxy_url=os.environ.get("WSKEY_PROXY_URL") or os.environ.get("WSKEY_PROXY_TUNNRL") or None
iswxpusher=False iswxpusher=False
counttime=0 counttime=0
if os.path.exists("/ql/config/auth.json"): if os.path.exists("/ql/config/auth.json"):
config="/ql/config/auth.json" config="/ql/config/auth.json"
envtype="ql"
if os.path.exists("/ql/data/config/auth.json"): if os.path.exists("/ql/data/config/auth.json"):
config="/ql/data/config/auth.json" config="/ql/data/config/auth.json"
envtype="ql"
if os.path.exists("/jd/config/auth.json"):
config="/jd/config/auth.json"
envtype="arcadia"
if os.path.exists("/arcadia/config/auth.json"):
config="/arcadia/config/auth.json"
envtype="arcadia"
if config=="": if config=="":
printf(f"无法判断使用环境,退出脚本!") printf(f"无法判断使用环境,退出脚本!")
@ -333,11 +430,18 @@ def main():
except: except:
iswxpusher=False iswxpusher=False
if proxy_url is None:
print("没有配置代理,无法使用代理!\n请配置环境变量WSKEY_PROXY_TUNNRL或WSKEY_PROXY_URL\n")
print("====================================")
else:
print(f"已配置代理: {proxy_url}\n")
resurt="" resurt=""
resurt1="" resurt1=""
resurt2="" resurt2=""
summary="" summary=""
if envtype == "ql":
with open(config, "r", encoding="utf-8") as f1: with open(config, "r", encoding="utf-8") as f1:
token = json.load(f1)['token'] token = json.load(f1)['token']
url = 'http://127.0.0.1:5600/api/envs' url = 'http://127.0.0.1:5600/api/envs'
@ -347,12 +451,26 @@ def main():
'Authorization': f'Bearer {token}' 'Authorization': f'Bearer {token}'
} }
datas = get(url, params=body, headers=headers).json()['data'] datas = get(url, params=body, headers=headers).json()['data']
if len(datas)>0: elif envtype == "arcadia":
with open(config, "r", encoding="utf-8") as f1:
#token = json.load(f1)['token']
data = json.load(f1)
token = data.get('openApiToken', '')
url = 'http://127.0.0.1:5678/openApi/count'
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ', 'api-token': f'{token}'}
datas = get(url, headers=headers).json()["data"]["accountCount"]
# printf(f"token{token}")
# printf(f"datas{datas}")
if datas > 0 if isinstance(datas, int) else len(datas) > 0:
printf("\n===============开始转换JD_WSCK==============") printf("\n===============开始转换JD_WSCK==============")
else: else:
printf("\n错误:没有需要转换的JD_WSCK退出脚本!") printf("\n错误:没有需要转换的JD_WSCK退出脚本!")
return return
if envtype == "ql":
for data in datas: for data in datas:
randomuserAgent() randomuserAgent()
if data['status']!=0: if data['status']!=0:
@ -360,7 +478,6 @@ def main():
key = data['value'] key = data['value']
pin = re.findall(r'(pin=([^; ]+)(?=;?))',key)[0][1] pin = re.findall(r'(pin=([^; ]+)(?=;?))',key)[0][1]
cookie = getcookie_wskey(key) cookie = getcookie_wskey(key)
if "app_open" in cookie: if "app_open" in cookie:
#printf("转换成功:"cookie) #printf("转换成功:"cookie)
orgpin = cookie.split(";")[1].split("=")[1] orgpin = cookie.split(";")[1].split("=")[1]
@ -384,6 +501,34 @@ def main():
message = f"转换失败:{newpin}" message = f"转换失败:{newpin}"
resurt2=resurt2+f"转换失败:{newpin}\n" resurt2=resurt2+f"转换失败:{newpin}\n"
elif envtype == "arcadia":
wslist = arcadia_getwskey()
#printf(f"wslist:\n{wslist}")
for ws,remark in wslist:
randomuserAgent()
pin = re.findall(r'(pin=([^; ]+)(?=;?))',ws)[0][1]
printf(f"当前转换的pin:\n{pin}")
cookie = getcookie_wskey(ws)
printf(f"转换后的cookie:\n{cookie}\n")
if "app_open" in cookie:
#printf("转换成功:"cookie)
res = arcadia_subcookie(cookie, token)
resurt1=resurt1+f"转换成功:{remark}@{pin}"
if res["code"] == 1:
resurt1=resurt1+f",面板同步成功! ✅\n"
else:
resurt1=resurt1+f"面板同步失败token错误或者请求失败。 ❌\n"
else:
if "fake_" in cookie:
message = f"{remark}@{pin}wskeyk可能过期了\n"
printf(message)
resurt2=resurt2+f"{remark}@{pin}wskeyk可能过期了\n"
else:
message = f"{remark}@{pin},转换失败! ❌"
printf(message)
resurt2=resurt2+f"{remark}@{pin},转换失败! ❌\n"
if resurt2!="": if resurt2!="":
resurt="👇👇👇👇👇转换异常👇👇👇👇👇\n"+resurt2+"\n" resurt="👇👇👇👇👇转换异常👇👇👇👇👇\n"+resurt2+"\n"
@ -405,6 +550,14 @@ def main():
if resurt1!="": if resurt1!="":
resurt=resurt+"👇👇👇👇👇转换成功👇👇👇👇👇\n"+resurt1 resurt=resurt+"👇👇👇👇👇转换成功👇👇👇👇👇\n"+resurt1
if iswxpusher:
send_notification("JD_WSCK转换结果",resurt,summary)
else:
if hadsend:
send("JD_WSCK转换结果",resurt)
else:
printf("没有启用通知!")
printf("\n\n===============转换结果==============\n") printf("\n\n===============转换结果==============\n")
printf(resurt) printf(resurt)