支付宝或者微信支付的回调处理

来源:互联网 发布:华科工商管理知乎 编辑:程序博客网 时间:2024/05/03 17:56

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 *)[UIApplicationsharedApplication].delegate;

    if ([url.hostisEqualToString:@"safepay"]) {//支付宝支付

        [[AlipaySDKdefaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {

            int resultSuccess = [[resultDicobjectForKey:kALipaykeyResult]intValue];

            if (delegate.alipayBlock) {

                delegate.alipayBlock(resultSuccess);

            }

        }];

        returnYES;

    }

//    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 [WXApihandleOpenURL:url delegate:self];

    }

    returnNO;

}

3:在你调起支付宝、或者微信的页面做处理

   __weaktypeof(self) weakSelf=self;

    AppDelegate *delegate = (AppDelegate *)[UIApplicationsharedApplication].delegate;

    delegate.alipayBlock=^(int result){

        if (result ==kALipaykeyResultSuccess) {

            [weakSelf oneHttpOrderPayWithPayType:alipayorderID:_s.alipay_orderID];

        }else{

            [weakSelf pushOneOrderDetailWithOrderID:_s.alipay_orderID];

        }

    };

    delegate.wxpayBlock=^(int result){

        if (result ==WXSuccess) {

            [weakSelf oneHttpOrderPayWithPayType:WXPAYorderID:_s.orderID];

        }else{

            [weakSelf pushOneOrderDetailWithOrderID:_s.orderID];

        }

    };


2 0
原创粉丝点击