python
pip install alipay-sdk-python
python
from alipay import AliPay
python
app_id = 'your_app_id'
app_private_key_path = 'your_app_private_key_path'
alipay_public_key_path = 'your_alipay_public_key_path'
callback_url = 'your_callback_url'
python
alipay = AliPay(
appid=app_id,
app_notify_url=callback_url,
app_private_key_path=app_private_key_path,
alipay_public_key_path=alipay_public_key_path,
sign_type='RSA2'
)
python
order_number = 'your_order_number'
total_amount = 'your_total_amount'
python
order_string = alipay.api_alipay_trade_page_pay(
out_trade_no=order_number,
total_amount=total_amount,
subject='your_subject',
return_url=callback_url,
notify_url=callback_url
)
python
from flask import Flask, request
app = Flask(__name__)
@app.route('/callback', methods=['POST'])
def handle_callback():
params = request.form.to_dict()
signature = params.pop('sign')
if alipay.verify(params, signature):
return 'success'
return 'fail'
if __name__ == '__main__':
app.run()