(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 |
Note:
| AC SDK --> Super App | M |
2. SPI
2.1 sendProxyRequest
interface (for iOS)
Syntax
@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 | 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 | M |
Callback
Name | iOS Type | Description | Required |
responseInfo | The response that is returned by the Super App server. If the request fails, | M |
iOS usage
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 | 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+:
| 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. |