1、配置工程
為保證客戶端能成功請(qǐng)求到服務(wù)端,需在客戶端配置網(wǎng)關(guān)地址;同時(shí)為防止客戶端請(qǐng)求被篡改和偽造,還需對(duì)請(qǐng)求數(shù)據(jù)進(jìn)行加簽。
2、配置網(wǎng)關(guān)
需要客戶端在?

?的 category 中重寫以下的接口方法,指定 RPC 的網(wǎng)關(guān)地址;

3、配置秘鑰
RPC 請(qǐng)求有簽名機(jī)制,客戶端使用的簽名密鑰保存在無(wú)線保鏢圖片中,需要通過(guò)在?DTRpcInterface?的 category 中重寫下面的接口方法,指定給 RPC 加密的密鑰名稱。

??使用 Xcode 插件添加 RPC 模塊后,會(huì)自動(dòng)從工程元數(shù)據(jù)中讀取網(wǎng)關(guān)地址和加簽信息,設(shè)置到當(dāng)前工程中,無(wú)需修改。
4、全局配置
RPC 在使用之前需要全局配置 V2,在第一個(gè) RPC 發(fā)起之前調(diào)用下面的代碼即可。

5、生成 RPC 代碼
當(dāng) App 在移動(dòng)網(wǎng)關(guān)控制臺(tái)接入后臺(tái)服務(wù)后,即可下載客戶端的 RPC 代碼

6、發(fā)送請(qǐng)求
將下載好的代碼拽到工程中,RPC 請(qǐng)求必須在子線程調(diào)用,可使用 RPC 模塊中,?DTRpcAsyncCaller?封裝的子線程調(diào)用接口,回調(diào)方法默認(rèn)為主線程。代碼示例如下
- (void)sendRpc
{
__block RPCDemoLoginResult *result =nil;
? ? [DTRpcAsyncCaller callAsyncBlock:^{
@try
? ? ? ? {
? ? ? ? ? ? RPCDemoLoginRequest *req = [[RPCDemoLoginRequest alloc] init];
req.loginId =@"alipayAdmin";
req.loginPassword =@"123456";
? ? ? ? ? ? RPCDemoAuthLoginPostReq *loginPostReq = [[RPCDemoAuthLoginPostReq alloc] init];
? ? ? ? ? ? loginPostReq._requestBody = req;
? ? ? ? ? ? RPCDemoCloudpay_accountClient *service = [[RPCDemoCloudpay_accountClient alloc] init];
? ? ? ? ? ? result = [service authLoginPost:loginPostReq];
? ? ? ? }
@catch(NSException*exception) {
NSLog(@"%@", exception);
? ? ? ? }
? ? } completion:^{
NSString*str =@"";
if(result && result.success) {
str =@"登錄成功";
}else{
str =@"登錄失敗";
? ? ? ? }
UIAlertView*alert = [[UIAlertViewalloc] initWithTitle:str message:nildelegate:nil
cancelButtonTitle:nilotherButtonTitles:@"ok",nil];
? ? ? ? [alert show];
? ? }];
}