10000 GitHub - qitianchan/alipay: alipay python sdk
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

qitianchan/alipay

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
< CAD5 div class="react-directory-truncate">LICENSE.txt
 
 
 
 
 
 
 
 
 
 

Repository files navigation

支付宝Python SDK

支付宝没有提供Python SDK。生成预付订单需要使用SHA1withRSA签名,签名的生成比较麻烦容易出错。这里提供了一个简单的库,希望能够简化一些Python开发的流程。

目前我们支持如下三种支付方式,且签名类型必须为RSA

关于支付宝移动支付的详细介绍参看这篇教程. 如果你不希望深入了解技术实现的细节,你可以直接参看下面的使用教程。

使用教程

安装

pip install python-alipay-sdk

####初始化

    from alipay import AliPay
    
    # 手机网站或者app支付
    alipay = AliPay(
      notify_url="", 
      appid="",
      app_private_key_path="", 
      app_alipay_public_key_path=""
    )
	
	# 即时到帐
	alipay = AliPay(
      notify_url="", 
      partner="",
      partner_private_key_path="", 
      partner_alipay_public_key_path=""
    )
	
	# 如果你希望 alipay能够同时处理三种支付方式, 那就传入所有的参数
	alipay = AliPay(
      notify_url="", 
	  appid="",
      app_private_key_path="",
      app_alipay_public_key_path="",
      partner="",
      partner_private_key_path="", 
      partner_alipay_public_key_path=""
    )

生成订单

	# App支付,将order_string返回给app即可
	order_string = alipay.create_app_trade(out_trade_no="20161112", total_amount="0.01", subject="测试订单")
	# 手机网站支付,需要跳转到https://openapi.alipay.com/gateway.do? + order_string
	order_string = alipay.create_wap_trade(out_trade_no="20161112", total_amount="0.01", subject="测试订单", return_url="")
	# 即时到帐,需要跳转到https://mapi.alipay.com/gateway.do? + order_string
	order_string = alipay.create_web_trade(out_trade_no="20161112", total_amount="0.01", subject="测试订单", return_url="")

通知验证

	# 验证alipay的异步通知,data来自支付宝回调POST 给你的data,字典格式.
	data = {
          "subject": "测试订单",
          "gmt_payment": "2016-11-16 11:42:19",
          "charset": "utf-8",
          "seller_id": "xxxx",
          "trade_status": "TRADE_SUCCESS",
          "buyer_id": "xxxx",
          "auth_app_id": "xxxx",
          "buyer_pay_amount": "0.01",
          "version": "1.0",
          "gmt_create": "2016-11-16 11:42:18",
          "trade_no": "xxxx",
          "fund_bill_list": "[{\"amount\":\"0.01\",\"fundChannel\":\"ALIPAYACCOUNT\"}]",
          "app_id": "xxxx",
          "notify_time": "2016-11-16 11:42:19",
          "point_amount": "0.00",
          "total_amount": "0.01",
          "notify_type": "trade_status_sync",
          "out_trade_no": "xxxx",
          "buyer_logon_id": "xxxx",
          "notify_id": "xxxx",
          "seller_email": "xxxx",
          "receipt_amount": "0.01",
          "invoice_amount": "0.01",
          "sign": "xxx"
        }
	data.pop("sign_type", "")
    signature = data.pop("sign")
	# 验证app支付
	success = alipay.verify_app_notify(data, signature)
    # 验证手机网站支付
	success = alipay.verify_wap_notify(data, signature)
	# 验证即时到帐
	success = alipay.verify_web_notify(data, signature)
	if success and (data["trade_status"] == "TRADE_SUCCESS" or data["trade_status"] == "TRADE_FINISHED" ):
		print("trade succeed")

About

alipay python sdk

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%
0