forked from jeanmoumou/XianYuApis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXianyuApis.py
More file actions
58 lines (51 loc) · 2.1 KB
/
XianyuApis.py
File metadata and controls
58 lines (51 loc) · 2.1 KB
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
import json
import time
import requests
from utils.xianyu_utils import generate_sign, trans_cookies, generate_device_id
class XianyuApis:
def __init__(self):
self.url = 'https://h5api.m.goofish.com/h5/mtop.taobao.idlemessage.pc.login.token/1.0/'
def get_token(self, cookies, device_id):
headers = {
'accept': 'application/json',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'no-cache',
'origin': 'https://www.goofish.com',
'pragma': 'no-cache',
'priority': 'u=1, i',
'referer': 'https://www.goofish.com/',
'sec-ch-ua': '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
}
params = {
'jsv': '2.7.2',
'appKey': '34839810',
't': str(int(time.time()) * 1000),
'sign': '',
'v': '1.0',
'type': 'originaljson',
'accountSite': 'xianyu',
'dataType': 'json',
'timeout': '20000',
'api': 'mtop.taobao.idlemessage.pc.login.token',
'sessionOption': 'AutoLoginOnly',
'spm_cnt': 'a21ybx.im.0.0',
}
data_val = '{"appKey":"444e9908a51d1cb236a27862abc769c9","deviceId":"' + device_id + '"}'
data = {
'data': data_val,
}
token = cookies['_m_h5_tk'].split('_')[0]
sign = generate_sign(params['t'], token, data_val)
params['sign'] = sign
response = requests.post('https://h5api.m.goofish.com/h5/mtop.taobao.idlemessage.pc.login.token/1.0/', params=params, cookies=cookies, headers=headers, data=data)
res_json = response.json()
return res_json
if __name__ == '__main__':
cookies_str = r''
xianyu = XianyuApis()