YMAccountBalanceViewModel.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. //
  2. // YMAccountBalanceViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/27.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAccountBalanceViewModel.h"
  9. #import "YMAccountBalanceModel.h"
  10. #import "YMAccountBalancePayInfoModel.h"
  11. #import <WechatOpenSDK/WXApi.h>
  12. #import <AlipaySDK/AlipaySDK.h>
  13. //#import <SDPTLib/SDPTFramework.h>
  14. #import <SandPayGate/SandPayGate.h>
  15. #import "WeChatMiniProgramHelper.h"
  16. @interface YMAccountBalanceViewModel ()
  17. /// 用户剩余余额
  18. @property (nonatomic, strong, readwrite) NSString *userRemainingBalance;
  19. /// 充值项目数据
  20. @property (nonatomic, strong, readwrite) NSArray <YMAccountBalanceRechargeItemCellViewModel*>*rechargeItemDataArray;
  21. /// 充值说明
  22. @property (nonatomic, strong, readwrite) NSAttributedString *rechargeNotes;
  23. /// 选中充值项目
  24. @property (nonatomic, strong, readwrite) RACSubject *selectedRechargeItemSubject;
  25. /// 选中支付方式
  26. @property (nonatomic, strong, readwrite) RACSubject *selectedPayMethodTypeSubject;
  27. /// 充值项目Id
  28. @property (nonatomic, assign) NSInteger rechargeItemId;
  29. /// 支付方式代码
  30. @property (nonatomic, copy) NSString *payMethodCode;
  31. @property (nonatomic, copy, readwrite) NSString *diamondStr;
  32. @end
  33. @implementation YMAccountBalanceViewModel
  34. - (void)ym_initialize{
  35. [super ym_initialize];
  36. self.customNavTitle = @"充值中心";
  37. self.diamondStr = @"";
  38. NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
  39. NSString *rechargeProtocolsStr = stringFormat(@"《%@充值服务协议》",appName);
  40. NSString *minorProtectionProgramStr = stringFormat(@"《%@未成年人保护计划》",appName);
  41. NSString *rechargeNotesStr = stringFormat(@"1、充值即代表已阅读并同意%@\n2、前往收支记录,可查询充值订单详情和消费详情\n3、禁止未成年人进行充值,点击详见%@\n4、在充值过程中如遇任何问题,可联系官方客服",rechargeProtocolsStr,minorProtectionProgramStr);
  42. NSMutableAttributedString *rechargeNotesAttributed = [[NSMutableAttributedString alloc]initWithString:rechargeNotesStr];
  43. rechargeNotesAttributed.yy_font = LCFont(11);
  44. rechargeNotesAttributed.yy_color = HexColorFromRGB(0x9c9c9c);
  45. rechargeNotesAttributed.yy_alignment = NSTextAlignmentLeft;
  46. rechargeNotesAttributed.yy_lineSpacing = 5;
  47. [rechargeNotesAttributed yy_setTextHighlightRange:[rechargeNotesStr rangeOfString:rechargeProtocolsStr] color:HexColorFromRGB(0x4e5889) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  48. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  49. ParamsUrl:[YMGlobalUtils shared].rechargeAgreementUrl
  50. }];
  51. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  52. RouterViewModel:webArticleVM
  53. } completion:nil];
  54. }];
  55. [rechargeNotesAttributed yy_setTextHighlightRange:[rechargeNotesStr rangeOfString:minorProtectionProgramStr] color:HexColorFromRGB(0x4e5889) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  56. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  57. ParamsUrl:[YMGlobalUtils shared].minorProtectionProgramUrl
  58. }];
  59. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  60. RouterViewModel:webArticleVM
  61. } completion:nil];
  62. }];
  63. self.rechargeNotes = rechargeNotesAttributed;
  64. @weakify(self)
  65. [[self.selectedRechargeItemSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * _Nullable value) {
  66. @strongify(self)
  67. YMAccountBalanceRechargeItemCellViewModel *viewModel = (YMAccountBalanceRechargeItemCellViewModel*)self.rechargeItemDataArray[[value intValue]];
  68. self.rechargeItemId = viewModel.rechargeItemId;
  69. }];
  70. [[self.selectedPayMethodTypeSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * _Nullable value) {
  71. @strongify(self)
  72. self.payMethodCode = value;
  73. }];
  74. }
  75. - (void)getAccountShowData{
  76. BOOL isRequestData = [OCUserDefaults boolForKey:kIS_FirstRechargeDialog];
  77. if (!isRequestData) {
  78. @weakify(self)
  79. [LCHttpHelper requestWithURLString:WalletShowDialog parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  80. @strongify(self)
  81. NSDictionary* dict = (NSDictionary*)responseObject;
  82. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  83. NSDictionary *dataDic = [dict objectForKey:@"data"];
  84. if (code == 0) {
  85. BOOL isShow = [[dataDic objectForKey:@"is_activity"] boolValue];
  86. NSArray *listArray = [dataDic objectForKey:@"list"];
  87. NSString *str = @"";
  88. if(listArray.count > 0){
  89. str = [NSString stringWithFormat:@"%@%@",listArray[0][@"name"],listArray[0][@"number"]];
  90. }
  91. self.diamondStr = str;
  92. if(!isShow){
  93. [OCUserDefaults setBool:YES forKey:kIS_FirstRechargeDialog];
  94. [self showRechagreDialog:str];
  95. }
  96. }
  97. } failure:^(NSError *error) {
  98. }];
  99. }
  100. }
  101. - (void)clickRechargeImageView{
  102. if([self.diamondStr isEqualToString:@""]){
  103. @weakify(self)
  104. [LCHttpHelper requestWithURLString:WalletShowDialog parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  105. @strongify(self)
  106. NSDictionary* dict = (NSDictionary*)responseObject;
  107. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  108. NSDictionary *dataDic = [dict objectForKey:@"data"];
  109. if (code == 0) {
  110. BOOL isShow = [[dataDic objectForKey:@"is_activity"] boolValue];
  111. NSArray *listArray = [dataDic objectForKey:@"list"];
  112. NSString *str = @"";
  113. if(listArray.count > 0){
  114. str = [NSString stringWithFormat:@"%@%@",listArray[0][@"name"],listArray[0][@"number"]];
  115. }
  116. self.diamondStr = str;
  117. [self showRechagreDialog:str];
  118. }
  119. } failure:^(NSError *error) {
  120. }];
  121. }else{
  122. [self showRechagreDialog:self.diamondStr];
  123. }
  124. }
  125. - (void)showRechagreDialog:(NSString*)moneyStr{
  126. return;
  127. UIView *customView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, adapt(310), adapt(366))];
  128. UIImageView *imgV = [[UIImageView alloc] init];
  129. imgV.image = ImageByName(@"ym_balance_show_bg");
  130. imgV.userInteractionEnabled = true;
  131. [customView addSubview:imgV];
  132. [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  133. make.top.equalTo(customView);
  134. make.centerX.equalTo(customView);
  135. make.width.mas_equalTo(adapt(310));
  136. make.height.mas_equalTo(adapt(366));
  137. }];
  138. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  139. [btn setImage:ImageByName(@"ym_balance_recharge_btn") forState:UIControlStateNormal];
  140. [customView addSubview:btn];
  141. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.bottom.equalTo(imgV.mas_bottom).offset(adapt(-8));
  143. make.centerX.equalTo(customView);
  144. make.width.mas_equalTo(adapt(222));
  145. make.height.mas_equalTo(adapt(78));
  146. }];
  147. UIImageView *closeImgv = [[UIImageView alloc] init];
  148. closeImgv.image = ImageByName(@"ym_common_close_white_icon");
  149. closeImgv.userInteractionEnabled = false;
  150. [customView addSubview:closeImgv];
  151. [closeImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.top.equalTo(customView.mas_bottom).offset(adapt(10));
  153. make.centerX.equalTo(customView);
  154. make.width.height.mas_equalTo(adapt(32));
  155. }];
  156. // UIImageView *bgV = [[UIImageView alloc] init];
  157. // bgV.image = ImageByName(@"ym_balance_diomand_bg");
  158. // bgV.userInteractionEnabled = true;
  159. // [customView addSubview:bgV];
  160. // [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  161. // make.bottom.equalTo(btn.mas_top).offset(adapt(-7));
  162. // make.centerX.equalTo(customView);
  163. // make.width.mas_equalTo(adapt(132));
  164. // make.height.mas_equalTo(adapt(31));
  165. // }];
  166. //
  167. // UIImageView *leftV = [[UIImageView alloc] init];
  168. // [bgV addSubview:leftV];
  169. // leftV.image = ImageByName(@"ym_account_balance_recharge_item_diamond_icon");
  170. // [leftV mas_makeConstraints:^(MASConstraintMaker *make) {
  171. // make.left.equalTo(bgV).offset(adapt(13));
  172. // make.centerY.equalTo(bgV);
  173. // make.width.mas_equalTo(adapt(18));
  174. // make.height.mas_equalTo(adapt(14));
  175. // }];
  176. //
  177. // UILabel *label = [[UILabel alloc] init];
  178. // [bgV addSubview:label];
  179. // label.text = moneyStr;
  180. // label.font = LCFont(15);
  181. // label.textColor = HexColorFromRGB(0xFF126B);
  182. // [label mas_makeConstraints:^(MASConstraintMaker *make) {
  183. // make.left.equalTo(leftV.mas_right).offset(adapt(5));
  184. // make.centerY.equalTo(bgV);
  185. // }];
  186. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  187. popupView.priority = 999;
  188. popupView.backgroundColor = UIColor.clearColor;
  189. popupView.positionStyle = YMPositionStyleCenter;
  190. popupView.isHideBg = NO;
  191. popupView.bgAlpha = 0.7;
  192. @weakify(popupView)
  193. popupView.bgClickBlock = ^{
  194. @strongify(popupView)
  195. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  196. };
  197. [[[btn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  198. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  199. }];
  200. [popupView pop];
  201. }
  202. - (void)getAccountBalanceInfoData{
  203. @weakify(self)
  204. [ZCHUDHelper showWithStatus:@"加载中..."];
  205. [LCHttpHelper requestWithURLString:WalletGoodList parameters:@{
  206. @"type":@(2)
  207. } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  208. @strongify(self)
  209. NSDictionary* dict = (NSDictionary*)responseObject;
  210. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  211. if (code == 0) {
  212. [ZCHUDHelper dismiss];
  213. YMAccountBalanceModel *model = [YMAccountBalanceModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
  214. self.userRemainingBalance = model.coin;
  215. self.rechargeItemDataArray = [model.list.rac_sequence map:^id _Nullable(YMAccountBalanceRechargeItemModel * _Nullable model) {
  216. YMAccountBalanceRechargeItemCellViewModel *viewModel = [[YMAccountBalanceRechargeItemCellViewModel alloc]initWithParams:@{
  217. ParamsModel:model
  218. }];
  219. return viewModel;
  220. }].array;
  221. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  222. }else{
  223. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  224. }
  225. } failure:^(NSError *error) {
  226. [ZCHUDHelper showTitle:error.localizedDescription];
  227. }];
  228. }
  229. - (void)detectionAccountBalanceRechargeInfoData{
  230. @weakify(self)
  231. [ZCHUDHelper showWithStatus:@"请求中..."];
  232. [LCHttpHelper requestWithURLString:DetectionAccountBalanceRechargeInfo parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  233. @strongify(self)
  234. NSDictionary* dict = (NSDictionary*)responseObject;
  235. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  236. if (code == 0) {
  237. [ZCHUDHelper dismiss];
  238. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  239. BOOL isPop = [data boolValueForKey:@"is_pop" defaultValue:NO];
  240. if (isPop) {
  241. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  242. [customView configutationWithTips:[data stringValueForKey:@"msg" defaultValue:@""] TipsAlignment:NSTextAlignmentCenter IsHideTitle:YES IsHideSingleButton:YES];
  243. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  244. popupView.priority = 999;
  245. popupView.cornerRadius = adapt(10);
  246. popupView.rectCorners = UIRectCornerAllCorners;
  247. popupView.positionStyle = YMPositionStyleCenter;
  248. popupView.isHideBg = NO;
  249. popupView.bgAlpha = 0.3;
  250. @weakify(popupView)
  251. customView.buttonBlock = ^(BOOL isConfirm) {
  252. @strongify(popupView)
  253. if (isConfirm) {
  254. [self submitAccountBalanceRechargeInfoData];
  255. }
  256. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  257. };
  258. [popupView pop];
  259. } else {
  260. [self submitAccountBalanceRechargeInfoData];
  261. }
  262. }else{
  263. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  264. }
  265. } failure:^(NSError *error) {
  266. [ZCHUDHelper showTitle:error.localizedDescription];
  267. }];
  268. }
  269. - (void)submitAccountBalanceRechargeInfoData{
  270. if ([self.payMethodCode containsString:@"wechat"]) {
  271. @weakify(self)
  272. [ZCHUDHelper showWithStatus:@"请求中..."];
  273. [LCHttpHelper requestWithURLString:AccountBalanceRechargeWeChatPay parameters:@{
  274. @"device":@(1),
  275. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  276. @strongify(self)
  277. NSDictionary* dict = (NSDictionary*)responseObject;
  278. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  279. if (code == 0) {
  280. [ZCHUDHelper dismiss];
  281. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  282. NSString *pay_channel = [data stringValueForKey:@"pay_channel" defaultValue:@""];
  283. //NSInteger polling = [data integerValueForKey:@"polling" defaultValue:0];
  284. [self payOrderWithChannel:pay_channel polling:-1];
  285. }else{
  286. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  287. }
  288. } failure:^(NSError *error) {
  289. [ZCHUDHelper showTitle:error.localizedDescription];
  290. }];
  291. } else if ([self.payMethodCode containsString:@"alipay"]) {
  292. [self payOrderWithChannel:self.payMethodCode polling:-1];
  293. }
  294. }
  295. - (void)payOrderWithChannel:(NSString*)channel polling:(NSInteger)polling{
  296. @weakify(self)
  297. [ZCHUDHelper showWithStatus:@"请求中..."];
  298. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  299. if (![channel isEqual:@"alipay"]) {
  300. channel = @"wechat";
  301. }
  302. [params setObject:channel forKey:@"channel"];
  303. [params setObject:@(self.rechargeItemId) forKey:@"goods_id"];
  304. [params setObject:@(polling) forKey:@"polling"];
  305. NSLog(@"输出🍀\n%@",params);
  306. [LCHttpHelper requestWithURLString:WalletRecharge parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  307. @strongify(self)
  308. NSDictionary* dict = (NSDictionary*)responseObject;
  309. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  310. NSLog(@"输出🍀\n%@",dict);
  311. if (code == 0) {
  312. [ZCHUDHelper dismiss];
  313. YMAccountBalancePayInfoModel *model = [YMAccountBalancePayInfoModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
  314. NSLog(@"这里----34");
  315. if ([self.payMethodCode containsString:@"wechat"]) {
  316. if(![WXApi isWXAppInstalled]){
  317. [ZCHUDHelper showTitle:@"未安装微信或版本过低"];
  318. return;
  319. }
  320. NSLog(@"当前支付类型---:%lu",(unsigned long)model.pay_obj.type);
  321. if (model.pay_obj.type == YMAccountBalabcePayTypeWechat_MiniApp) {
  322. NSString*allPath = [NSString stringWithFormat:@"/pages/pay/index?isVip=0&channel=wechat&goods_id=%@&polling=-1&token=%@&TTTYPE=1&api=%@",@(self.rechargeItemId),[LCSaveData getTokenString],WXAPPAPI];
  323. NSLog(@"将要跳转的小程序PATH:%@",allPath);
  324. [WeChatMiniProgramHelper openMiniProgramWithUserName:model.pay_obj.applet_gh_id path:allPath];
  325. }else if (model.pay_obj.type == YMAccountBalabcePayType_H5) {
  326. NSDictionary*dic =model.pay_obj.data;
  327. NSURL *url = [NSURL URLWithString:dic[@"pay_info"]];
  328. // 检查是否可以打开URL
  329. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  330. // 打开URL
  331. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  332. }
  333. }else if (model.pay_obj.type == YMAccountBalabcePayTypeAlipay_H5) {
  334. NSLog(@"当前支付类型3---:%@",model.pay_obj.data);
  335. NSURL *url = [NSURL URLWithString:model.pay_obj.data];
  336. // 检查是否可以打开URL
  337. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  338. // 打开URL
  339. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  340. }
  341. }else if(model.pay_obj.type == YMAccountBalabcePayTypeWeChat_pay) {
  342. NSDictionary *result_dict = [dict objectForKey:@"data"];
  343. NSDictionary *pay_obj_dict = [result_dict objectForKey:@"pay_obj"];
  344. NSDictionary *pay_obj_data = [pay_obj_dict objectForKey:@"data"];
  345. YMAccountBalanceWeChatInfoModel *wechatpayinfo = [YMAccountBalanceWeChatInfoModel yy_modelWithJSON:pay_obj_data];
  346. PayReq *request = [[PayReq alloc] init];
  347. request.partnerId = wechatpayinfo.mch_id;
  348. request.prepayId = wechatpayinfo.prepay_id;
  349. request.package = @"Sign=WXPay";
  350. request.nonceStr = wechatpayinfo.nonce_str;
  351. request.timeStamp = (uint32_t)[wechatpayinfo.timestamp intValue];
  352. request.sign = wechatpayinfo.paySign;
  353. NSString *partnerId = request.partnerId;
  354. NSString *prepayId = request.prepayId;
  355. NSString *package = request.package;
  356. NSString *nonceStr = request.nonceStr;
  357. NSInteger timeStamp = request.timeStamp;
  358. NSString *sign = request.sign;
  359. NSLog(@"输出🍀\n%@",@{
  360. @"partnerId":partnerId,
  361. @"prepayId":prepayId,
  362. @"package":package,
  363. @"nonceStr":nonceStr,
  364. @"timeStamp":@(timeStamp),
  365. @"sign":sign
  366. });
  367. [WXApi sendReq:request completion:^(BOOL success) {
  368. }];
  369. } else {
  370. NSString *token = model.pay_obj.data;
  371. NSLog(@"%@",token);
  372. if (!token || token.length == 0) {
  373. [ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败,请联系技术人员"]];
  374. return;
  375. }
  376. [SandPayGateService.shared queryTradeRecordInfoWith:token];
  377. SandPayGateService.shared.sandpayGateResultBlock = ^(NSString* status, NSDictionary* dataDic) {
  378. NSLog(@"输出🍀\n%@ \n%@",status, dataDic);
  379. if ([status isEqualToString:@"success"]) {
  380. NSString *funcCode = dataDic[@"funcCode"];
  381. NSString *ghOriId = dataDic[@"ghOriId"];
  382. NSString *miniProgramType = dataDic[@"miniProgramType"];
  383. NSString *pathUrl = dataDic[@"pathUrl"];
  384. NSString *subAppId = dataDic[@"subAppId"];
  385. NSString *tokenId = dataDic[@"tokenId"];
  386. //跳转微信小程序
  387. NSString *allPath = [NSString stringWithFormat:@"%@token_id=%@&funcCode=%@", pathUrl, tokenId, funcCode];
  388. NSLog(@"输出🍀\n%@", allPath);
  389. WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
  390. launchMiniProgramReq.userName = ghOriId;
  391. launchMiniProgramReq.path = allPath;
  392. launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; // 使用适当的类型,例如WXMiniProgramTypeRelease
  393. [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
  394. if (success) {
  395. NSLog(@"跳转微信成功");
  396. } else {
  397. NSLog(@"跳转微信异常");
  398. }
  399. }];
  400. } else {
  401. //[ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败:%@",errorMsg]];
  402. [ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败"]];
  403. }
  404. };}
  405. //
  406. //
  407. // XHPayParameterModel *payParameter = [XHPayParameterModel yy_modelWithJSON:model.pay_obj.data];
  408. // [SDPTController shared].paySucTypeBlock = ^(ProductPyType type, id _Nonnull responseObj) {
  409. // NSLog(@"测试打印:%@",responseObj);
  410. // //跳转微信小程序
  411. // NSDictionary *pay_extra = [payParameter.pay_extra mj_JSONObject];
  412. // NSString * allPath = [NSString stringWithFormat:@"%@token_id=%@",pay_extra[@"path_url"],responseObj];
  413. // WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
  414. //
  415. // launchMiniProgramReq.userName = pay_extra[@"gh_ori_id"];
  416. // launchMiniProgramReq.path = allPath;
  417. // /// 0 正式版
  418. // launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease;
  419. // [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
  420. // if (success) {
  421. // NSLog(@"跳转微信成功");
  422. // } else {
  423. // NSLog(@"跳转微信异常");
  424. // }
  425. // }];
  426. //
  427. // };
  428. // [SDPTController shared].payFailureBlock = ^(ProductPyType type, NSString * _Nonnull errorMsg) {
  429. // [ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败:%@",errorMsg]];
  430. // };
  431. //
  432. // if(payParameter){
  433. // [[SDPTController shared] singletonPaymentMethodWith:payParameter];
  434. // }else{
  435. // [ZCHUDHelper showTitle:@"支付数据错误"];
  436. // }
  437. } else if ([self.payMethodCode containsString:@"alipay"]) {
  438. if(model.pay_obj.type == YMAccountBalabcePayTypeAliSdk_pay){
  439. NSString *appScheme = @"msyoupaipay";
  440. [[AlipaySDK defaultService] payOrder:model.payinfo fromScheme:appScheme callback:^(NSDictionary *resultDic) {
  441. NSLog(@"reslut ====== %@",resultDic);
  442. if ([resultDic[@"resultStatus"] isEqualToString:@"9000"] || [resultDic[@"resultStatus"] isEqualToString:@"8000"] || [resultDic[@"resultStatus"] isEqualToString:@"6004"]) {
  443. [ZCHUDHelper showTitle:@"支付成功"];
  444. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  445. [OCNotificationCenter postNotificationName:ALIPAY_SUCCESS_NOTIFICATION object:nil];
  446. });
  447. } else if ([resultDic[@"resultStatus"] isEqualToString:@"6001"]) {
  448. }else {
  449. [ZCHUDHelper showTitle:@"支付失败"];
  450. }
  451. }];
  452. }else{
  453. NSLog(@"这里----1");
  454. if (model.pay_obj.type == YMAccountPayTypeAlipay_H5) {
  455. // 拼接支付宝 Scheme URL
  456. NSString *alipayUrlString = [NSString stringWithFormat:@"alipay://platformapi/startapp?appId=20000067&url=%@",model.pay_obj.data];
  457. NSURL *alipayUrl = [NSURL URLWithString:alipayUrlString];
  458. // 检查是否可以打开URL
  459. if ([[UIApplication sharedApplication] canOpenURL:alipayUrl]) {
  460. // 打开URL
  461. NSLog(@"尝试打开支付宝");
  462. [[UIApplication sharedApplication] openURL:alipayUrl options:@{} completionHandler:nil];
  463. }else {
  464. NSLog(@"不能打开支付宝");
  465. }
  466. }else if (model.pay_obj.type == YMAccountBalabcePayType_H5) {
  467. NSDictionary*dic =model.pay_obj.data;
  468. NSURL *url = [NSURL URLWithString:dic[@"pay_info"]];
  469. // 检查是否可以打开URL
  470. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  471. // 打开URL
  472. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  473. }
  474. }else if (model.pay_obj.type == YMAccountBalabcePayTypeAlipay_H5) {
  475. NSLog(@"当前支付类型3---:%@",model.pay_obj.data);
  476. NSURL *url = [NSURL URLWithString:model.pay_obj.data];
  477. // 检查是否可以打开URL
  478. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  479. // 打开URL
  480. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  481. }
  482. }else {
  483. NSString *token = model.pay_obj.data;
  484. NSLog(@"%@",token);
  485. if (!token || token.length == 0) {
  486. [ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败,请联系技术人员"]];
  487. return;
  488. }
  489. [SandPayGateService.shared queryTradeRecordInfoWith:token];
  490. SandPayGateService.shared.sandpayGateResultBlock = ^(NSString* status, NSDictionary* dataDic) {
  491. NSLog(@"输出🍀\n%@ \n%@",status, dataDic);
  492. if ([status isEqualToString:@"success"]) {
  493. } else {
  494. //[ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败:%@",errorMsg]];
  495. [ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败"]];
  496. }
  497. };
  498. }
  499. // [SDPTController shared].paySucTypeBlock = ^(ProductPyType type, id _Nonnull responseObj) {
  500. // NSLog(@"支付数据匹配成功");
  501. //
  502. // };
  503. // [SDPTController shared].payFailureBlock = ^(ProductPyType type, NSString * _Nonnull errorMsg) {
  504. // [ZCHUDHelper showTitle:[NSString stringWithFormat:@"支付失败:%@",errorMsg]];
  505. // };
  506. //
  507. // XHPayParameterModel *data = [XHPayParameterModel mj_objectWithKeyValues:responseObject[@"data"][@"pay_obj"][@"data"]];
  508. // [[SDPTController shared] singletonPaymentMethodWith:data];
  509. }
  510. }
  511. }else{
  512. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  513. }
  514. } failure:^(NSError *error) {
  515. [ZCHUDHelper showTitle:error.localizedDescription];
  516. }];
  517. }
  518. - (void)gotoIncomeBreakdown{
  519. YMIncomeBreakdownViewModel *incomeBreakdownVM = [[YMIncomeBreakdownViewModel alloc]initWithParams:@{}];
  520. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_INCOME_BREAKDOWN) withUserInfo:@{
  521. RouterViewModel:incomeBreakdownVM
  522. } completion:nil];
  523. }
  524. - (RACSubject *)selectedRechargeItemSubject{
  525. if (!_selectedRechargeItemSubject) {
  526. _selectedRechargeItemSubject = [RACSubject subject];
  527. }
  528. return _selectedRechargeItemSubject;
  529. }
  530. - (RACSubject *)selectedPayMethodTypeSubject{
  531. if (!_selectedPayMethodTypeSubject) {
  532. _selectedPayMethodTypeSubject = [RACSubject subject];
  533. }
  534. return _selectedPayMethodTypeSubject;
  535. }
  536. @end