zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

iOS开发之微信支付

ios开发 支付
2023-09-14 08:57:56 时间
不得不吐槽,微信支付的SDK,这里连个代理都没有,所以,你想获取支付后的结果的返回信息,需要去AppDelegate里,添加如下代码,添加微信的代理:

(BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 

return [WXApi handleOpenURL:url delegate:self]; 
然后,再实现这个方法:

-(void) onResp:(BaseResp*)resp 

通过这个方法,你就可以获取微信支付后的信息了。但是如果这样,所有的支付代码都在AppDelegate里,不好,至少微信给的例子就是这样。我的方法是添加通知,代码如下:

-(void) onResp:(BaseResp*)resp 

if ([resp isKindOfClass:[PayResp class]]) 

PayResp response = (PayResp )resp;

// NSString *strTitle = [NSString stringWithFormat:@”支付结果”]; 
// NSString *strMsg = [NSString stringWithFormat:@”errcode:%d”, response.errCode]; 
// 
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle 
// message:strMsg 
// delegate:self 
// cancelButtonTitle:@”OK” 
// otherButtonTitles:nil, nil]; 
// [alert show];

 switch (response.errCode) {

 case WXSuccess: {

 NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object:@"success"];

 [[NSNotificationCenter defaultCenter] postNotification:notification];

 break;

 default: {

 NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object:@"fail"];

 [[NSNotificationCenter defaultCenter] postNotification:notification];

 break;

}

然后,在支付那个VC,添加通知

pragma mark - tabBar隐藏 (void)viewWillAppear:(BOOL)animated { 
[super viewWillAppear:animated]; 
if([WXApi isWXAppInstalled]) // 判断 用户是否安装微信 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getOrderPayResult:) name:ORDER_PAY_NOTIFICATION object:nil];//监听一个通知 

pragma mark - tabbar还原 (void)viewWillDisappear:(BOOL)animated 

[super viewWillDisappear:animated]; 
[[NSNotificationCenter defaultCenter
iOS 微信支付开发流程 项目中要用到支付功能,需要支付宝支付、支付宝网页支付转客户端、微信支付、银联支付、Apple_pay,所以打算总结一下,方便以后的查阅,也方便大家, 用到的地方避免再次被坑。 今天我们就主要介绍一下微信支付,其他支付也写了对应教程,并且给出了连接。
ios授权登录sdk分享(不包含支付功能)   为了解决开发者在ios中使用支付宝授权接口产品上架问题,所以推出授权登录相关sdk(不包含支付功能) 如果商户有使用到支付宝登录授权功能接口,可以参考使用。 ios SDK:AFAuthSDK.