|
| 1 | +import re |
| 2 | +import requests |
| 3 | + |
| 4 | + |
| 5 | +def wskey_to_ptkey(wskey): |
| 6 | + url = "https://api.jds.codes/jd/gentoken" |
| 7 | + data = {"url": "https://home.m.jd.com/myJd/newhome.action"} |
| 8 | + headers = { |
| 9 | + "user-agent": "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", |
| 10 | + "Content-Type": "application/json" |
| 11 | + } |
| 12 | + res = requests.post(url, json=data, headers=headers).json() |
| 13 | + res = res['data']['sign'] |
| 14 | + uuid = re.search(r'uuid=(.*?)&', res).group(1) |
| 15 | + client_version = re.search(r'clientVersion=(.*?)&', res).group(1) |
| 16 | + client = re.search(r'client=(.*?)&', res).group(1) |
| 17 | + sign = re.search(r'(st=.*)', res).group(1) |
| 18 | + url = f"https://api.m.jd.com/client.action?functionId=genToken&clientVersion={client_version}&uuid={uuid}&client={client}&{sign}" |
| 19 | + headers = { |
| 20 | + "Host": 'api.m.jd.com', |
| 21 | + "Cookie": wskey, |
| 22 | + "accept": '*/*', |
| 23 | + "referer": '', |
| 24 | + 'user-agent': "okhttp/3.12.1;jdmall;apple;version/9.4.0;build/88830;screen/1440x3007;os/11;network/wifi;", |
| 25 | + 'accept-language': 'zh-Hans-CN;q=1, en-CN;q=0.9', |
| 26 | + 'content-type': 'application/x-www-form-urlencoded;', |
| 27 | + } |
| 28 | + res = requests.post(url, headers=headers, data="body=%7B%22to%22%3A%20%22https%3A//home.m.jd.com/myJd/newhome.action%22%2C%20%22action%22%3A%20%22to%22%7D").json() |
| 29 | + token_key = res['tokenKey'] |
| 30 | + |
| 31 | + url = f"https://un.m.jd.com/cgi-bin/app/appjmp?tokenKey={token_key}&to=https://plogin.m.jd.com/jd-mlogin/static/html/appjmp_blank.html" |
| 32 | + s = requests.Session() |
| 33 | + s.get(url, allow_redirects=True) |
| 34 | + return f"pt_key={s.cookies.get_dict()['pt_key']};pt_pin={s.cookies.get_dict()['pt_pin']};" |
| 35 | + |
| 36 | + |
| 37 | +_wskey = 'pin=jd_;wskey=AAJ;' |
| 38 | +cookie = wskey_to_ptkey(_wskey) |
| 39 | +print(cookie) |
0 commit comments