Giter Club home page Giter Club logo

Comments (24)

fzlee avatar fzlee commented on August 19, 2024

你说的是这个吗,用户跳转到支付宝网页,通过扫码或者密实现支付。然后后台可以异步收到支付提醒
https://doc.open.alipay.com/doc2/detail?treeId=62&articleId=103566&docType=1

用create_web_trade可以实现

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

不是这个,是这个
https://doc.open.alipay.com/doc2/detail?treeId=194&articleId=105072&docType=1
WEB和网页还有即时到账现在都要求域名备案的,这个是可以不备案的一个方法,但是官方没python sdk

from alipay.

fzlee avatar fzlee commented on August 19, 2024

暂时没有,反正最近我有时间,明天我做一个试试

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

太好啦,我看了半天不会弄…

from alipay.

fzlee avatar fzlee commented on August 19, 2024

试试新版的代码吧, pip install python-alipay-sdk --upgrade

测试不是很严谨,有bug及时找我

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

好的,我下班了试一下。支持预生成二维码收款的话就可以不用营业执照和备案啦

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

关于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.

fzlee avatar fzlee commented on August 19, 2024

哈哈哈, 好的,我稍后会修改文档

from alipay.

fzlee avatar fzlee commented on August 19, 2024

你是用的Python2吗?里面的code即使是unicode也应该可以取出的,因为python会对unicode做隐式的转换, 比如:

a = {u"name": u"Lily"}
a["name"]
u'Lily'
>>>

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

返回值为:
{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.

relei1988 avatar relei1988 commented on August 19, 2024

是字典里套了个字典的关系 前面我复制的时候少复制了第一个{

from alipay.

fzlee avatar fzlee commented on August 19, 2024

哦,了解, 我明天修改一下吧,其实我是希望所有result返回内容里面不带有alipay_trade_precreate_response这个字段的。

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

我了解啦 那我等更新了再操作 辛苦了

from alipay.

fzlee avatar fzlee commented on August 19, 2024

0.6.1 好了,你可以再试试

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

神速(大拇指),试了有问题我再报告哈

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

现在有个问题是
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.

relei1988 avatar relei1988 commented on August 19, 2024

查了一下,异步检测是要有服务器的,ali会post给你一个支付成功的通知= =
https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.oLj0ut&treeId=194&articleId=103296&docType=1

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

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.

fzlee avatar fzlee commented on August 19, 2024

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.

relei1988 avatar relei1988 commented on August 19, 2024

好的我一会看一看,谢谢

from alipay.

relei1988 avatar relei1988 commented on August 19, 2024

刚传入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.

fzlee avatar fzlee commented on August 19, 2024

用户扫码前一直是显示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.

relei1988 avatar relei1988 commented on August 19, 2024

果然是要扫一下才行,我以为会有pedding之类的状态,之前看到文档里写的WAIT_BUYER_PAY状态 以为会有

from alipay.

fzlee avatar fzlee commented on August 19, 2024

是的,我之前看文档, 也是以为有你说的那个状态,感觉文档和实际的有点对不上了

from alipay.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.