天天看點

支付寶或者微信支付的回調處理

1:

#import <UIKit/UIKit.h>

#import <BaiduMapAPI_Base/BMKBaseComponent.h>

typedef void(^alipayResultBlock)(int result);

typedef void(^wxpayResultBlock)(int result);

@interface AppDelegate : UIResponder <UIApplicationDelegate>

{

    BMKMapManager* _mapManager;

}

@property (nonatomic,copy) void (^wxloginCompleteBlock)(id);

@property (strong, nonatomic) UIWindow *window;

@property (nonatomic,copy) alipayResultBlock alipayBlock;

@property (nonatomic,copy) wxpayResultBlock  wxpayBlock;

@end

2:

// NOTE: 9.0以後使用新API接口

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{

//    UZGPersonalSetting *s=[UZGPersonalSetting getInstance];

//    NSLog(@"url.host:%@",url.host);

    //url.host:safepay,支付寶用戶端

    //url.host:pay,微信用戶端

    //url.host:platformId=wechat,//微信分享和微信取消登入

    //url.host:oauth//微信登入成功

     AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    if ([url.host isEqualToString:@"safepay"]) {//支付寶支付

        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

            int resultSuccess = [[resultDic objectForKey:kALipaykeyResult] intValue];

            if (delegate.alipayBlock) {

                delegate.alipayBlock(resultSuccess);

            }

        }];

        return YES;

    }

//    else if ([url.host isEqualToString:@"pay"]){//微信支付

//        [WXApi handleOpenURL:url delegate:self];

//    }

//    else if([s.payType isEqualToString:@"wxpay"]){//微信支付

//        return [WXApi handleOpenURL:url delegate:self];

//    }else if ([s.payType isEqualToString:@"wxLogin"]){

//        return [WXApi handleOpenURL:url delegate:self];

//    }

    else {

        return [WXApi handleOpenURL:url delegate:self];

    }

    return NO;

}

3:在你調起支付寶、或者微信的頁面做處理

   __weak typeof(self) weakSelf=self;

    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    delegate.alipayBlock=^(int result){

        if (result == kALipaykeyResultSuccess) {

            [weakSelf oneHttpOrderPayWithPayType:alipay orderID:_s.alipay_orderID];

        }else{

            [weakSelf pushOneOrderDetailWithOrderID:_s.alipay_orderID];

        }

    };

    delegate.wxpayBlock=^(int result){

        if (result == WXSuccess) {

            [weakSelf oneHttpOrderPayWithPayType:WXPAY orderID:_s.orderID];

        }else{

            [weakSelf pushOneOrderDetailWithOrderID:_s.orderID];

        }

    };

繼續閱讀