Comments (5)
同步验签和异步验签的技术实现原理应该差不多,异步需要验签是为了验证请求确实来自支付宝,而同步不太需要,是因为我们向支付宝发起HTTP请求时,已经验证了它的HTTPS证书。
不过多验证一步也没有问题,我稍后会添加这个功能
from alipay.
OK,多谢!目前我也实现了同步响应验签的功能,不过感觉写得不太好,到时候可以学习下你的代码 👍
from alipay.
暂时推送到了dev, 我好想明白你是怎么纠结同步验签功能的了,获取待验证的字符串有点麻烦,你可以看看这个函数__get_string_to_be_signed
,应该没有什么问题的
from alipay.
同步验签比较麻烦,因为要保证原先 response
中的 key-value
顺序。我是用下面的方式先将 json
字符串提取成有序字典,从而保持原先的顺序不乱:
def load_from_json_text(text, keep_order=True):
"""
加载 json 格式的文本
"""
from json import loads
from collections import OrderedDict
if keep_order is True:
return loads(text, object_pairs_hook=OrderedDict)
else:
return loads(text)
然后将 xxx_response
提取出来(仍然是有序字典)后再转回 json
字符串,参见下面的函数。在重新转成 json 字符串时,要把 ,
, :
两边空格去掉,才能和原先的字符串一致。:
def to_json_text(data=None, sort_keys=True):
"""
用于将字典转换成有序的字符串 JSON
:param data: 字典数据
:param sort_keys: 是否排序
:return:
"""
from json import dumps
assert isinstance(data, dict)
return dumps(data, ensure_ascii=False, sort_keys=sort_keys, separators=(',', ':'))
总的来说,也挺麻烦,不过多多借助了 json
模块。
:)
from alipay.
感觉你的方法好一点
from alipay.
Related Issues (20)
- alipay.api_alipay_trade_query(out_trade_no=order_id) HOT 4
- uwsgi 无法正常返回 HOT 6
- 验证回调通知错误 HOT 4
- 没有公网ip,怎么样验证支付是否成功 HOT 2
- 能否增加aes支持 HOT 2
- ImportError: cannot import name 'Alipay' from 'alipay'
- 使用支付宝公钥 初始化AliPay时报错 binascii.Error: Incorrect padding HOT 8
- ssl依赖该升级了 HOT 3
- 您好,请问支持分账吗? HOT 11
- 证书方式如何安装 HOT 30
- 是否支持证书方式的签名 HOT 10
- 应用网关是什么 HOT 3
- 3.0如何获取请求返回状态 HOT 10
- 获取用户信息怎么调用 HOT 9
- alipay支付网关已经变更了
- notify 回调消息验证失败 binascii.Error: Invalid base64-encoded string HOT 8
- ValueError: nameserver is not an IP address or valid https URL HOT 2
- 沙箱环境下调用失败(invalid-app-id)及其解决办法 HOT 4
- 支付宝POST回调时使用alipay.verify报错 HOT 4
- 调试错误,请回到请求来源地,重新发起请求。 错误代码 invalid-signature 错误原因: 验签出错,建议检查签名字符串或签名私钥与应用公钥是否匹配 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alipay.