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

      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.

      Note:
      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. 


        copy
        //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=" + "\"http://notify.msp.hk/notify.htm\"";
                orderInfo += "&service=\"mobile.securitypay.pay\"";
                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=\"http://notify.msp.hk/return.htm\"";
                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:https://global.alipay.com/service

      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:

      _input_charset="utf-8"&body="test"&currency="HKD"&forex_biz="FP"&it_b_pay="30m"&notify_url="http://notify.msp.hk/notify.htm"&out_trade_no="012215363975791"&partner="208862xxxx533516"&payment_inst="ALIPAYHK"&payment_type="1"&product_code="NEW_WAP_OVERSEAS_SELLER"&return_url="http://notify.msp.hk/return.htm"&secondary_merchant_id="A80001"&secondary_merchant_industry="7011"&secondary_merchant_name="Muku"&service="mobile.securitypay.pay"&subject="test123"&total_fee="0.1"

      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