支付宝支付结果数据处理

{
memo = "";
result = "{"alipay_trade_app_pay_response":{"code":"10000","msg":"Success","app_id":"2017010204801650","auth_app_id":"2017010204801650","charset":"UTF-8","timestamp":"2017-03-13 10:46:15","total_amount":"0.01","trade_no":"2017031321001004770271758127","seller_id":"2088021865511731","out_trade_no":"148936861523774_1489373148"},"sign":"BvEdx13G3DPx22bmszP+CfWLw0OTDX4QRVcyOFlXRDLo3DzULWJ8GGSjb9izYWuS1Oexaqvi8ixnDAVQYTOKuYvPwvPOeFyjSHlOYsMxsQjsCi83aKM4aDQl+b8T1/M4CQoL3z2TcTgglD4kPfP5aal0NmnGIPtPYqULHUjOSeQ=","sign_type":"RSA"}";
resultStatus = 9000;
}

以上是支付宝支付成功返回来的结果, result字段对应的不是一个字典,接收的时候要用字符串接收,我的处理思路如下:
1.先把result对应的字符串取出来
2.把该字符串转为json,进行相关操作

    // NOTE: 调用支付结果开始支付
         [[AlipaySDK defaultService] payOrder:orderString fromScheme:@"YiNuanTong" callback:^(NSDictionary *resultDic) {
             
             NSLog(@"支付页面reslut = %@",resultDic);
             
       
            // 提取支付结果字符串
             NSDictionary *returnDic =  [self stringToJson:resultDic[@"result"]];
         
          NSDictionary *dataDic = returnDic[@"alipay_trade_app_pay_response"];
             
          
             NSLog(@"支付码:%@",dataDic[@"code"]);
              NSLog(@"支付结果:%@",dataDic[@"msg"]);
              NSLog(@"支付appid:%@",dataDic[@"app_id"]);
              NSLog(@"支付授权auth_app_id:%@",dataDic[@"auth_app_id"]);
              NSLog(@"支付时间:%@",dataDic[@"timestamp"]);
              NSLog(@"支付费用:%@",dataDic[@"total_amount"]);
              NSLog(@"支付交易码trade_no:%@",dataDic[@"trade_no"]);
              NSLog(@"支付编号:%@",dataDic[@"out_trade_no"]);
              NSLog(@"支付seller_id:%@",dataDic[@"seller_id"]);
         }];

#pragma mark - 处理支付宝支付结果  (字符串转json)
- (NSDictionary *)stringToJson:(NSString *)str
{
  
    NSString *requestTmp = [NSString stringWithString: str];
    
    NSData *resData = [[NSData alloc] initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
    return resultDic;
    }

你可能感兴趣的:(支付宝支付结果数据处理)