微信支付回调

1.在AppDelegate中设置微信代理

@interface AppDelegate ()<WXApiDelegate>

2.在openUrl中判断返回url   并设置代理

- (BOOL)application:(UIApplication *)application

            openURL:(NSURL *)url

  sourceApplication:(NSString *)sourceApplication

        annotation:(id)annotation{

([[url scheme] isEqualToString:@"wx711e29e7c52bb3d9"]) {

        if ([url.host isEqualToString:@"pay"]) {

  [WXApi handleOpenURL:url delegate:self];

        }

}

3,调用代理方法

- (void)onResp:(BaseResp *)resp {
    if ([resp isKindOfClass:[PayResp class]]) {
        PayResp *response = (PayResp *)resp;
        if (response.errCode == WXSuccess) {
              NSLog(@"支付成功");
      
        }else{
           
            NSString *string = @"支付成功";
            [[NSNotificationCenter defaultCenter] postNotificationName:@"wxResult" object:string];
           
              NSLog(@"支付失败, retcode=%d",resp.errCode);
        }
    }
}
原文地址:https://www.cnblogs.com/gaojingxuan/p/4942793.html