您的位置:首页 > 移动开发 > 微信开发

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

2016-05-26 17:46 721 查看
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];

        }

    };
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息