// // QXNobilityBuyViewController.m // QXLive // // Created by 启星 on 2025/11/7. // #import "QXNobilityBuyViewController.h" #import "QXNobilityBuyDesCell.h" #import "QXRechargePayTypeTableCell.h" #import "QXNobilityPriceView.h" #import "QXMineNetwork.h" #import "QXBuyNobilitySuccessViewController.h" #import #import @interface QXNobilityBuyViewController () @property (nonatomic,strong)UITableView *tableView; @property (nonatomic,strong)QXNobilityGetPriceModel *model; @property (nonatomic,strong)NSMutableArray* payTypeArray; @property (nonatomic,strong)QXNobilityPriceView *priceView; @property (nonatomic,strong)UIView *footerView; @property (nonatomic,strong)UIView *tableFooterView; @property (nonatomic,assign)BOOL isSelectedAgreement; @property (nonatomic,strong)QXPayTypeModel* selectedPayTypeModel; @end @implementation QXNobilityBuyViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } -(void)setNavgationItems{ [super setNavgationItems]; self.navigationItem.title = @"支付"; } - (void)initSubViews{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paySuccess) name:noticeAlipayResult object:nil]; self.tableView.tableHeaderView = self.priceView; self.tableView.tableFooterView = self.tableFooterView; [self.view addSubview:self.tableView]; [self getRechargeList]; } -(void)setNobility_id:(NSString *)nobility_id{ _nobility_id = nobility_id; MJWeakSelf [QXMineNetwork getNobilityPriceWithId:nobility_id successBlock:^(QXNobilityGetPriceModel * _Nonnull model) { weakSelf.model = model; weakSelf.priceView.model = model; [weakSelf.tableView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }); }]; } -(void)getRechargeList{ MJWeakSelf [QXMineNetwork walletPayTypeWithUserId:QXGlobal.shareGlobal.loginModel.user_id successBlock:^(QXPayTypeStatusModel * _Nonnull model) { [weakSelf.payTypeArray removeAllObjects]; if (model.wx.is_pay_open.intValue == 1) { [weakSelf.payTypeArray addObject:model.wx]; } if (model.ali.is_pay_open.intValue == 1) { [weakSelf.payTypeArray addObject:model.ali]; } if (model.wx_tl.is_pay_open.intValue == 1) { [weakSelf.payTypeArray addObject:model.wx_tl]; } if (model.ali_tl.is_pay_open.intValue == 1) { [weakSelf.payTypeArray addObject:model.ali_tl]; } [weakSelf.tableView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)payAction{ if (!self.isSelectedAgreement) { showToast(@"请先阅读并同意爵位用户协议"); return; } if (self.selectedPayTypeModel == nil) { showToast(@"请选择支付方式"); return; } @weakify(self) [QXMineNetwork rechargePayWithMoney:self.model.price coin:@"" type:self.selectedPayTypeModel.type userId:QXGlobal.shareGlobal.loginModel.user_id typeId:@"" nobility_id:self.nobility_id successBlock:^(NSDictionary * _Nonnull dict) { @strongify(self) if (self.selectedPayTypeModel.type.intValue == 2) { NSDictionary *resultDict = dict[@"data"]; NSString *order = [NSString stringWithFormat:@"%@",resultDict[@"ali"]]; [[AlipaySDK defaultService] payOrder:order fromScheme:AppScheme callback:^(NSDictionary *resultDic) { NSLog(@"支付宝H5支付回调 - %@", resultDic); }]; }else if (self.selectedPayTypeModel.type.intValue == 1) { NSDictionary *resultDict = dict[@"data"][@"wx"]; NSString *appid = resultDict[@"appid"]; NSString *partnerId = resultDict[@"partnerid"]; NSString *prepayId = [NSString stringWithFormat:@"%@",resultDict[@"prepayid"]]; NSString *nonceStr = resultDict[@"noncestr"]; UInt32 timeStamp = (UInt32)[resultDict[@"timestamp"] intValue]; NSString *package = resultDict[@"package"]; NSString *sign = resultDict[@"sign"]; PayReq *req = [[PayReq alloc] init]; req.openID = appid; req.partnerId = partnerId; req.prepayId = prepayId; req.nonceStr = nonceStr; req.timeStamp = timeStamp; req.package = package; req.sign = sign; [WXApi sendReq:req completion:^(BOOL success) { }]; } else if (self.selectedPayTypeModel.type.intValue == 4) { NSMutableDictionary*dic = [NSMutableDictionary dictionaryWithDictionary:dict[@"data"][@"tl"]]; [dic removeObjectForKey:@"json_data"]; NSString *json = [dic jsonStringEncoded]; NSString *thirdPartSchema = [NSString stringWithFormat:@"thirdPartSchema=%@://",AppScheme]; NSString *json1 = [json stringByReplacingOccurrencesOfString:@"\\" withString:@""]; NSCharacterSet *customSet1 = [[NSCharacterSet characterSetWithCharactersInString:@"!*'();:@&=+$,/?%#[]{}\""] invertedSet]; // NSCharacterSet *customSet2 = [[NSCharacterSet characterSetWithCharactersInString:@"!*'();:@&=+$,/?%#[]{}\""] invertedSet]; NSCharacterSet *customSet3 = [[NSCharacterSet characterSetWithCharactersInString:@"!*'();:@&=+$,/?%#[]{}\""] invertedSet]; NSString *json2 = [json1 stringByAddingPercentEncodingWithAllowedCharacters:customSet1]; NSString *encodedString = [thirdPartSchema stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSString *queryString = [NSString stringWithFormat:@"payinfo=%@", json2]; NSString *doubleEncodedQuery = [queryString stringByAddingPercentEncodingWithAllowedCharacters:customSet3]; NSString *jumpStr = [NSString stringWithFormat:@"alipays://platformapi/startapp?appId=2021001104615521&page=pages/orderDetail/orderDetail&%@&query=%@",encodedString,doubleEncodedQuery]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:jumpStr] options:@{} completionHandler:nil]; }else if (self.selectedPayTypeModel.type.intValue == 5) { WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; launchMiniProgramReq.userName = @"gh_e64a1a89a0ad"; NSDictionary *dic = dict[@"data"][@"tl"]; NSString *param = @""; for (NSString*key in dic.allKeys) { if (param.length == 0) { param = [param stringByAppendingFormat:@"%@=%@",key,dic[key]]; }else{ param = [param stringByAppendingFormat:@"&%@=%@",key,dic[key]]; } } launchMiniProgramReq.path = [NSString stringWithFormat:@"pages/orderDetail/orderDetail?%@",param]; launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; [WXApi sendReq:launchMiniProgramReq completion:nil]; } } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)paySuccess{ QXBuyNobilitySuccessViewController *vc = [[QXBuyNobilitySuccessViewController alloc] init]; vc.model = self.model; [self.navigationController pushViewController:vc animated:YES]; } -(void)agreementAction{ // id = 30; NSString *urlString = [NSString stringWithFormat:@"%@api/Page/page_show?id=%@",ServerUrl,@"30"]; QXBaseWebViewController *vc = [[QXBaseWebViewController alloc] init]; vc.urlStr = urlString; [self.navigationController pushViewController:vc animated:YES]; } -(void)selectedAction:(UIButton*)sender{ sender.selected = !sender.selected; self.isSelectedAgreement = sender.isSelected; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 2; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (section == 0) { return self.payTypeArray.count; }else{ return self.model.power_list.count; } } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { QXRechargePayTypeTableCell *cell = [QXRechargePayTypeTableCell cellWithTableView:tableView]; cell.model = self.payTypeArray[indexPath.row]; return cell; }else{ QXNobilityBuyDesCell *cell = [QXNobilityBuyDesCell cellWithTableView:tableView]; QXNobilityGetPricePowerList *md = self.model.power_list[indexPath.row]; cell.titleLabel.text = md.content; return cell; } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 36; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section == 0) { UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 42)]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16, 12, SCREEN_WIDTH-32, 30)]; label.font = [UIFont boldSystemFontOfSize:16]; label.text = @"支付方式"; label.textColor = RGB16A(0x000000, 0.85); [header addSubview:label]; return header; }else{ return nil; } } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 0) { return 42; }else{ return 0; } } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ if (section == 0) { return self.footerView; } return nil; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if (section == 0) { return self.footerView.height; } return 0; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { QXPayTypeModel *model = self.payTypeArray[indexPath.row]; if (model == self.selectedPayTypeModel) { return; } if (self.selectedPayTypeModel) { self.selectedPayTypeModel.isSelected = NO; } model.isSelected = YES; self.selectedPayTypeModel = model; [tableView reloadData]; } } -(UITableView *)tableView{ if (!_tableView) { self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavContentHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight) style:UITableViewStyleGrouped]; self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; } return _tableView; } -(QXNobilityPriceView *)priceView{ if (!_priceView) { _priceView = [[QXNobilityPriceView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 187)]; } return _priceView; } -(UIView *)footerView{ if (!_footerView) { _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120)]; UIButton *payBtn = [[UIButton alloc] initWithFrame:CGRectMake(37, 28, SCREEN_WIDTH-37*2, 42)]; payBtn.backgroundColor = QXConfig.themeColor; [payBtn addRoundedCornersWithRadius:21]; [payBtn setTitle:@"立即支付" forState:(UIControlStateNormal)]; [payBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; payBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [payBtn addTarget:self action:@selector(payAction) forControlEvents:(UIControlEventTouchUpInside)]; [_footerView addSubview:payBtn]; UILabel *titleLabel = [[UILabel alloc] init]; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"点击支付即表示您同意《爵位用户协议》"]; [attr yy_setColor:QXConfig.textColor range:NSMakeRange(0, attr.length)]; [attr yy_setColor:QXConfig.themeColor range:NSMakeRange(attr.length-8, 8)]; [attr yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attr.length)]; titleLabel.attributedText = attr; [titleLabel sizeToFit]; titleLabel.x = (SCREEN_WIDTH-titleLabel.width)/2+15; titleLabel.y = payBtn.bottom+9; titleLabel.height = 30; [_footerView addSubview:titleLabel]; UIButton *agreementBtn = [[UIButton alloc] initWithFrame:CGRectMake(titleLabel.right-100, titleLabel.top, 100, 30)]; [agreementBtn addTarget:self action:@selector(agreementAction) forControlEvents:(UIControlEventTouchUpInside)]; [_footerView addSubview:agreementBtn]; UIButton *selectedBtn = [[UIButton alloc] initWithFrame:CGRectMake(titleLabel.left-30, titleLabel.top, 30, 30)]; [selectedBtn setImage:[UIImage imageNamed:@"login_agreement_nor"] forState:(UIControlStateNormal)]; [selectedBtn setImage:[UIImage imageNamed:@"login_agreement_sel"] forState:(UIControlStateSelected)]; [selectedBtn addTarget:self action:@selector(selectedAction:) forControlEvents:(UIControlEventTouchUpInside)]; [_footerView addSubview:selectedBtn]; } return _footerView; } -(UIView *)tableFooterView{ if (!_tableFooterView) { _tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 90)]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nobility_desc_icon"]]; imageView.frame = CGRectMake(16, 15, 18, 18); [_tableFooterView addSubview:imageView]; UILabel *titleLabel =[[ UILabel alloc] initWithFrame:CGRectMake(imageView.right+5, 15, 100, 18)]; titleLabel.textColor = QXConfig.textColor; titleLabel.text = @"升级说明"; titleLabel.font = [UIFont boldSystemFontOfSize:16]; [_tableFooterView addSubview:titleLabel]; UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, imageView.bottom+10, SCREEN_WIDTH-16*2, 42)]; bottomLabel.numberOfLines = 0; bottomLabel.textColor = QXConfig.textColor; bottomLabel.font = [UIFont systemFontOfSize:14]; bottomLabel.text = @"如果您当前已有爵位,升级时将自动计算剩余价值抵扣新爵位费用"; [_tableFooterView addSubview:bottomLabel]; } return _tableFooterView; } -(NSMutableArray *)payTypeArray{ if (!_payTypeArray) { _payTypeArray = [NSMutableArray array]; } return _payTypeArray; } @end