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

Signing the Request

To send a request to call an AlipayHK API, you must sign the request parameters to create a request URL.

Sign the request

1、Package the following request parameters: protocol parameters, required parameters, and optional parameters.

You can use only parameters defined by AlipayHK, no other parameters allowed.Take Java as an example, you can use the following code to package the parameters. 

    //package the request parameters
        private static String getOrderInfo(String partner, String sellerId, boolean isHK) {
            String orderInfo = "partner=" + "\"" + partner + "\"";
            orderInfo += "&seller_id=" + "\"" + sellerId + "\"";
            orderInfo += "&out_trade_no=" + "\"" + getOutTradeNo() + "\"";
            orderInfo += "&subject=" + "\"alipay testing\"";
            orderInfo += "&body=" + "\"test\"";
            orderInfo += "&total_fee=" + "\"0.01\"";
            orderInfo += "&notify_url=" + "\"\"";
            orderInfo += "&service=\"\"";
            orderInfo += "&payment_type=\"1\"";
            orderInfo += "&_input_charset=\"utf-8\"";
            //orderInfo += "&it_b_pay=\"2019-02-26 21:04:42\"";
            orderInfo += "&it_b_pay=\"30m\"";
            // After the request being processed by Alipay, the page is directed to the merchant specified URL, which is optional.
            orderInfo += "&return_url=\"\"";
            if (isHK) {
                // identify the Alipay wallet type, optional.
                orderInfo += "&payment_inst=\"ALIPAYHK\"";
            orderInfo += "&currency=\"HKD\"";
            // identify the product type, can be set only to NEW_WAP_OVERSEAS_SELLER
            orderInfo += "&product_code=\"NEW_WAP_OVERSEAS_SELLER\"";
            orderInfo += "&forex_biz=\"FP\"";
            orderInfo += "&secondary_merchant_id=\"A80001\"";
            orderInfo += "&secondary_merchant_name=\"Muku\"";
            orderInfo += "&secondary_merchant_industry=\"7011\"";
            return orderInfo;
        //To add other parameters,please refer to development documents.Document address:

2、Sort the packaged parameters and generate a pre-sign string.

Combine all array values in the format of key = value, link the combinations with the character of &, and sort in an order of A to Z. You can sort the parameters by using the corresponding function provided in demo code. For example, a string with sorted parameters for the RSA sign type is as below:


3、Get the value of the sign parameter.

RSA sign type (SHA1, SHA256)
If sign_type = RSA, run the RSA signature function with the pre-sign string you get in Step 2 to get the value of sign. An example for the Base64 encoded sign:
sign= K1RrdUXEjV33olDRU3ws9m6M1jFWlmU%2BDwNCG986a6OZOdWVNnLf3MHViLgpL4W39EZnQ989D0zdTP9ScTODMXNYBLjAPec6mswLe8kyV68ODiaCxyI1jx1jsZ9FG1TFQXCxjeI%2Bsb8XoYXhwst3ZJBiSlqqlt8Jwx49Wd4uS%2BU%3D