2121# 获取用户信息接口
2222get_user_info_api = "https://cat-match.easygame2021.com/sheep/v1/game/user_info?uid=%s&t=%s"
2323# 用户登录接口,POST请求 需要wx_open_id
24- user_login_api = "https://cat-match.easygame2021.com/sheep/v1/user/login_tourist "
24+ user_login_api = "https://cat-match.easygame2021.com/sheep/v1/user/login_oppo "
2525
2626header_t = config .get ("header_t" )
2727header_user_agent = config .get ("header_user_agent" )
3838request_header = {
3939 "Host" : "cat-match.easygame2021.com" ,
4040 "User-Agent" : header_user_agent ,
41- "t" : header_t ,
4241 "Referer" : "https://servicewechat.com/wx141bfb9b73c970a9/17/page-frame.html" ,
4342 "Accept-Encoding" : "gzip,compress,br,deflate" ,
4443 "Connection" : "close"
@@ -63,9 +62,21 @@ def uid2token(uid, legitimate_token):
6362 try :
6463 get_res = requests .get (get_user_info_api % (uid , legitimate_token ), headers = request_header , timeout = 15 ,
6564 verify = False )
66- uuid = get_res .json ()["data" ]["wx_open_id" ]
65+
66+ if get_res .status_code == 200 :
67+ result_json = get_res .json ()
68+ uuid = result_json ["data" ]["wx_open_id" ]
69+ avatar = result_json ["data" ]["avatar" ]
70+ else :
71+ print ("请求失败" )
72+ print ("请求状态:{}" .format (get_res .status_code ))
73+ sys .exit (- 1 )
6774 login_body = {
68- "uuid" : str (uuid )
75+ "uid" : str (uuid ),
76+ "avatar" : avatar ,
77+ "nick_name" : "1" ,
78+ "sex" : 1
79+
6980 }
7081 except Exception :
7182 try_get_user_info_api_count += 1
@@ -81,7 +92,9 @@ def uid2token(uid, legitimate_token):
8192 while True :
8293 print (f"开始尝试第{ try_user_login_api } 次换取用户header_t" )
8394 wait_for_random_interval (False )
95+
8496 try :
97+
8598 login_res = requests .post (user_login_api , headers = request_header , json = login_body , timeout = 15 , verify = False )
8699 # 响应模型
87100 # {
@@ -96,9 +109,11 @@ def uid2token(uid, legitimate_token):
96109 user_token = login_res .json ()["data" ]["token" ]
97110 print ("获取token成功:" , user_token )
98111 global header_t
112+
99113 header_t = user_token
100- except Exception :
114+ except Exception as e :
101115 try_user_login_api += 1
116+ print (e )
102117 finally :
103118 if try_user_login_api > max_try_count :
104119 print (f"超过target_uid模式最大尝试次数,本次程序运行结束,请稍后重试或者检查uid是否正确!" )
0 commit comments