[Python] 纯文本查看 复制代码
import hashlib
import json
import requests
import string
import random
import time
from urllib.parse import urlparse, parse_qs
from urllib3 import disable_warnings
from urllib3.exceptions import InsecureRequestWarning
# 禁用特定的警告
disable_warnings(InsecureRequestWarning) # 禁用未验证的 SSL 警告
cookies = {}
proxies = {
'http': '127.0.0.1:9001',
'https': '127.0.0.1:9001'
}
xm_sign_str = 'uh3$Hg&^HK876%gbxVG7f$%p=0M~>s1x'
token_sign_str = 'J7h8&^Bgs5#bn*7hn%!=kh308*bv2!s^'
referer = ''
li = ''
def md5_encrypt(text):
return hashlib.md5(text.encode('utf-8')).hexdigest()
# 获取重定向地址
def get_referer_url(openid,consumerid):
url = "https://p3720226302625wls8-xiaoman.activity.hixiaoman.com/xm/activity/place/3720226302625/54-89306-0qu103bgg0/v1-f3d8nu"
params = {
'vs': "2",
'appKey': "hdzy_jwsp_hvfjbf",
'placeId': "3720226302625",
'sui': "8934578636691287364",
'platform': "3",
'env': "prod",
'channelType': "1046",
'putChannel': "",
'openId':openid,
'consumerId': consumerid,
'unionId': "ottkj0uHbbThj37QSZc6oZwALf5k"
}
response = requests.get(url, params=params, verify=False, proxies=proxies, allow_redirects=False)
# 获取响应头中的 Location 字段
return response.headers.get('Location', None)
# 加载重定向
def load_referer_url(url):
global cookies
response = requests.get(url=url, verify=False, proxies=proxies, allow_redirects=False)
cookies = response.cookies.get_dict()
return response.headers.get('Location', None)
# 随机字符串
def get_nonce_str(length=32):
characters = string.hexdigits.lower()
nonce_str = ''.join(random.choices(characters, k=length))
return nonce_str
# 用户信息
def get_user_account():
url = "https://p3720226302625d4zq-xiaoman.activity.hixiaoman.com/activity/function/getUserAccount"
nonce_str = get_nonce_str()
timetamp = str(int(time.time() * 1000))
headers = {
'User-Agent': "Mozilla/5.0 (iPhone; CPU iPhone OS 17_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.42(0x18002a32) NetType/WIFI Language/zh_CN",
'xmSign': md5_encrypt(nonce_str + timetamp + xm_sign_str),
'xmTimestamp': timetamp,
'xmToken': "",
'bdrk': "null",
'nonceStr': nonce_str,
'ri': "",
'functionId': "100540000",
'Sec-Fetch-Site': "same-origin",
'Sec-Fetch-Mode': "cors",
'Sec-Fetch-Dest': "empty",
'Referer': referer,
'Accept-Language': "zh-CN,zh;q=0.9",
}
response = requests.get(url, headers=headers, verify=False, proxies=proxies)
return response.json()
# 签到
def sign(xm_token, date_str):
url = "https://p3720226302625m9pt-xiaoman.activity.hixiaoman.com/sign/action"
nonce_str = get_nonce_str()
timetamp = str(int(time.time() * 1000))
payload = {
"patchDate": date_str
}
headers = {
'User-Agent': "Mozilla/5.0 (iPhone; CPU iPhone OS 17_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.42(0x18002a32) NetType/WIFI Language/zh_CN",
'Content-Type': "application/json",
'Pragma': "no-cache",
'Cache-Control': "no-cache",
'xmSign': md5_encrypt(nonce_str + date_str + timetamp + xm_token + xm_sign_str),
'bdrk': "null",
'ri': "",
'xmToken': xm_token,
'nonceStr': nonce_str,
'xmTimestamp': timetamp,
'functionId': "0",
'Origin': "https://p3720226302625m9pt-xiaoman.activity.hixiaoman.com",
'Sec-Fetch-Site': "same-origin",
'Sec-Fetch-Mode': "cors",
'Sec-Fetch-Dest': "empty",
'Referer': referer,
'Accept-Language': "zh-CN,zh;q=0.9",
}
response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False, proxies=proxies)
print(response.text)
# 上报信息
def behavior(id: str):
url = "https://p3720226302625m9pt-xiaoman.activity.hixiaoman.com/sign/action"
print(referer)
nonce_str = get_nonce_str()
timetamp = str(int(time.time() * 1000))
headers = {
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Type": "application/json",
"Origin": "https://p3720226302625m9pt-xiaoman.activity.hixiaoman.com",
"Pragma": "no-cache",
"Referer": referer,
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.42(0x18002a32) NetType/WIFI Language/zh_CN",
"bdrk": "null",
"functionId": "0",
"nonceStr": nonce_str,
"ri;": "",
"xmSign": md5_encrypt(id + nonce_str + timetamp + xm_sign_str),
"xmTimestamp": timetamp,
"xmToken;": ""
}
url = "https://p3720226302625m9pt-xiaoman.activity.hixiaoman.com/behavior/log"
data = {
"behaviorId": id
}
data = json.dumps(data, separators=(',', ':'))
response = requests.post(url, headers=headers, data=data, verify=False, proxies=proxies)
print(response.text)
print(response)
# 任务列表
def get_tast_list():
url = "https://p3720226302625d4zq-xiaoman.activity.hixiaoman.com/activity/function/task/get"
nonce_str = get_nonce_str()
timetamp = str(int(time.time() * 1000))
headers = {
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c2d)XWEB/11581",
'xmSign': md5_encrypt(nonce_str + timetamp + xm_sign_str),
'xmTimestamp': timetamp,
'xmToken': "",
'bdrk': "null",
'nonceStr': nonce_str,
'ri': "",
'functionId': "100540002",
'Sec-Fetch-Site': "same-origin",
'Sec-Fetch-Mode': "cors",
'Sec-Fetch-Dest': "empty",
'Referer': referer,
'Accept-Language': "zh-CN,zh;q=0.9",
}
response = requests.get(url, headers=headers, verify=False, proxies=proxies)
return response.json()
# 获取token
def get_user_token():
nonce_str = get_nonce_str()
timetamp = str(int(time.time() * 1000))
token_sign = md5_encrypt(li + nonce_str + timetamp + token_sign_str)
url = "https://p3720226302625d4zq-xiaoman.activity.hixiaoman.com/xm/token/getUserToken"
params = {
'timestamp': timetamp,
'nonceStr': nonce_str,
'tokenSign': token_sign
}
xmTime = str(int(time.time() * 1000))
nonce_str = get_nonce_str()
headers = {
'User-Agent': "Mozilla/5.0 (iPhone; CPU iPhone OS 17_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.42(0x18002a32) NetType/WIFI Language/zh_CN",
'xmSign': md5_encrypt(nonce_str + timetamp + token_sign + xmTime + xm_sign_str),
'xmTimestamp': xmTime,
'xmToken': "",
'bdrk': "null",
'nonceStr': nonce_str,
'ri': "",
'functionId': "0",
'Sec-Fetch-Site': "same-origin",
'Sec-Fetch-Mode': "cors",
'Sec-Fetch-Dest': "empty",
'Referer': referer,
}
try:
response = requests.get(url, params=params, headers=headers, verify=False, proxies=proxies, cookies=cookies)
return response.json().get('data', None)
except Exception as e:
print('get_user_token')
return None
if __name__ == '__main__':
# 获取referer
url = get_referer_url('olTwC423yRYlHSZul4sHv7oeheDM','2503101116000010103917')
referer = load_referer_url(url)
# 上报
behavior("1011000")
# 取参
parse_url = urlparse(referer)
query_params = parse_qs(parse_url.query)
li = query_params.get('li', [None])[0]
# 取token
token = get_user_token()
# 签到
sign(token, '2025-03-10')