美文网首页iOS Developer
iOS-微信,支付宝支付回调跳转页面

iOS-微信,支付宝支付回调跳转页面

作者: DreamMmMmM | 来源:发表于2016-12-20 16:06 被阅读511次

    一、支付宝
    支付宝自带的有支付回调的block
    在AppDelegate.h里面
    9.0新的

    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
    {
    if ([url.host isEqualToString:@"safepay"]) {
            //跳转支付宝钱包进行支付,处理支付结果
          [[AlipaySDK  defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
     if ([statusStr isEqualToString:@"9000"]) {
                NSLog(@"支付成功");
           //发送对应的通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"successPay" object:nil];
    
            } else if ([statusStr isEqualToString:@"8000"]) {
                NSLog(@"正在处理中");
                /
            } else if ([statusStr isEqualToString:@"6001"]) {
              
                NSLog(@"用户中途取消支付");
            } else if ([statusStr isEqualToString:@"6002"]) {
                NSLog(@"网络故障支付失败");
            } else if ([statusStr isEqualToString:@"4000"]) {
                NSLog(@"支付失败");
           
            }
     }
    

    在支付页面注册通知,跳转对应页面

    -(void)registerNotification
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(successPay) name:@"successPay" object:nil];
        
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(failePay) name:@"failePay" object:nil];
    }
    
    
    -(void)successPay
    {
        //成功支付
       //也可以从服务端获取结果后在跳转(后台给的API查询支付结果)
        PaySuccessViewController *success = [[PaySuccessViewController alloc]init];
        [self.navigationController pushViewController:success animated:YES];
    }
    

    二、微信
    微信差不多

    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
    {
    
     return [WXApi handleOpenURL:url delegate:self];
    }
    

    //微信回调,微信给的接口

    -(void)onResp:(BaseResp*)resp
    {
        PayResp*response=(PayResp*)resp;
        switch(response.errCode)
        {
            case WXSuccess:
                //服务器端查询支付通知或查询API返回的结果再提示成功
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"successPay" object:nil];
                NSLog(@"支付成功");
                break;
            case WXErrCodeUserCancel:
                //服务器端查询支付通知或查询API返回的结果再提示成功
                [[NSNotificationCenter defaultCenter] postNotificationName:@"failePay" object:nil];
                NSLog(@"用户取消支付");
                break;
            default:
                [[NSNotificationCenter defaultCenter] postNotificationName:@"failePay" object:nil];
                NSLog(@"支付失败,retcode=%d",resp.errCode);
                break;
        }
    

    相关文章

      网友评论

        本文标题:iOS-微信,支付宝支付回调跳转页面

        本文链接:https://www.haomeiwen.com/subject/xfffvttx.html