Alipay+ DocsAlipay+ Docs

Proxy SDK requests

You must proxy all requests from the Alipay+ NFC SDK to the Ant server through your app and server. This guide describes your client-side and server-side responsibilities for proxying these requests.

Workflow

image

The process of proxying the SDK request consists of the following steps:

  1. The Alipay+ NFC SDK sends a request with encapsulated data to the MPP app via the NFCRequestProxy SPI. (Step 1)
  2. The MPP app forwards this request to the MPP server through the login session without modifying the data. (Step 2)
  3. The MPP server checks the login status. (Step 3)
  4. The MPP server adds the customer ID to the request body to form an HTTPS request. (Step 4)
  5. The MPP server forwards this request to the Ant server using the sdkProxy API. (Step 5)
  6. The Ant server processes the request and sends a response back to the MPP server. (Step 6)
  7. The MPP server relays the response to the MPP app and the SDK. (Steps 7-8)

Step 1: Initiate and forward the request

  1. The Alipay+ NFC SDK calls the NFCRequestProxy SPI to send a request with the encapsulated sdkRequestHeader and sdkRequestData to your app.
  2. Your app forwards this request through the login session to your server without modifying the sdkRequestHeader and sdkRequestData.

Processing logic

When using the NFCRequestProxy SPI, take the following into consideration:

  • Ensure the following parameters are configured properly in the request:
    • type: specifies the request type. Valid values are:
      • GET_PK: Public key retrieval interface.
      • APPLY: Card opening request.
      • TRANSFER: Internal SDK notifications. This type is not recommended for MPP to use.
      • SYNC_TOKEN: Token status update request.
      • NOTIFY: Message retrieval request.
    • body: the request body encapsulated within the SDK, which contains sdkRequestHeader and sdkRequestData. Do not modify this parameter.
  • Handle the response properly:
    • enrollmentData: The data returned by the server must be returned to the SDK entirely. If the SDK receives null or no data, it will determine that the request has failed.

For more information about how the MPP app proxies the request from the SDK to the MPP server on an Android device, see the NFCRequestProxy API.

Step 2: Verify and enhance the request

After verifying the login status to ensure secure processing access, your server adds the customerId to the body parameter to construct a secure HTTPS request.

Step 3: Forward and sync responses

  1. Your server calls the sdkProxy API to forward this HTTPS request to the Ant server.
  2. The Ant server processes the request and sends a response back to your server.
  3. Your server synchronizes the response body with your app and the Alipay+ NFC SDK for further action.

Processing logic

When calling the sdkProxy API, take the following into consideration:

  • Configure the request parameters properly:
    • sdkRequestHeader: The header from the original SDK request, passed through your app. Do not modify this data.
    • sdkRequestData: The data from the original SDK request, passed through your app. Do not modify this data.
    • customerId: the unique ID that is assigned by the MPP to identify a customer.
  • Handle the response properly:
    • result: The request processing result, which contains information such as result code, result status, and result message.
    • sdkResponseHeader: The response header from the Ant server. This field is present if result.resultCode is SUCCESS.
    • sdkResponseData: The response data from the Ant server. This field is present if result.resultCode is SUCCESS.

Note: The response data must be returned to the SDK entirely. If the MPP app returns null data or no data is returned, the SDK will determine that the request has failed.

Sample

The following sample shows how the MPP server constructs and sends an HTTPS request by adding the customerId into the MPP client's request body.

Note: This sample code only provides a general implementation on how to add the customerId into the request body, which skips some unrelated steps.

copy
public class NFCProxyHandler {


    /**
     * send request to Ant server when receive the Client App proxy request.
     *
     * @param  body is the generated by PosTap SDK
     * @return the response is the Ant server sdkProxy responseBody
     */
    public String sendRequest(String body) {

        JSONObject jsonObject = JSON.parseObject(body);

        // This step needs to be rewritten according to the actual situation of the MPP; this is just an example.
        String userId = MobileRpcHolder.getLiteSession().get(SessionKey.USER_ID);

        jsonObject.put("customerId", userId);

        String requestBody = JSON.toJSONString(jsonObject);

        // This section skips the steps for MPP to assemble the request header and signing. It is important to note that the body of the request should use the requestBody described above.
        String signValue = genSignValue(httpMethod, path, clientId, reqTime, requestBody);

        // Skip some steps...

        HttpResult rsp = sendHttpRequest(requestUrl, httpMethod, header, requestBody);
        
        if (rsp == null) {
            throw new RuntimeException("HttpResult is null.");
            
        } else {
            int httpRespCode = rsp.getRspCode();
            String rspBody = rsp.getRspBody();
            if (httpRespCode != 200) {
                throw new RuntimeException("Response data error, rspBody:" + rspBody);
            }

            signatureVerification(httpMethod, path, clientId, rspTime, rspBody, rspSignValue);
            
            return rspBody;
        }
    }
}

For more information about the sdkProxy API, see the sdkProxy API.