Sign the request
Generate pre-sign string
This section describes how to generate the pre-sign string.
- Except for
sign
andsign_type
, all other parameters used need to be signed. - Parameters without a value do not need to be transmitted or included in the data to be signed.
- The charset in the sign must be consistent with the charset used previously.
- If the parameter
_input_charset
is sent, it must also be included in the data to be signed. - According to HTTP protocol, special characters like ampersand (&) and the at sign (@) need to be URL encoded so that the request receiver can get the correct value. In this situation, the pre-sign string should be the original value instead of the encoded value. For example, when calling an API to sign the parameter email, the pre-sign string should be email=test@msn.com, not email=test%40msn.com.
The following is an example of a parameter array:
string[] parameters={
"_input_charset=UTF-8",
"available_day=21",
"confirm_date=2016-11-19 11:19:30",
"country_code=KR",
"departure_point=1028离境口岸",
"doc_expire_date=2016-12-30 12:12:00",
"doc_id=232132324242",
"final_refund_amount=10000",
"final_refund_currency=CNY",
“memo=aa”,
“nationality=CHINA”,
“notify_url=https://www.alipay.com”,
“out_order_no=7662691435324651”,
“partner=2088111956092332”,
“passport_name=HY”,
“passport_no=32342443324232”,
“phone_no=13075381014”,
“refund_amount=220.00”,
“refund_currency=KRW”,
“refund_print_date=2016-11-01 09:00:00”,
“refund_scene_type=02”,
“sales_amount=200.00”,
“sales_currency=KRW”,
“sales_date=2016-10-30 09:00:00”,
“service=alipay.oversea.taxrefund.single.taxdata.send”,
};
To generate the pre-sign string, combine all array values in the key=value format and link them up with the ampersand symbol (&) in an alphabetical order. For example:
_input_charset=UTF-8&available_day=21&confirm_date=2016-11-19 11:19:30&country_code=KR&departure_point=1028离境口岸&doc_expire_date=2016-12-30 12:12:00&doc_id=232132324242&final_refund_amount=10000&final_refund_currency=CNY&memo=aa&nationality=CHINA¬ify_url=https://www.alipay.com&out_order_no=7662691435324651&partner=2088111956092332&passport_name=HY&passport_no=32342443324232&phone_no=13075381014&refund_amount=220.00&refund_currency=KRW&refund_print_date=2016-11-01 09:00:00&refund_scene_type=02&sales_amount=200.00&sales_currency=KRW&sales_date=2016-10-30 09:00:00&service=alipay.oversea.taxrefund.single.taxdata.send×tamp=2016-11-21 12:07:42
Sign the request
MD5 sign type
After the pre-sign string is generated, perform the following steps to generate the signature:
- Append the MD5 secret key to the pre-sign string to generate a new string.
- Calculate the new string with the MD5 signature algorithm. Use the MD5 signature function.
The 32-byte result string is the signature, and is used as the value of the sign
parameter.
RSA2/RSA sign type
After the pre-sign string is generated, perform the following steps to generate the signature:
- Use the RSA/RSA2 algorithm and your private key to generate the signature.
- Encode the signature to a string.
Then, use the string as the value of the sign
parameter.