iOS-支付相关

支付宝支付

#import <AlipaySDK/AlipaySDK.h>

 


//orderStrAliPay为服务端传的订单信息
//fromScheme为应用配置的schemeUrl标识,用户支付包支付成功后跳转会本应用内
//callback回调需要在- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url 中调用 Alipay.defaultService().processPayResultFromAlipayclient(withOrder: url),后才能收到支付回调

-(void)aliPayAction{
    
    if (tc_isEmptyString(self.orderStrAliPay) ) {
        [MBProgressHUD showMessage:@"订单异常"];
        return;
    }
    [[Alipay defaultService] payOrder:self.orderStrAliPay fromScheme:@"alipayruyistore" callback:^(NSDictionary * _Nonnull resultDic) {
        if ([resultDic[@"resultStatus"] integerValue] == 9000) {
            if (self.CompletionBlock) {
                self.CompletionBlock(@{@"payChannel":@"alipay"},YES);
            }
            [self.navigationController popViewControllerAnimated:YES];
           
        }else{
            NSString* memo = resultDic[@"memo"];
            if (tc_isEmptyString(memo)) {
                memo = @"支付失败";
            }
            MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            hud.mode = MBProgressHUDModeText;
            hud.detailsLabelFont = [UIFont boldSystemFontOfSize: 16.0f];
            hud.detailsLabelText= memo;
            hud.removeFromSuperViewOnHide = YES;
            [hud hide:YES afterDelay:2.0];
        }
        
    }];
    

}

微信小程序支付

#import "WXApiManager.h"
//回到前台后需要轮询取出支付结果
-(void)wxPayAction{
    if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]) {
        NSMutableString* strQuery  = [NSMutableString string];
        NSDictionary* orderDict = self.dictOrder[@"order"] ;
        if (orderDict) {
            for (NSString* key in [orderDict allKeys]) {
                NSString* strContent =  orderDict[key];
                [strQuery appendString:[NSString stringWithFormat:@"%@=%@&",key,strContent]];
            }
        }
        if (strQuery.length != 0) {
            [strQuery deleteCharactersInRange:NSMakeRange(strQuery.length-1, 1)];
        }
        
        NSString* envVersion = @"release";
        if ([AppUtilBridge getEnvironment] != MMCTaobaoEnvironmentOnline) {
            envVersion = @"trial";
        }
        NSString* url = [NSString stringWithFormat:@"weixin://dl/business/?appid=%@&path=%@&query=%@&env_version=%@",APPPID,PATH,strQuery.wvStringByURLEncoded,envVersion];
        [AppUtilBridge routerOpenWithUrl:url];
        
        [self.navigationController popViewControllerAnimated:YES];
        if (self.CompletionBlock) {
            self.CompletionBlock(@{@"payChannel":@"wechat"},YES);
        }
    }
}
-(void)toWechatMiniProgram:(NSString *)appid ghId:(NSString *)username path:(NSString *)path type:(NSString *)miniProgramtype{
    
    NSString *mPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
    
    NSString *url = [NSString stringWithFormat:@"weixin://app/%@/jumpWxa/?userName=%@&path=%@&miniProgramType=%@&extMsg=",appid,username,mPath,miniProgramtype];
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]options:@{} completionHandler:^(BOOL success) {
        NSLog(@"跳转成功");
    }];
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值