博客
关于我
python-aliyay-sdk中verify函数一直返回false的解决办法
阅读量:639 次
发布时间:2019-03-14

本文共 1800 字,大约阅读时间需要 6 分钟。

最近flask项目在使用支付宝沙箱支付时出现了以下问题:

def verify(self, data, signature):    if "sign_type" in data:        sign_type = data.pop("sign_type")        if sign_type != self._sign_type:            raise AliPayException(None, "Unknown sign type: {}".format(sign_type))        # 排序后的字符串        unsigned_items = self._ordered_data(data)        message = "&".join(u"{}={}".format(k, v) for k, v in unsigned_items)        return self._verify(message, signature)

verify函数接收两个变量,其中data是支付宝发送过的除了sign(签名信息)以外的其他信息,signature是支付宝发送过来的签名信息,verify函数会更具data信息来生成一个前面信息和支付宝的signature做比较,如果相等则返回true,不相等返回false。

在运行过程中该函数的返回结果一直是false,verify函数中把sign_type参数给剔除掉了。
解决办法对verify函数进行以下修改:

def verify(self, data, signature):        # if "sign_type" in data:        #     sign_type = data.pop("sign_type")        #     if sign_type != self._sign_type:        #         raise AliPayException(None, "Unknown sign type: {}".format(sign_type))        # 排序后的字符串        unsigned_items = self._ordered_data(data)        message = "&".join(u"{}={}".format(k, v) for k, v in unsigned_items)        return self._verify(message, signature)

支付宝请求的网址如下:GET /payComplete.html?charset=utf-8&out_trade_no=25&method=alipay.trade.wap.pay.return&total_amount=5000.00&sign=TqQXWB0glO95D3usCbvES38L%2BZn4XjG8mR%2FhoTMmbR8CU0GJePMFTcN%2Flh%2FoaebCzZcQytmO2QV1DRdyJJhaVx618T0t0WlV4V%2F4ItVZbWt8VfUOJUD8Mvv5c1qmPwIo05FaoIa9crF6qX8SWKweSiuaU7bRFbmwGfIYGE1Ga00f7HpqH3BOUs6eT4KkmUq5mVVLIOPftsPyQDF9zs%2FYlcnHGsBb4RRMS1uRGASNuoax6VrPpOKC%2BpsMqAoROB5SPC2FZTBEKd48rEZ6MaGA9zdTnbKGyWajJ2lmZZwfjbKpgsDkCFgD%2F2VL4upxfDwMoqRv%2Fbn3F%2F4sDD%2FUCpUMPg%3D%3D&trade_no=2020090722001475820501161374&auth_app_id=2016101900722989&version=1.0&app_id=2016101900722989&sign_type=RSA2&seller_id=2088102180276586&timestamp=2020-09-07+11%3A22%3A56 HTTP/1.1" 200 -

如果有不对的地方希望大家多多指教!

转载地址:http://eihoz.baihongyu.com/

你可能感兴趣的文章
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>