代码仅供学习交流,请勿用于非法用途
直接上代码
import hashlib
from parser import parseParam
from sign import sign
# 接口秘钥,代码仅供学习,不提供暴露签名
secret = ""
def md5(s):
m = hashlib.md5()
m.update(s.encode("utf-8"))
return str(m.hexdigest()).lower()
def getSign(params, header):
paramStr = ""
if header['content-type'] == "application/x-www-form-urlencoded":
paramStr = parseParam(params)
else:
paramStr = str(params)
return sign(secret, paramStr, header['api-timestamp'])
if __name__ == '__main__':
# application/x-www-form-urlencoded 测试
params = {
"marketingDataQueryReq": '{"spuSns":["20200823000422101803314"],"areaId":10}',
"userKey": "请填写自己的userKey",
}
header = {
"content-type": "application/x-www-form-urlencoded",
"userkey": "请填写自己的userKey",
"api-version": "V3",
"api-sign": "46a2a47696572c2c087e5534a311237a",
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.15(0x17000f27) NetType/WIFI Language/zh_CN",
"referer": "https://servicewechat.com/wx6025c5470c3cb50c/170/page-frame.html",
"api-timestamp": "1598366897123",
}
sign = getSign(params, header)
print(sign)
# application/json 测试
params = {
"windowId": 45,
"areaId": 10,
"storeId": "66880000000512",
"excludeAct": "N",
"windowType": "ACTIVITY",
"pageSize": 12,
"spuSns": [],
"isFirstRefresh": "TRUE",
"userKey": "请填写自己的userKey"
}
header = {
"content-type": "application/json",
"userkey": "请填写自己的userKey",
"api-version": "V3",
"api-sign": "d4903f86cb0b258d9723f99a68e1d123",
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.15(0x17000f27) NetType/WIFI Language/zh_CN",
"referer": "https://servicewechat.com/wx6025c5470c3cb50c/170/page-frame.html",
"api-timestamp": "1598366845610",
}
sign = getSign(params, header)
print(sign)