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

(Optional) Use common Network Proxy

1. Overview

Common network proxy solution allows the wallet client to redirect AC SDK requests to the wallet proxy server instead of sending them directly to the AC backend. By doing so, the wallet can control and monitor the transferred data. When there is compliance or specific business requirements for this, the wallet can implement the common network proxy. The common network proxy only needs the wallet client to implement the sending and receiving of network requests.

1.2 SPI

Name

Description

Direction

Required

sendProxyRequest 

  1. Send the httpProxyRequestInfo  data that complies with OpenAPI specifications to the Super App server. 
  2. After the request is sent successfully, convert the data body of the response to HttpProxyResponseInfo object. Otherwise, if the request fails, null is returned.

Note: 

  • iOS: This is a synchronous SPI.
  • Andriod: This is an asynchronous SPI.

AC SDK --> Super App

M

2. SPI

2.1 sendProxyRequest interface (for Android)

Syntax

copy
/**
 * The Network Proxy interface
 */
public interface NetworkProxy{
    /**
     * 
     *
     * Note: for Android it is a synchronous SPI
     * @param httpProxyRequestInfo    the request, the network proxy information, to be sent by Issuing Participants
     * @return httpProxyResponseInfo  the Issuing Participant needs to convert the data body of the response to HttpProxyResponseInfo object. Otherwise, if the request fails, null is returned.
     * @throws IOException
     */
    @Nullable
    HttpProxyResponseInfo sendProxyRequest(@NonNull HttpProxyRequestInfo httpRequestInfo) throws IOException;
}

Description

Send a httpProxyRequestInfo request that complies with OpenAPI specifications to the server synchronously. After the request is sent successfully, convert the data body of the response to HttpProxyResponseInfo object. Otherwise, if the request fails, null is returned.

Parameter

Name

Android Type

Description

Required

httpProxyRequestInfo 

HttpProxyRequestInfo 

The AC SDK HTTP request information, including the business type, the header, and the data body.

M

Return

Name

Android Type

Description

Required

httpProxyResponseInfo 

HttpProxyResponseInfo 

The response that is returned by the Super App server. If the request fails, null is returned.

M

Android usage

copy
InitConfig initConfig = new InitConfig();
        initConfig.registerNetworkProxy(ProxyScene.PROXY_SCENE_AC, new NetworkProxy() {
            @Override
            public HttpProxyResponseInfo sendHttpRequest(HttpProxyRequestInfo httpProxyRequestInfo) {
                //this is a sample code for how to use proxy network
                HttpURLConnection connection = null;
                URL url = null;
                try {
                    url = new URL("hostUrl");
                    connection = (HttpURLConnection) url.openConnection();
                    if (connection.getResponseCode() == 200) {//if http request success,then we fetch body from response,and assemble a httpProxyResponseInfo
                        HttpProxyResponseInfo httpProxyResponseInfo = new HttpProxyResponseInfo();
                        httpProxyRequestInfo.setxxx();   //the setxxx function is to configure fields/properties of the request data body
                        return httpProxyResponseInfo;
                    } else {
                        return null;    //if http request fails, return null.
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }
                return null;
            }
        });

3. Appendix

3.1 Data model for Android

Public class HttpProxyRequestInfo (for Android)

Item

Type

Description

Required

scene 

ProxyScene

The business scenario of an AC SDK HTTP request

M

httpProxyRequestHeader 

String

The header of the AC SDK HTTP request 

M

httpProxyRequestData 

String

The data body of the AC SDK HTTP request 

M

Public class HttpProxyResponseInfo (for Android)

Item

Type

Description

Required

isSuccess 

Boolean

The result status returned from Alipay+:

  • true: indicates the request is sent successfully.
  • false: indicates the request fails.

M

errorCode 

String

The error code returned from Alipay+

M

errorMessage 

String

The error message returned from Alipay+

httpProxyResponseHeader 

String

The header information returned from Alipay+

M

httpProxyResponseData 

String

The data body returned from Alipay+

M

Public enum ProxyScene (for Android)

Item

Description

PROXY_SCENE_MINIPROGRAM 

Indicates a specific business scenario (mini program scenario) of a network request proxy.

When a request needs to access only the Alipay+ region server, it is transferred to the designated network proxy that is registered by this scenario.

PROXY_SCENE_PAY 

Indicates a specific business scenario (payment scenario) of a network request proxy.

If a network proxy is registered under this scenario, the request in the original SDK, which directly accesses the Alipay server, is transferred to this network proxy.