自学内容网 自学内容网

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(@"跳转成功");
    }];
    
}


原文地址:https://blog.csdn.net/u010742414/article/details/131913130

免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!