Personal payment plan (no contract required) - Pay in person with Alipay

background

As an individual developer, the author wanted to access the payment function, so he learned about the current payment-related solutions and found that there are generally the following types (seexpay< a i=2>):

  • Alipay and WeChat official payment interfaces: basically require enterprise qualifications to open, at least individual industrial and commercial households (with a business license).
  • Third-party payment platform: for exampleTuring payment, xpay Wait, individual developers are supported, but the handling fee is too high.
  • Ye Luzi: There are open source solutions on the Internet that monitor the payment notifications of Alipay app and realize payment, such as PaysApi, Green Dot Payment, etc. In essence, they still adopt the strategy of on-hook monitoring, but they are aimed at the payment notifications of mobile Alipay or WeChat. Message, high cost, troublesome configuration, requires an Android phone to be installed 24 hours a day, not free

The above solutions either do not have enterprise qualifications, are too troublesome, or are too expensive. Fortunately, I discovered Alipaypay in person (individual activation is supported, but If you need store photos, Baidu is fine).
Insert image description here
The business license is optional. If you do not upload it, the single payment is limited to ≤1000 and the single-day payment is ≤5W, which is enough for individual developers.
I have used python to encapsulate the Alipay face-to-face payment SDK and integrated it into flask. The following is the github address
Python has encapsulated the Alipay face-to-face payment SDK

Alipay face-to-face payment integrated into flask

renderings

Insert image description here
Insert image description here
Insert image description here

Pay in person with Alipay

Access process

  • Clickhere to enter, log in to your Alipay account and choose to access immediately.
  • Business content: Department store retail-supermarket-supermarket (non-platform type)
  • Business license does not need to be uploaded
  • Store signs can be found on Baidu
  • You will receive an approval notification more than ten minutes after submitting your application.

Development Process

After successful access, you can see many of my applications in theAnt Financial Open Platformwebpage & mobile application An application of "Application 2.0 Signing******" is created:
Insert image description here
Now we can develop and access it, which is generally divided into the following steps (refer toPay documents in person,Pay development process in person):

  • Configure the public key and private key for face-to-face payment
    • Find the application "Application 2.0 Signing******" and click on the right side to view details
      Insert image description here
    • Set the public key in the application information
      Insert image description here
      Alipay officially provides a key generation tool. It is very simple. Use the tool to generate the application public key and private key, and set the application public key to Alipay. The application private key is saved locally. After the application public key is set to Alipay, Alipay will generate an Alipay public key and save it locally. See here for details
  • Development: I use python as the backend and the open source library. Here is a simple code example:
from alipay import AliPay
import time

# 密钥工具生成的私钥,和支付宝公钥(我保存在了文件中)
app_private_key_string = open("app_private_key.pem").read()
alipay_public_key_string = open("alipay_public_key.txt").read()

print(alipay_public_key_string)
'''
这里打印应该是这种格式(如果支付宝密钥生成工具生成的密钥没有头尾要自己加上)
私钥格式:
-----BEGIN RSA ** KEY-----
    base64 encoded content
-----END RSA PRIVATE KEY-----

公钥格式:
-----BEGIN PUBLIC KEY-----
    base64 encoded content
-----END PUBLIC KEY-----
'''

alipay = AliPay(
    appid="2019***********",   # 应用列表中“应用2.0签约******”的appid
    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
)

out_trade_no = "out_trade_no_123"
# 创建订单
result = alipay.api_alipay_trade_precreate(
    subject="test subject",  # 订单标题
    out_trade_no=out_trade_no,  # 订单号(不可重复)
    total_amount=0.1    # 订单金额,单位元
)

print(result)
# 这里应该打印出{'code': '10000', 'msg': 'Success', 'out_trade_no': 'out_trade_no_123', 'qr_code': 'https://qr.alipay.com/bax05832mvaotxhcpjeh6074'}
# 其中用qr_code生成二维码,支付宝扫描即可付款

# check order status
paid = False
for i in range(30):
    # check every 3s, and 10 times in all
    print("now sleep 3s")
    time.sleep(3)
    result = alipay.api_alipay_trade_query(out_trade_no=out_trade_no)
    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:
    print("支付失败,取消订单")
    alipay.api_alipay_trade_cancel(out_trade_no=out_trade_no)
else:
    print("支付成功")

other

Face-to-face payment related interfaces

View transaction data here

Guess you like

Origin blog.csdn.net/rankun1/article/details/92401295