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 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
currency------------------USD
out_trade_no--------------out_trade_no_20200109_175140
partner-------------------2088021017666931
product_code--------------NEW_OVERSEAS_SELLER
service-------------------create_forex_trade
subject-------------------Mika's coffee shop
timeout_rule--------------12h

Combine all array values in the format of "key=value" (without quotation marks) and then link them up with the ampersand symbol (&) in an alphabetical order. For example:

_input_charset=UTF-8&currency=USD&out_trade_no=out_trade_no_20200109_175140&partner=2088021017666931&product_code=NEW_OVERSEAS_SELLER&service=create_forex_trade&subject=Mika's coffee shop&timeout_rule=12h&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.