支付宝或者微信支付的回调处理
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];
}
};
#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];
}
};
相关文章推荐
- Lua中让回调函数支持回调对象方法的解决方法
- 浅谈使用PHP开发微信支付的流程
- 我的Node.js学习之路(三)--node.js作用、回调、同步和异步代码 以及事件循环
- 微信支付如何实现内置浏览器的H5页面支付
- 谈谈JavaScript自定义回调函数
- C语言模块回调Lua函数的两种方法
- C++基础入门教程(九):函数指针之回调
- C#的回调机制浅析
- Thinkphp和onethink实现微信支付插件
- php开发微信支付获取用户地址
- Asp.net回调技术Callback学习笔记
- java实现微信支付(服务端)
- 浅析PHP微信支付通知的处理方式
- ASP.NET中如何实现回调
- javascript实现网页子页面遍历回调的方法(涉及 window.frames、递归函数、函数上下文)
- 剖析Node.js异步编程中的回调与代码设计模式
- 深入浅析NodeJs并发异步的回调处理
- PHP开发微信支付的代码分享
- 微信公众号支付(二)实现统一下单接口
- 微信支付PHP SDK之微信公众号支付代码详解