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 iOS)

Syntax

copy

@protocol IAPNetworkProxy <NSObject>
- (void)sendProxyRequest:(IAPProxyRequestInfo *)requestInfo 
   withCompletionHandler:(void(^)(IAPProxyResponseInfo *responseInfo))completionHandler;
@end

Description

To send a requestInfo request and receive a responseInfo response asynchronously for iOS AC SDK.

Parameters

Name

iOS Type

Description

Required

requestInfo 

IAPProxyRequestInfo

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

M

completionHandler 

Block  

An asynchronous callback. After a network request finishes, the completionHandler sends the response back to the AC SDK.

M

Callback

Name

iOS Type

Description

Required

responseInfo 

IAPProxyResponseInfo

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

M

iOS usage

copy

IAPConnectInitConfig *config = [IAPConnectInitConfig new];
config.envType = kIAPACDev;
[config registerNetworkProxy:PSPHttpRequestRegionProxy.new forScene:IAPProxySceneMiniProgram];
[IAPConnect initWithContext:config];

@interface PSPHttpRequestRegionProxy: NSObject <IAPNetworkProxy>
- (void)sendProxyRequest:(IAPProxyRequestInfo *)requestInfo 
   withCompletionHandler:(void(^)(IAPProxyResponseInfo *responseInfo))completionHandler;
@end

@implementation PSPHttpRequestRegionProxy
- (void)sendProxyRequest:(IAPProxyRequestInfo *)requestInfo 
   withCompletionHandler:(void(^)(IAPProxyResponseInfo *responseInfo))completionHandler
{
    NSString *proxyRequestHeader = requestInfo.proxyRequestHeader;
    NSString *proxyRequestData = requestInfo.proxyRequestData;
    // proxyRequestHeader、proxyRequestData as request parameters of Server;
    // PSP initiates and send a network request;
    // Obtain the response, error, data;
    if (error) {
        completionHandler(nil);
    } else {
        // NSDictionary *json = data.toJson;      // convert to JSON
        IAPProxyResponseInfo *responseInfo = IAPProxyResponseInfo.new;
        responseInfo.isSuccess = [json["resultCode"] isEqualToString:@"SUCCESS"]; // example
        if (!responseInfo.isSuccess) {
            responseInfo.errorCode = json["resultCode"];  // example
        } else {
            responseInfo.proxyResponseHeader = json[@"proxyResponseHeader"];    //example
            responseInfo.proxyResponseData = json[@"proxyResponseData"];        //example
        }
        completionHandler(responseInfo);
    }
}
@end

3. Appendix

3.1 Data model for iOS

Public class IAPProxyRequestInfo (for iOS)

Item

Type

Description

Required

scene

IAPProxyScene

The business scenario of an AC SDK HTTP request

M

proxyRequestHeader

String

The header of the AC SDK HTTP request 

M

proxyRequestData

String

The data body of the AC SDK HTTP request 

M

Public class IAPProxyResponseInfo (for iOS)

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+.

O

errorMessage 

String

The error message returned from Alipay+.

O

proxyResponseHeader 

String

The header information returned from Alipay+.

M

proxyResponseData 

String

The data body returned from Alipay+.

M

Public enum IAPProxyScene (for iOS)

Item

Description

IAPProxySceneMiniProgram 

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.

IAPProxyScenePay 

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.