跳到主要内容

支付宝服务窗H5跨境支付


For code instructions select Python, Java, Node.js or PHP with the tabs below.

#coding=utf8
import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, hashlib
import requests
import datetime
import string

# Enter Client Credentials
environment = 'https://test-openapi-hk.qfapi.com'
app_code = 'D5589D2A1F2E42A9A60C37*********'
client_key = '0E32A59A8B454940A2FF39**********'


# Create parameter values for data payload
current_time = datetime.datetime.now().replace(microsecond=0)

print(current_time)

# Create signature
def make_req_sign(data, key):
keys = list(data.keys())
keys.sort()
p = []
for k in keys:
v = data[k]
p.append('%s=%s'%(k,v))
unsign_str = ('&'.join(p) + key).encode("utf-8")
s = hashlib.md5(unsign_str).hexdigest()
return s.upper()


# Body payload
txamt = '10' #In USD,EUR,etc. Cent. Suggest value > 200 to avoid risk control
txcurrcd = 'HKD'
pay_type = '801107' # Alipay Wap Payment = 801107
auth_code='283854702356157409' #CPM only
out_trade_no = '01234567890123'
txdtm = current_time
goods_name = 'test1'
mchid = 'ZaMVg*****'
key = client_key


#data ={'txamt': txamt, 'txcurrcd': txcurrcd, 'pay_type': pay_type, 'out_trade_no': out_trade_no, 'txdtm': txdtm, 'goods_name': goods_name, 'mchid': mchid}
data ={'txamt': txamt, 'txcurrcd': txcurrcd, 'pay_type': pay_type, 'out_trade_no': out_trade_no, 'txdtm': txdtm, 'mchid': mchid}

r = requests.post(environment+"/trade/v1/payment",data=data,headers={'X-QF-APPCODE':app_code,'X-QF-SIGN':make_req_sign(data, key)})

print(r.json())

The above command returns JSON structured like this:

{
"sysdtm": "2020-04-13 11:32:03",
"paydtm": "2020-04-13 11:32:03",
"txcurrcd": "HKD",
"respmsg": "",
"pay_type": "801107",
"cardcd": "",
"udid": "qiantai2",
"txdtm": "2020-04-13 11:32:03",
"txamt": "300",
"resperr": "success",
"out_trade_no": "BUFB3PT9ZDUWEUAE4ATD21JKNHVEIIPV",
"syssn": "20200413000200020087171988",
"respcd": "0000",
"pay_url": "https://globalmapi.alipay.com/gateway.do?total_fee=3.0&secondary_merchant_name=###merchant_name###&out_trade_no=20200413000200020087171988&secondary_merchant_industry=7011&service=create_forex_trade_wap&_input_charset=UTF-8&sign=f16ef36efbb55058d1c1d36fef89bcf8&currency=THB&timeout_rule=30m&notify_url=https%3A%2F%2Fo2.qfpay.com%2Fonline-test%2Ftrade%2Falipay%2Fv1%2Fonline_notify&secondary_merchant_id=2565075&sign_type=MD5&partner=2088631377368888&product_code=NEW_WAP_OVERSEAS_SELLER&return_url=&subject=###merchant_name###",
"chnlsn": ""
}
Alipay H5 process-flow

支付宝服务窗H5跨境支付(WAP)

支付宝服务窗口H5支付允许商户使用JSAPI接口调用支付宝支付模块进行收款.顾客可以通过支付宝在商户的手机端网站上确认总金额后付款.

HTTP请求

POST ../trade/v1/payment PayType: 800107

Step 1: 获取userid 详细请参考支付宝官方文档.

Step 2: 请求支付

请求支付参数

参数名称参数编码是否必填参数类型描述
常用支付参数
支付宝授权码openidString(64)从第一步所返回的 user_id, 示例: 2088802811715388
重定向URLreturn_urlString(512)用户在成功支付后跳转的地址
指定支付方式limit_payString只适用于中国大陆

响应参数

参数编码二级参数编码参数类型参数名称描述
pay_paramstradeNOString交易号通过传入交易号唤起快捷调用方式
txcurrcdString(3)交易币种, 请查看币种表以获取完整的可选用的币种
常用响应参数

Step 3: 收银台唤起支付 详细请参考支付宝官方文档.