关于支付的回调处理

此处拿微信支付来举例,支付宝支付同理
添加WXApiDelegate
//不同iOS版本的回调函数不同,但也大同小异,具体不再列举。
- (BOOL)application: (UIApplication * )application openURL: (NSURL * )url sourceApplication: (NSString * )sourceApplication annotation: (id)annotation
if ([WXApi handleOpenURL: url delegate:self]) {
return [WXApi handleOpenURL: url delegate:self];
}
}
只有实现了上述回调才会返回对应的支付结果
-(void) onResp: (BaseResp* )resp
{
NSString *strMsg = [NSString stringWithFormat: @”errcode: %d”, resp.errCode];
NSString *strTitle;

if([resp isKindOfClass: [SendMessageToWXResp class]])
{
    strTitle = [NSString stringWithFormat: @"发送媒体消息结果"];
}
if([resp isKindOfClass: [PayResp class]]){
    //支付返回结果,实际支付结果需要去微信服务器端查询
    strTitle = [NSString stringWithFormat: @"支付结果"];

    switch (resp.errCode) {
        case WXSuccess: {
            strMsg = @"支付结果:成功!";
            NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
            NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object: @"success"];
            [[NSNotificationCenter defaultCenter] postNotification:notification];
            break;
        }
        default: {
            strMsg = [NSString stringWithFormat: @"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
            NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
            NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object: @"fail"];
            [[NSNotificationCenter defaultCenter] postNotification:notification];
            break;
        }
    }
}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值