fzlee / alipay

Python Alipay(支付宝) SDK with SHA1/SHA256 support
Other
1.29k stars 378 forks source link

验证回调通知错误 #139

Closed hyoukaija closed 2 years ago

hyoukaija commented 2 years ago

使用文档提示代码验证回调通知接口时,支付宝返回的数据全是list 环境:django rest framework

代码:

data = request.data.copy()
sign = data.pop("sign")
# 日志中打印
logger.error(data)
verify_re = alipay.verify(data, sign)

日志打印结果: <QueryDict: {'gmt_create': ['2022-04-22 01:54:42'], 'charset': ['utf-8'], 'seller_email': ['hnjck@163.com'], 'subject': ['star-10min'], 'buyer_id': ['2088812963715204'], 'invoice_amount': ['6.00'], 'notify_id': ['2022042200222015443015201411061542'], 'fund_bill_list': ['[{"amount":"6.00","fundChannel":"PCREDIT"}]'], 'notify_type': ['trade_status_sync'], 'trade_status': ['TRADE_SUCCESS'], 'receipt_amount': ['6.00'], 'app_id': ['2021003122614884'], 'buyer_pay_amount': ['6.00'], 'seller_id': ['2088341365256665'], 'gmt_payment': ['2022-04-22 01:54:43'], 'notify_time': ['2022-04-22 01:54:43'], 'version': ['1.0'], 'out_trade_no': ['202204220254368957891'], 'total_amount': ['6.00'], 'trade_no': ['2022042222001415201447873962'], 'auth_app_id': ['2021003122614884'], 'buyer_logon_id': ['185****6517'], 'point_amount': ['0.00']}> 所有值都是list

hyoukaija commented 2 years ago

问题解决,做了一次数据处理

data = {}
        for key, value in request.data.items():
            data[key] = value

分析的话,应该是请求解析过程出问题,至于为什么出现这个问题,希望大佬可以点评一下

fzlee commented 2 years ago

URL里面这种写法是正确的:

example.com?a=123&a=456 那么用dict就没有办法表示了,所以用了QueryDict。

现在比较规范的框架会用QueryDict, 稍微不严谨的会用dict表示。 以前restframework应该可以用request.data 现在可能也是修改了?

H0nGzA1 commented 1 year ago

drf 改了, requset.data 拿不到回调数据了

H0nGzA1 commented 1 year ago
image