收藏
回答

支付签名mp_sig error

Python代码

class WxMiniGame(object):
 
    def __init__(self, midas_app_key, session_key)
        self.midas_app_key = midas_app_key
        self.session_key = session_key
 
    def _sort_params(self, data):
        return "&".join([
            "%s=%s" % i for i in
            sorted(data.items(), key=lambda m:m[0])
        ])
 
    def _init_sign(self, uri, req_data):
        sig_data = {
            "openid": req_data.get("openid"),
            "appid": req_data.get("appid"),
            "offer_id": req_data.get("offer_id"),
            "ts": req_data.get("ts"),
            "zone_id": req_data.get("zone_id"),
            "pf": req_data.get("pf"),
        }
        request_method = "POST"
        request_str = self._sort_params(sig_data)
        unsign_str = "%s&org_loc=%s&method=%s&secret=%s" % (
                request_str, uri, request_method, self.midas_app_key
            )
        error_logger.error(unsign_str)
        sig = hmac.new(self.midas_app_key, unsign_str, hashlib.sha256)\
                .hexdigest()
         
        ### 生成mp_sig
        sig_data.update({
                "sig": sig,
                "access_token": req_data.get("access_token"),
            })
        request_str = self._sort_params(sig_data)
        unsign_str = "%s&org_loc=%s&method=%s&session_key=%s" % (
                request_str, uri, request_method, self.session_key
            )
        error_logger.error(unsign_str)
        mp_sig = hmac.new(self.session_key, unsign_str, hashlib.sha256)\
                .hexdigest()
 
        req_data.update({
                "sig": sig,
                "mp_sig": mp_sig,
            })
 
 
wmg = WxMiniGame("my_midas_app_key", "my_session_key")
 
uri = "/cgi-bin/midas/getbalance"
req_data = {
    "openid": "my_open_id",
    "appid": "my_app_id",
    "offer_id": "my_offer_id",
    "ts": int(time.time()),
    "zone_id": "zone_id",
    "pf": "android",
}
wmg._init_sign(uri, req_data)


返回错误

{'errcode': 90009, 'errmsg': 'mp_sig error hint: [v197dA0543shc1]'}


帮看看算法有没有问题

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容