求一款支持Python开发的扫描支付模块
最近突然对支付扫描模块感兴趣,鉴于只略懂 python,特来找一款支持 python 的模块。
求一款支持Python开发的扫描支付模块
2 回复
对于Python开发的扫描支付,我推荐使用WeChatPay-API-v3或alipay-sdk-python。
如果你需要微信支付,WeChatPay-API-v3是目前最推荐的库:
# 安装:pip install wechatpayv3
from wechatpayv3 import WeChatPay, WeChatPayType
# 初始化
wxpay = WeChatPay(
wechatpay_type=WeChatPayType.NATIVE, # 扫码支付
mchid='商户号',
private_key='商户私钥',
cert_serial_no='证书序列号',
apiv3_key='APIv3密钥',
appid='应用ID',
notify_url='回调地址'
)
# 创建支付订单
def create_native_order(out_trade_no, amount, description):
resp = wxpay.order.create(
out_trade_no=out_trade_no,
amount={'total': amount}, # 单位:分
description=description
)
return resp['code_url'] # 返回二维码链接
支付宝的话,用官方SDK:
# 安装:pip install python-alipay-sdk
from alipay import AliPay
alipay = AliPay(
appid='应用ID',
app_notify_url='回调地址',
app_private_key_string='应用私钥',
alipay_public_key_string='支付宝公钥'
)
# 生成支付链接
order_string = alipay.api_alipay_trade_precreate(
out_trade_no='订单号',
total_amount='金额', # 单位:元
subject='商品描述'
)['qr_code']
这两个都是官方维护的,文档全、更新及时。微信那个用APIv3,比老版本安全多了;支付宝的SDK也挺稳定。看你具体需求选一个就行。
总结:根据支付平台选对应官方SDK。
没有

