Integrate the operation module

The mini program operation module mainly includes data monitoring and release management, user interaction (such as message pushing, content delivery), and handling feedback and comments. The operation platform also supports permission management and multi-environment operations, ensuring the smooth flow of development, testing, and launch processes.

To realize the functions that are supported in the operation platform, integrate the operation module by the following steps.

Step 1. Add operation-related dependencies

Add the private source and operation-related dependency to your Podfile file with the following code:

copy
source 'https://globaltech.alipay.com/api/v1/file/common/2017062215370883/minisdk'

target 'YOUR_TARGET' do

  pod 'IAPMiniProgram'
  
  pod 'IAPMiniProgram/Operation'
  
end

Note: Initialization is not required, because the operation-related dependencies are automatically initialized during the initialization of the mini program SDK. You can directly call the corresponding methods within the mini program.

Step 2. Register the network proxy

Take the following code sample as references to register the network proxy.

a. Define GRVNetworkProxy by calling the sendProxyRequest:withCompletion method.

copy
import GriverOperation

class RegionHelper: NSObject, GRVNetworkProxy {
    
    static let shared = RegionHelper()

    func sendRequest(_ requestInfo: GRVProxyRequestInfo, withCompletion completion: @escaping (GRVProxyResponseInfo?) -> Void) {
        
        var request: URLRequest
        let url = "Your backed url"
        
        request = URLRequest(url: url)
        request.httpMethod = "POST"
        
        // construct the request header
        let tenant = "Your walletTenantId"
        let operationType = "Your operationType"
        request.allHTTPHeaderFields = [
            "walletTenantId": tenant.uppercased(),
            "Content-Type": "application/json",
            "appId": "Your appId",
            "workspaceId": "default",
            "operation-type": "Your operationType"
        ]
        
        // construct the request body
        var bodyDict = [String: Any]()
        // obtain the user ID
        let userId = "Your userId"
        bodyDict["customerId"] = userId
        
        // add the proxy request parameters
        bodyDict["proxyRequestHeader"] = requestInfo.proxyRequestHeader
        bodyDict["proxyRequestData"] = requestInfo.proxyRequestData
        
        // dict is packaged to array
        let bodyArray = [bodyDict]
        
        do {
            let bodyData = try JSONSerialization.data(withJSONObject: bodyArray, options: .prettyPrinted)
            request.httpBody = bodyData
        } catch {
            print("JSON serialization failed: \(error)")
            completionHandler(nil)
            return
        }
        
        // send the network request
        URLSession.shared.dataTask(with: request) { data, response, error in
            //  handle the response
            let responseInfo = GRVProxyResponseInfo()
            if let error = error {
                print("Request failed: \(error.localizedDescription)")
                DispatchQueue.main.async {
                    completionHandler(nil)
                }
                return
            }
            
            guard let data = data else {
                DispatchQueue.main.async {
                    completionHandler(nil)
                }
                return
            }
            
            do {
                // parse the json data
                if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
                    responseInfo.proxyResponseHeader = json["proxyResponseHeader"] as? String
                    responseInfo.proxyResponseData = json["proxyResponseData"] as? String
                    responseInfo.isSuccess = !(responseInfo.proxyResponseHeader?.isEmpty ?? true)
                                          && !(responseInfo.proxyResponseData?.isEmpty ?? true)
                }
            } catch {
                print("JSON parsing failed: \(error)")
            }
            
            //  callback
            DispatchQueue.main.async {
                completionHandler(responseInfo)
            }
        }.resume()
    }
}

b. Configure the operationNetworkProxy by using the MiniProgramInitConfig method.

copy
let config = MiniProgramInitConfig()
config.riverConfiguration?.operationNetworkProxy = RegionHelper.shared

Step 3. Call operation-specific APIs per your business requirements.

To implement specific operation-related services/capabilities, call APIs per your business requirements.