标签:seq ash ipa bak http return 资质 沙箱 deb
支付宝开放平台: https://open.alipay.com/platform/home.htm
支付宝沙箱环境: https://openhome.alipay.com/platform/appDaily.htm?tab=info
支付宝开发者文档:https://openhome.alipay.com/developmentDocument.htm
电脑网站支付流程:https://docs.open.alipay.com/270
生成签名:https://docs.open.alipay.com/291/106103/
python-alipay-adk : https://github.com/fzlee/alipay/blob/master/README.zh-hans.md
直接使用第三方SDK(python-alipay-sdk): https://github.com/fzlee/alipay/blob/master/README.zh-hans.md
# 访问"支付宝开发平台"登录,可以访问开发者中心
https://open.alipay.com/platform/home.htm
# 可以参考"电脑网站支付" 熟悉电脑支付整体流程
https://docs.open.alipay.com/270/105899/
1)沙箱环境说明
1. 线上环境需要创建应用,因为我们不是企业,没有资质,所以只能申请沙箱环境
2. 简单来讲沙箱环境就是给开发者使用的测试环境
3. 沙箱环境地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info
生成秘钥参考官网:https://docs.open.alipay.com/291/105971
沙箱环境地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info
阿里官方没有提供python对接支付的sdk,但是python库中有非官方的sdk包可以使用
python-alipay-adk : https://github.com/fzlee/alipay/blob/master/README.zh-hans.md
使用起来非常简单,只要传入几个必要的参数就可以完成
由于支付对安全要求很高,所以要理解对接支付宝安全的流程:公钥加密、私钥解密 这八个字
# alipay_test.py
from alipay import AliPay
# 沙箱环境中 app 私钥
app_private_key_string = open('app_private_key.pem').read()
# 支付宝公钥
alipay_public_key_string = open( 'alipay_public_key.pem').read()
def get_alipay_url():
alipay = AliPay(
appid="2016101800716047", # 沙箱appid
app_notify_url=None, # 默认回调url
app_private_key_string=app_private_key_string,
# 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
alipay_public_key_string=alipay_public_key_string,
sign_type="RSA", # RSA 或者 RSA2
debug=True, # 默认False,我们是沙箱,所以改成True(让访问沙箱环境支付宝地址)
)
# 调用支付接口
# 电脑网站支付,需要跳转到https://openapi.alipay.com/gateway.do? + order_string
order_string = alipay.api_alipay_trade_page_pay(
out_trade_no="201611124", # 订单id,应该从前端获取
total_amount=str(0.01), # 订单总金额
subject="测试阿里云付款", # 付款标题信息
return_url=None, # 付款成功回调地址(可以为空)
notify_url=None # 付款成功后异步通知地址(可以为空)
)
pay_url = "https://openapi.alipaydev.com/gateway.do?" + order_string
print(pay_url) # 将这个url复制到浏览器,就会打开支付宝支付页面
def query_pay():
alipay = AliPay(
appid="2016101800716047", # 沙箱appid
app_notify_url=None, # 默认回调url
app_private_key_string=app_private_key_string,
# 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥
alipay_public_key_string=alipay_public_key_string,
sign_type="RSA", # RSA 或者 RSA2
debug=True, # 默认False,我们是沙箱,所以改成True(让访问沙箱环境支付宝地址)
)
trade_query = alipay.api_alipay_trade_query(
out_trade_no=20161112, # 上面生成支付码页面时传入的商品订单号
trade_no=None
)
print(trade_query)
if __name__ == '__main__':
get_alipay_url()
query_pay()
'''
trade_query 查询用户付款信息
返回信息详情请看官方:https://docs.open.alipay.com/api_1/alipay.trade.query
{
"code": "10000", # code=10000代表支付成功
"msg": "Success",
"buyer_logon_id": "foq***@sandbox.com",
"buyer_pay_amount": "0.00",
"buyer_user_id": "2088102180228981",
"buyer_user_type": "PRIVATE",
"invoice_amount": "0.00",
"out_trade_no": "20161112",
"point_amount": "0.00",
"receipt_amount": "0.00",
"send_pay_date": "2020-02-20 21:20:48",
"total_amount": "0.01",
"trade_no": "2020022022001428981000087565",
"trade_status": "TRADE_SUCCESS"
}
'''
# alipay_public_key.pem 支付宝公钥
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIgHnOn7LLILlKETd6BFRJ0GqgS2Y3mn1wMQmyh9zEyWlz5p1zrahRahbXAfCfSqshSNfqOmAQzSHRVjCqjsAw1jyqrXaPdKBmr90DIpIxmIyKXv4GGAkPyJ/6FTFY99uhpiq0qadD/uSzQsefWo0aTvP/65zi3eof7TcZ32oWpwIDAQAB
-----END PUBLIC KEY-----
# app_private_key.pem app私钥
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqHFHARYve67Nt/xADRjFsRVTuwOaUiE6GBoQD6JnDOeD07TF1L7cqL4c4zxqEWlcb5p7ZO5Czyw7mpQ7W1jtI9smBxEPEC0ZvlsOuh8zAiVng4gj54eDHarLhfkMk+/pzq44AT/B1CQgtUJRGZrppTO/4SEQZYMO5RcesnPO32QIDAQABAoGAZXlbMuzJkQLdGAKM1McseD+reHjNk1D0NnLwkTxRbOm7zZ8oX5VFF/8eFL9GPCl/yP77Ru6HVRkOHHvdrD5DQjkJ4VipmDQ8xfZlpMmdc2HLtezqR9GG3xso/cAdpCCRjR+vHfr/BTltEiZD3OJapGojyURo/QG5qe7r5lPGBJkCQQD0iZy2+xTfgS58vlD8wtYOXVYkQ4aGtejKx0wgvyws3ahLmv5t9lBB6YfKCVuOHv1ZvwAngWpTsoh4vxeLT8sbAkEAshWaaRyER9SJaeMIBuRf24Bmlyk6piDLTpOOE4lduvjR6j+IgJjY5/N4QTwy9G1vMVwWVzOX/wyinrY48wSkGwJBALcncudiO4oDuYvZB9OpIqZzphdXNCUljoyCpTRJu46HHowyNKqruAUGIpxiUd6qu1tCwZzVQ4wYxjqZ9cp0I00CQEJJ7ldQCSFfyOLEYrmGCvR/ADEmZLFwJZ2TKWC2UlCFzEWg7qPHwX3d0BagXOtFTQ2XlK1TBDIpNuNTOzGiuZ8CQAY/vcaxPm3VyjfevHpFmmwqHuNmRTyKdc3bd8NXTj/MJk7en/gK86PUHdixvudojGTbQOdSSWM/QQoVu8d+DFk=
-----END RSA PRIVATE KEY-----
python-alipay-adk : https://github.com/fzlee/alipay/blob/master/README.zh-hans.md
标签:seq ash ipa bak http return 资质 沙箱 deb
原文地址:https://www.cnblogs.com/xinzaiyuan/p/12371539.html