|
/

api接口调用api/send?sign=mysign 接口返回签名错误

Yy*
发布于 4 年前
234来自湖北省
移动统计 U-App

调用接口 api/send?sign=mysign

python发送的http请求 提示签名错误

代码如下

appkey = "****"
app_master_secret  = "tope****dsp"
timestamp  = int(time.time())
method ='POST'
url ='http://msg.umeng.com/api/send'
data = {
"appkey": appkey,
"timestamp": timestamp,
"type": "broadcast",
"production_mode": "false",
#"device_tokens": "xx(Android为44位)",
"payload": {
"display_type": "message",  # 消息,message
"body": {
"custom": "自定义custom" # /{}// message类型只需填写custom即可,可以是字符串或JSON。
        }
    },
"policy": {
"expire_time": (datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
    },
"description": "测试单播消息-Android"
}

post_body = json.dumps(data).encode("utf-8")
def md5(s: str):
m = hashlib.md5(s.encode("utf-8"))
return m.hexdigest()

sign = md5('%s%s%s%s' % (method, url, post_body, app_master_secret))
print(sign)
res = requests.post(url=url+"?sign="+sign,data= post_body)
print(res.text)


调用返回提示 签名错误


{"ret":"FAIL","data":{"error_msg":"签名不正确","error_code":"2027"}}

2个回答
 
4 年前
来自上海

楼主你好,你可以检查一下签名的设置,看一下加密成功没有

 
4 年前
来自浙江省

你好,检查一下计算签名时使用的编码方式和发送时是否一致,为保证加密成功,AppMasterSecret 应选择其对应的值,确保App MasterSecret设置正确。

Loading ...
登录社区,分享你的经验