YMAccountBalanceViewModel.m 28 KB

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