Comments (24)
你说的是这个吗,用户跳转到支付宝网页,通过扫码或者密实现支付。然后后台可以异步收到支付提醒
https://doc.open.alipay.com/doc2/detail?treeId=62&articleId=103566&docType=1
用create_web_trade可以实现
from alipay.
不是这个,是这个
https://doc.open.alipay.com/doc2/detail?treeId=194&articleId=105072&docType=1
WEB和网页还有即时到账现在都要求域名备案的,这个是可以不备案的一个方法,但是官方没python sdk
from alipay.
暂时没有,反正最近我有时间,明天我做一个试试
from alipay.
太好啦,我看了半天不会弄…
from alipay.
试试新版的代码吧, pip install python-alipay-sdk --upgrade
测试不是很严谨,有bug及时找我
from alipay.
好的,我下班了试一下。支持预生成二维码收款的话就可以不用营业执照和备案啦
from alipay.
关于DEMO
预创建/查询/取消当面付
alipay = Alipay(appid="", ...)
# create an order
result1 = alipay.precreate_face_to_face_trade(
"out_trade_no", 100, "test subject"
# you may input more parameters here, refer to alipay official doc for details
)
if result1["code"] = "10000":
print("Order is paid")
elif result1["code"] == "10003":
print("Pending paid by user")
for i in range(10):
# check every 3s to see if the order is paid
time.sleep(3)
result2 = alipay.query_face_to_face_trade(out_trade_no=out_trade_no)
if result2["code"] == "10000":
print("Order is paid")
break
# order is not paid in 30s , cancel this order
alipay.cancel_face_to_face_trade(out_trade_no=out_trade_no)
中Alipay应为AliPay,if result1["code"] = "10000":
应为if result1["code"] == "10000":
别的还没开始试,把密钥啥的输入完发现是要贴路径= =
from alipay.
哈哈哈, 好的,我稍后会修改文档
from alipay.
你是用的Python2吗?里面的code即使是unicode也应该可以取出的,因为python会对unicode做隐式的转换, 比如:
a = {u"name": u"Lily"}
a["name"]
u'Lily'
>>>
from alipay.
返回值为:
{u'alipay_trade_precreate_response': {u'msg': u'Success', u'out_trade_no': u'out_trade_no', u'code': u'10000', u'qr_code': u'https://qr.alipay.com/bax07***6095'}, u'sign': u'EDiiwckDOcvMU***I8Hybrrj+WTxZ89CzNJ55HSgPk0frTvJu7y7XszxrI='}
要用
if result1['alipay_trade_precreate_response']['code'] == "10000":
才行……
from alipay.
是字典里套了个字典的关系 前面我复制的时候少复制了第一个{
from alipay.
哦,了解, 我明天修改一下吧,其实我是希望所有result返回内容里面不带有alipay_trade_precreate_response
这个字段的。
from alipay.
我了解啦 那我等更新了再操作 辛苦了
from alipay.
0.6.1 好了,你可以再试试
from alipay.
神速(大拇指),试了有问题我再报告哈
from alipay.
现在有个问题是
result1 = alipay.precreate_face_to_face_trade(out_trade_no="20150320010101001", total_amount=0.01,subject= "test subject")
用这行可以正确生成付款二维码链接,扫码确认正常,但是result1
中返回的code
其实是指生成二维码是否成功,只要生成二维码成功了返回都是10000,例子中
if result1["code"] == "10000":
print("Order is paid")
讲的应该是异步检测,检测的结果不管付没付都是生成二维码的结果,也就是成功
from alipay.
查了一下,异步检测是要有服务器的,ali会post给你一个支付成功的通知= =
https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.oLj0ut&treeId=194&articleId=103296&docType=1
from alipay.
在node js的F2F项目里,作者写道
服务器网络暴毙? 没收到支付宝回调?
不要慌我给你实现了一个checkInvoiceStatus方法.
/**
* 校验通知签名
* @param {string} postData 支付宝post过的来数据
* @return {bool} 是否通过校验
*/
verifyCallback(postData) {
return aop.notifyVerify(postData, this._config);
}
/**
* 检测订单状况
* @param {string} tradeNo 订单号
* @return {Promise}
*/
checkInvoiceStatus(tradeNo) {
return new Promise((resolve, reject) => {
if (tradeNo == "" || tradeNo == null || tradeNo == undefined) {
return reject({ message: "订单号不能为空.", info : null });
}
aop.execute("alipay.trade.query", this._config, {
out_trade_no: tradeNo
}).then(resolve).catch(reject);
});
}
看来下是这段,不知道是不是一定要有服务器接收post,还是说可以手动request查一下……
from alipay.
notify_url 可以在使用precreate_face_to_face_order 的时候传入,然后支付成功会收到支付宝的回调请求。
然后为了不使用这种回调的方法,可以检查result["trade_status"], 如果是“WAIT_BUYER_PAY”, 说明没有支付,如果是“TRADE_SUCCESS”, 则是支付了
>>> alipay.query_face_to_face_trade(out_trade_no="out_trade_no23")
{'code': '10000', 'msg': 'Success', 'buyer_logon_id': 'csq***@sandbox.com', 'buyer_pay_amount': '0.00', 'buyer_user_id': '20881
02169481075', 'invoice_amount': '0.00', 'open_id': '20880072506750308812798160715407', 'out_trade_no': 'out_trade_no23', 'point
_amount': '0.00', 'receipt_amount': '0.00', 'total_amount': '20.00', 'trade_no': '2017032221001004070200177033', 'trade_status'
: 'WAIT_BUYER_PAY'}
from alipay.
好的我一会看一看,谢谢
from alipay.
刚传入alipay.precreate_face_to_face_trade("out_trade_no23", total_amount=0.01,subject= "test subject")
{u'msg': u'Success', u'out_trade_no': u'out_trade_no23', u'code': u'10000', u'qr_code': u'https://qr.alipay.com/ba***niq4091'}
返回成功,然后查询时同样传入alipay.query_face_to_face_trade(out_trade_no="out_trade_no23")
返回交易不存在
{u'code': u'40004', u'sub_msg': u'\u4ea4\u6613\u4e0d\u5b58\u5728', u'sub_code': u'ACQ.TRADE_NOT_EXIST', u'receipt_amount': u'0.00', u'out_trade_no': u'out_trade_no23', u'buyer_pay_amount': u'0.00', u'invoice_amount': u'0.00', u'msg': u'Business Failed', u'point_amount': u'0.00'}
from alipay.
用户扫码前一直是显示4004的,扫码之后就会有trade_status了,你可以这样试试
alipay = AliPay(appid="", ...)
# create an order
result1 = alipay.precreate_face_to_face_trade(
"out_trade_no", 100, "test subject"
# you may input more parameters here, refer to alipay official doc for details
)
# check order status
paid = False
for i in range(10):
# check every 3s, and 10 times in all
print("now sleep 3s")
time.sleep(3)
result = alipay.query_face_to_face_trade(out_trade_no="out_trade_no24")
if result.get("trade_status", "") == "TRADE_SUCCESS":
paid = True
break
print("not paid...")
# order is not paid in 30s , cancel this order
if paid is False:
alipay.cancel_face_to_face_trade(out_trade_no=out_trade_no)
from alipay.
果然是要扫一下才行,我以为会有pedding之类的状态,之前看到文档里写的WAIT_BUYER_PAY状态 以为会有
from alipay.
是的,我之前看文档, 也是以为有你说的那个状态,感觉文档和实际的有点对不上了
from alipay.
Related Issues (20)
- 支付宝公钥已经采用证书的形式,没有提供公钥这种形式,需要自己转换?请问有没有好的解放方案么?谢谢 HOT 3
- 添加支持 alipay.fund.account.query(支付宝资金账户资产查询接口) HOT 2
- alipay.api_alipay_trade_query(out_trade_no=order_id) HOT 4
- uwsgi 无法正常返回 HOT 6
- 验证回调通知错误 HOT 4
- 没有公网ip,怎么样验证支付是否成功 HOT 2
- 能否增加aes支持 HOT 2
- ImportError: cannot import name 'Alipay' from 'alipay'
- 使用支付宝公钥 初始化AliPay时报错 binascii.Error: Incorrect padding HOT 8
- ssl依赖该升级了 HOT 3
- 您好,请问支持分账吗? HOT 11
- 证书方式如何安装 HOT 30
- 是否支持证书方式的签名 HOT 10
- 应用网关是什么 HOT 3
- 3.0如何获取请求返回状态 HOT 10
- 获取用户信息怎么调用 HOT 9
- alipay支付网关已经变更了
- notify 回调消息验证失败 binascii.Error: Invalid base64-encoded string HOT 8
- ValueError: nameserver is not an IP address or valid https URL HOT 2
- 沙箱环境下调用失败(invalid-app-id)及其解决办法 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alipay.