阿里支付
直接用大神写好的模块
# 安装python-alipay-sdk pip install python-alipay-sdk --upgrade
# 伪代码 需要加入自己实际内容运用 from alipay import AliPay class PaymentView(APIView): """付款接口""" def post(self, request): alipay = self.get_alipay() query_params = alipay.api_alipay_trade_page_pay( subject="测试订单", out_trade_no="2017020111", total_amount=111, goods_type=0, # 可选 timeout_express="90m" # 可选 ) pay_url = "https://openapi.alipaydev.com/gateway.do?{}".format(query_params) response.data = "订单创建成功!" response.url = pay_url return Response(response.dict) def get_alipay(self): # 沙箱环境地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info app_id = "2016091100486897" # POST请求,用于最后的检测 notify_url = "http://47.94.172.250:8804/page2/" # notify_url = "http://www.*****.com:8804/page2/" # GET请求,用于页面的跳转展示 return_url = "http://47.94.172.250:8804/page2/" # return_url = "http://www.*****.com:8804/page2/" app_private_key_string = open("utils/keys/app_private_2048.txt").read() # 公钥 文件中的字符串 alipay_public_key_string = open("utils/keys/alipay_public_2048.txt").read() # 阿里公钥 文件中字符串 alipay = AliPay( appid=app_id, app_notify_url=None, # 默认回调url app_private_key_string=app_private_key_string, # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥, alipay_public_key_string=alipay_public_key_string, sign_type="RSA2" , # RSA 或者 RSA2 debug = False # 默认False ) return alipay
原文链接https://github.com/fzlee/alipay/blob/master/README.zh-hans.md