文章目录
- 签名方法
- 异步同步通知数据验签
- 生活号响应数据验签
- 同步响应数据验签
🌈你好呀!我是 山顶风景独好
🎈欢迎踏入我的博客世界,能与您在此邂逅,真是缘分使然!😊
🌸愿您在此停留的每一刻,都沐浴在轻松愉悦的氛围中。
📖这里不仅有丰富的知识和趣味横生的内容等您来探索,更是一个自由交流的平台,期待您留下独特的思考与见解。🌟
🚀让我们一起踏上这段探索与成长的旅程,携手挖掘更多可能,共同进步!💪✨
签名方法
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
from alipay.aop.api.util.SignatureUtils import *
# 请求的待签名字符串(已升序排序处理)
content = "app_id=20***2&biz_content={\"out_trade_no\":\"20190401144352106451724\",\"total_amount\":\"0.01\",\"subject\":\"土豪机\",\"timeout_express\":\"10m\",\"qr_code_timeout_express\":\"2m\",\"store_id\":\"HK001\"}&charset=UTF-8&format=json&method=alipay.trade.precreate¬ify_url=http://notify.dengw.online/do/6e5e3bd0-c2c5-4565-bcfd-bf57ea822672&sign_type=RSA2×tamp=2019-04-01 14:43:53&version=1.0"
# 私钥
privateKey = ""
# 编码格式
charset = "utf-8"
# 请求网关地址
gateway = "https://openapi.alipay.com/gateway.do"
# RSA2签名方式
sign = sign_with_rsa2(privateKey, content, charset)
# RSA签名方式
# sign = sign_with_rsa(privateKey, content, charset)
# 输出sign值
print sign
异步同步通知数据验签
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from alipay.aop.api.util.SignatureUtils import verify_with_rsa
# 支付宝公钥
alipay_public_key = ""
# 待签名字符串需要做升序处理,且去除sign和sign_type
message = "app_id=201****2&auth_app_id=2014****2&body=煜雨电脑网站测试&buyer_id=2088022*****2&buyer_pay_amount=0.01&charset=UTF-8&fund_bill_list=[{\"amount\":\"0.01\",\"fundChannel\":\"PCREDIT\"}]&gmt_create=2019-03-29 19:42:00&gmt_payment=2019-03-29 19:42:03&invoice_amount=0.01¬ify_id=2019032900222194204081941005192208¬ify_time=2019-03-29 19:42:04¬ify_type=trade_status_sync&out_trade_no=20190329ygyg45484544100003&point_amount=0.00&receipt_amount=0.01&seller_id=20*******5&subject=煜雨测试电脑网站支付&total_amount=0.01&trade_no=2019032922001481941025940236&trade_status=TRADE_SUCCESS&version=1.0"
# 返回的sign值
sign = ""
# 验签方法,message必须做一次encode否则接口抛异常(直接对message参数值转义也会异常)
flag = verify_with_rsa(alipay_public_key, message.encode('UTF-8','strict'), sign)
# 输出验签结果
print flag
生活号响应数据验签
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from alipay.aop.api.util.SignatureUtils import verify_with_rsa
# 支付宝公钥
alipay_public_key = ""
# 待签名字符串需要做升序处理,去除sign
message = "biz_content=<?xml version=\"1.0\" encoding=\"gbk\"?><XML><AppId><![CDATA[20*****6]]></AppId><FromUserId></FromUserId><CreateTime><![CDATA[15****5]]></CreateTime><MsgType><![CDATA[event]]></MsgType><EventType><![CDATA[verifygw]]></EventType><ActionParam></ActionParam><AgreementId></AgreementId><AccountNo></AccountNo></XML>&charset=GBK&service=alipay.service.check&sign_type=RSA2"
# 返回的sign值
sign = ""
# 验签方法,message必须做一次encode否则接口抛异常(直接对message参数值转义也会异常)
flag = verify_with_rsa(alipay_public_key, message.encode('UTF-8','strict'), sign)
# 输出验签结果
print flag
同步响应数据验签
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from alipay.aop.api.util.SignatureUtils import verify_with_rsa
# 支付宝公钥
alipay_public_key = ""
# 响应的待验签字符串大框号内的值
message = "{\"code\":\"10000\",\"msg\":\"Success\",\"app_id\":\"201***5\",\"auth_app_id\":\"201***\",\"charset\":\"utf-8\",\"timestamp\":\"2019-04-01 14:33:01\",\"out_trade_no\":\"0401022927-9449\",\"total_amount\":\"0.01\",\"trade_no\":\"2019040122001456751034473539\",\"seller_id\":\"2088***5\"}"
# 返回的sign值
sign = ""
# 验签方法,message必须做一次encode否则接口抛异常(直接对message参数值转义也会异常)
flag = verify_with_rsa(alipay_public_key, message.encode('UTF-8','strict'), sign)
# 输出验签结果
print flag
✨ 这就是今天要分享给大家的全部内容了,我们下期再见!😊
🏠 我在CSDN等你哦!我的主页😍