支付宝

前言:关于支付宝的集成就看蚂蚁金服的集成步骤走就好了。这里只提一下其他问题。

  1. 唤起支付宝
  2. 支付宝支付成功后无法返回app
  3. 支付成功后回调

--------------------------------V----------------------------------
mark
->服务端‘配置’完成后给的数据格式

"partner=\"2088901199988772\"&seller_id=\"2088901199988772\"&out_trade_no=\"ali_2018052217132700062\"&subject=\"\U96ea\U8304\U5ba2\U6808-\U79ef\U5206\U5145\U503c\"&body=\"\U96ea\U8304\U5ba2\U6808-\U79ef\U5206\U5145\U503c\"&total_fee=\"0.1\"&notify_url=\"https://cigartest.iusung.com/Pay/AlipayNotify\"&service=\"mobile.securitypay.pay\"&payment_type=\"1\"&_input_charset=\"utf-8\"&it_b_pay=\"30m\"&show_url=\"m.alipay.com\"&sign=\"dO3KD%2fOC7C5HYl9K5zySWgpnRsE3Ene1mN4MbOGiC6BMcSg8V4htij3vqLAvTEVOhYMvvl0OaNkJwwsRTYgXU60jKAeZXeX%2b%2b8tO%2fi5yijazq2%2fyysj90Bnxk1fDGlx0%2b%2fqAMdyLjD3p%2bV6rLtJ4uHkveSVQQwL6t7fcjkGapbg%3d\"&sign_type=\"RSA\""

// 就是下面的orderString

-> objectName即你的工程名称

  1. 唤起支付宝
[[AlipaySDK defaultService] payOrder:orderString fromScheme:@"objectName" callback:^(NSDictionary *resultDic) {
        
}];
  1. 支付宝支付成功后无法返回app,需要设置如下图:


    0022xwlygy6Me0sOY9re9.jpeg
  2. 支付成功后回调

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    // 微信支付回调
    [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
    //支付宝回调
    if ([url.host isEqualToString:@"safepay"]) {
        //跳转支付宝钱包进行支付,处理支付结果
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
            NSLog(@"result1 = %@",resultDic);
            [self zhifubaoIsPay_status:resultDic[@"resultStatus"]];
        }];
    }
    return YES;
}
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
    // 微信支付回调
    [WXApi handleOpenURL:url delegate:self];
    //支付宝回调
    if ([url.host isEqualToString:@"safepay"]) {
        //跳转支付宝钱包进行支付,处理支付结果
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
            NSLog(@"result2 = %@",resultDic);
            [self zhifubaoIsPay_status:resultDic[@"resultStatus"]];
        }];
    }
    return YES;
}

#pragma mark -- 处理支付宝支付回调结果
-(void)zhifubaoIsPay_status:(NSString *)status
{
    NSInteger code = [status integerValue];
    NSString *msg = @"支付失败";
    switch (code) {
        case 9000:
        {
            msg = @"支付成功";
            [[NSNotificationCenter defaultCenter] postNotificationName:ZFBPaySuccess object:nil];
        }break;
        case 8000: msg = @"正在支付中"; break;
        case 4000: msg = @"支付失败"; break;
        case 5000: msg = @"重复请求"; break;
        case 6001: msg = @"中途取消"; break;
        case 6002: msg = @"网络错误"; break;
        default:break;
    }
    [MBProgressHUD showAutoMessage:msg];
}

推荐阅读更多精彩内容