Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solution

Generating pre-sign string

Except for sign and sign_type, all other parameters used need to be signed.

Generating the pre-sign string for request

For In-App Payment, combine all array values in the format of key="value" (with quotation marks) and then link them up with the ampersand symbol (&) in an alphabetical order. For example:

For the following parameter array:

copy
key-----------------------value
total_fee-----------------0.01
trade_information---------{"business_type":"4","goods_info":"Macbook 12 inch M3 8G 256G SSD^1|Apple iPad Pro 11 inch^1","total_quantity":"2"}
_input_charset------------UTF-8
appenv--------------------system=android^version=3.0.1.2
body----------------------test
currency------------------USD
forex_biz-----------------FP
out_trade_no--------------out_trade_no_20200109_175417
partner-------------------2088021017666931
payment_type--------------1
product_code--------------NEW_WAP_OVERSEAS_SELLER
seller_id-----------------2088021017666931
service-------------------mobile.securitypay.pay
subject-------------------Mika's coffee shop

The pre-sign string after processing:

_input_charset="UTF-8"&appenv="system=android^version=3.0.1.2"&body="test"&currency="USD"&forex_biz="FP"&out_trade_no="out_trade_no_20200109_175417"&partner="2088021017666931"&payment_type="1"&product_code="NEW_WAP_OVERSEAS_SELLER"&seller_id="2088021017666931"&service="mobile.securitypay.pay"&subject="Mika's coffee shop"&total_fee="0.01"&trade_information="{"business_type":"4","goods_info":"Macbook 12 inch M3 8G 256G SSD^1|Apple iPad Pro 11 inch^1","total_quantity":"2"}"

Generating the pre-sign string for synchronous notification

The following sample illustrates the content of a synchronous notification:

resultStatus={9000};memo={};result={partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="test"&body="testtest"&total_fee="0.01"&notify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&show_url="m.alipay.com"&success="true"&sign_type="RSA"&sign="hkFZr+zE9499nuqDNLZEF7W75RFFPsly876QuRSeN8WMaUgcdR00IKy5ZyBJ4eldhoJ/2zghqrD4E2G2mNjs3aE+HCLiBXrPDNdLKCZgSOIqmv46TfPTEqopYfhs+o5fZzXxt34fwdrzN4mX6S13cr3UwmEV4L3Ffir/02RBVtU="}

Take out the part of result, remove sign and sign_type parameters:

partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="test"&body="testtest"&total_fee="0.01"&notify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&show_url="m.alipay.com"&success="true"

Generating the pre-sign string for asynchronous notification

The following sample illustrates the contents of an asynchronous notification:

http://0ee96cd2.ngrok.io/notify.htm? buyer_id=208812287878****&currency=HKD&forex_rate=0.85420000&notify_id=e5f5c6a77034fcd111e373e7e61dcbegdy&notify_type=trade_status_sync&notify_time=2017-08-11 17:31:39&out_trade_no=0811172929-1013&rmb_fee=0.09&seller_id=208861122157****&trade_no=2017081121001003050274536539&total_fee=0.10&trade_status=TRADE_FINISHED&sign_type=RSA&sign=$$$

Remove sign and sign_type, sort other parameters in alphabetical order, and then link up all array values by the character of "&":

buyer_id=208812287878****&currency=HKD&forex_rate=0.85420000&notify_id=e5f5c6a77034fcd111e373e7e61dcbegdy&notify_type=trade_status_sync&notify_time=2017-08-11 17:31:39&out_trade_no=0811172929-1013&rmb_fee=0.09&seller_id=208861122157****&trade_no=2017081121001003050274536539&total_fee=0.10&trade_status=TRADE_FINISHED

Note:

  • Parameters without value don't need to be transmitted, nor to be included in the data to be signed;
  • At signing, the character set used to change the character into byte stream must be consistent with that specified in _input_charset;
  • If the parameter _input_charset is transmitted, it shall also be included in the data to be signed.