此處拿微信支付來舉例,支付寶支付同理 添加WXApiDelegate //不同iOS版本的回調函數不同,但也大同小異,具體不再列舉。 - (BOOL)application: (UIApplication * )application openURL: (NSURL * )url sourceApplication: (NSString * )sourceApplication annotation: (id)annotation if ([WXApi handleOpenURL: url delegate:self]) { return [WXApi handleOpenURL: url delegate:self]; } } 只有實現了上述回調才會返回對應的支付結果 -(void) onResp: (BaseResp* )resp { NSString *strMsg = [NSString stringWithFormat: @”errcode: %d”, resp.errCode]; NSString *strTitle;
if([resp isKindOfClass: [SendMessageToWXResp class]]){ strTitle = [NSString stringWithFormat: @"發送媒體消息結果"];}if([resp isKindOfClass: [PayResp class]]){ //支付返回結果,實際支付結果需要去微信服務器端查詢 strTitle = [NSString stringWithFormat: @"支付結果"]; switch (resp.errCode) { case WXSuccess: { strMsg = @"支付結果:成功!"; NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode); NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object: @"success"]; [[NSNotificationCenter defaultCenter] postNotification:notification]; break; } default: { strMsg = [NSString stringWithFormat: @"支付結果:失敗!retcode = %d, retstr = %@", resp.errCode,resp.errStr]; NSLog(@"錯誤,retcode = %d, retstr = %@", resp.errCode,resp.errStr); NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object: @"fail"]; [[NSNotificationCenter defaultCenter] postNotification:notification]; break; } }}}
新聞熱點
疑難解答