PayOrderView.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. //
  2. // PayOrderView.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/14.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "PayOrderView.h"
  9. #import <WXApi.h>
  10. #import "Order.h"
  11. #import <AlipaySDK/AlipaySDK.h>
  12. #import "DataSigner.h"
  13. #import "DataVerifier.h"
  14. #import "YBRechargeType.h"
  15. @implementation PayOrderView
  16. -(instancetype)initWithPrice:(NSString *)price AndOrderId:(NSString *)orderid AndShopName:(NSString *)nameStr{
  17. self = [super init];
  18. if (self) {
  19. self.backgroundColor = RGBA(29, 29, 29, 0.4);
  20. self.payArr = [NSArray array];
  21. infoDic = [NSDictionary dictionary];
  22. index = 0;
  23. _priceStr = [price stringByReplacingOccurrencesOfString:@"¥" withString:@""];
  24. _orderIdStr = orderid;
  25. _shopNameStr = nameStr;
  26. [self createUI];
  27. [self requestBalance];
  28. }
  29. return self;
  30. }
  31. -(void)createUI{
  32. UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height*0.4, _window_width, _window_height*0.6)];
  33. backView.backgroundColor = [UIColor whiteColor];
  34. [self addSubview:backView];
  35. UIButton *closeBtn = [UIButton buttonWithType:0];
  36. closeBtn.frame = CGRectMake(_window_width-30, 15, 20, 20);
  37. [closeBtn setImage:[UIImage imageNamed:@"standardClose"] forState:0];
  38. [closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
  39. [backView addSubview:closeBtn];
  40. UILabel *titlelb = [[UILabel alloc]init];
  41. titlelb.frame = CGRectMake(0, 10, _window_width, 30);
  42. titlelb.font = [UIFont systemFontOfSize:14];
  43. titlelb.textAlignment = NSTextAlignmentCenter;
  44. titlelb.textColor = [UIColor blackColor];
  45. titlelb.text = YZMsg(@"收银台");
  46. [backView addSubview:titlelb];
  47. [PublicObj lineViewWithFrame:CGRectMake(0, titlelb.bottom+10, _window_width, 1) andColor:RGB(240, 240, 240) andView:backView];
  48. UILabel *priceLb = [[UILabel alloc]init];
  49. priceLb.font = [UIFont systemFontOfSize:20];
  50. priceLb.text = _priceStr;
  51. priceLb.textColor = [UIColor blackColor];
  52. [backView addSubview:priceLb];
  53. [priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.centerX.equalTo(backView);
  55. make.top.equalTo(titlelb.mas_bottom).offset(30);
  56. }];
  57. UILabel *fuhao =[[UILabel alloc]init];
  58. fuhao.font = [UIFont systemFontOfSize:14];
  59. fuhao.text = @"¥";
  60. fuhao.textColor = [UIColor blackColor];
  61. [backView addSubview:fuhao];
  62. [fuhao mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.right.equalTo(priceLb.mas_left);
  64. make.bottom.equalTo(priceLb.mas_bottom);
  65. }];
  66. UILabel *shopNameLb = [[UILabel alloc]init];
  67. shopNameLb.font = [UIFont systemFontOfSize:14];
  68. shopNameLb.text = [NSString stringWithFormat:@"%@%@",[common shop_system_name],YZMsg(@"支付")];//_shopNameStr;
  69. shopNameLb.textColor = [UIColor grayColor];
  70. [backView addSubview:shopNameLb];
  71. [shopNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.top.equalTo(priceLb.mas_bottom).offset(5);
  73. make.centerX.equalTo(backView);
  74. }];
  75. [backView layoutIfNeeded];
  76. payTable = [[UITableView alloc]initWithFrame:CGRectMake(15, shopNameLb.bottom, _window_width-30, backView.height-shopNameLb.bottom-80) style:UITableViewStylePlain];
  77. payTable.delegate = self;
  78. payTable.dataSource = self;
  79. payTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  80. [backView addSubview:payTable];
  81. UIButton *payBtn = [UIButton buttonWithType:0];
  82. payBtn.frame = CGRectMake(15, backView.height-60, _window_width-30, 40);
  83. [payBtn setBackgroundColor:Pink_Cor];
  84. [payBtn setTitle:YZMsg(@"立即支付") forState:0];
  85. [payBtn setTitleColor:[UIColor whiteColor] forState:0];
  86. payBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  87. payBtn.layer.cornerRadius = 20;
  88. payBtn.layer.masksToBounds = YES;
  89. [payBtn addTarget:self action:@selector(payBtnClick) forControlEvents:UIControlEventTouchUpInside];
  90. [backView addSubview:payBtn];
  91. }
  92. -(void)closeClick{
  93. if (self.hideEvent) {
  94. self.hideEvent(NO);
  95. }
  96. }
  97. -(void)payBtnClick{
  98. if ([typeStr isEqual:@"1"]) {
  99. [self doAlipayPay];
  100. }else if ([typeStr isEqual:@"2"]){
  101. [self WeiXinPay];
  102. }else if ([typeStr isEqual:@"3"]){
  103. [self doBalance];
  104. }else if ([typeStr isEqual:@"6"]){
  105. //paypal支付
  106. [self dopayPal];
  107. }
  108. }
  109. -(void)requestBalance{
  110. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken], @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  111. NSString *sign = [PublicObj sortString:signdic];
  112. NSDictionary *dic = @{
  113. @"uid":[Config getOwnID],
  114. @"token":[Config getOwnToken],
  115. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  116. @"sign":sign
  117. };
  118. [YBNetworking postWithUrl:@"Buyer.getBalance" Dic:dic Suc:^(int code, id info, NSString *msg) {
  119. if (code ==0) {
  120. infoDic = [info firstObject];
  121. NSMutableArray *originPaylist = [NSMutableArray arrayWithArray:[infoDic valueForKey:@"paylist"]];
  122. NSMutableArray *delArray = [NSMutableArray array];
  123. if ([PublicObj isUp]) {
  124. for (NSDictionary *subDic in originPaylist) {
  125. if ([[subDic valueForKey:@"id"] isEqual:@"balance"]) {
  126. [delArray addObject:subDic];
  127. }
  128. }
  129. [originPaylist removeObjectsInArray:delArray];
  130. }
  131. self.payArr = [NSArray arrayWithArray:originPaylist];
  132. NSDictionary *payDic = self.payArr[0];
  133. if ([minstr([payDic valueForKey:@"id"]) isEqual:@"ali"]) {
  134. typeStr = @"1";
  135. }else if([minstr([payDic valueForKey:@"id"]) isEqual:@"wx"]){
  136. typeStr = @"2";
  137. }else if([minstr([payDic valueForKey:@"id"]) isEqual:@"balance"]){
  138. typeStr = @"3";
  139. }
  140. _aliapp_key_ios = [infoDic valueForKey:@"aliapp_key_ios"];
  141. _aliapp_partner = [infoDic valueForKey:@"aliapp_partner"];
  142. _aliapp_seller_id = [infoDic valueForKey:@"aliapp_seller_id"];
  143. //微信的信息
  144. _wx_appid = [infoDic valueForKey:@"wx_appid"];
  145. [WXApi registerApp:_wx_appid universalLink:WechatUniversalLink];
  146. [payTable reloadData];
  147. }else{
  148. [MBProgressHUD showError:msg];
  149. }
  150. } Fail:^(id fail) {
  151. }];
  152. }
  153. #pragma mark-----tabelviewDelegate------
  154. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  155. {
  156. return 1;
  157. }
  158. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  159. {
  160. return _payArr.count;
  161. }
  162. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. return 50;
  165. }
  166. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  167. {
  168. UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"paycell"];
  169. UIImageView *iconImg = [[UIImageView alloc]init];
  170. [iconImg sd_setImageWithURL:[NSURL URLWithString:[self.payArr[indexPath.row]valueForKey:@"thumb"]]];
  171. [cell addSubview:iconImg];
  172. [iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
  173. make.left.equalTo(cell).offset(5);
  174. make.centerY.equalTo(cell.mas_centerY);
  175. make.height.width.mas_equalTo(20);
  176. }];
  177. UILabel *nameLb = [[UILabel alloc]init];
  178. nameLb.font = [UIFont systemFontOfSize:14];
  179. nameLb.textColor = [UIColor blackColor];
  180. nameLb.text = minstr([self.payArr[indexPath.row]valueForKey:@"name"]);
  181. [cell addSubview:nameLb];
  182. [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.left.equalTo(iconImg.mas_right).offset(5);
  184. make.centerY.equalTo(iconImg.mas_centerY);
  185. }];
  186. UILabel *balanceLb = [[UILabel alloc]init];
  187. balanceLb.font = [UIFont systemFontOfSize:14];
  188. balanceLb.textColor = [UIColor grayColor];
  189. balanceLb.text =[NSString stringWithFormat:@"(¥%@)",minstr([infoDic valueForKey:@"balance"])];
  190. if ([nameLb.text containsString:YZMsg(@"余额")]) {
  191. balanceLb.hidden = NO;
  192. }else{
  193. balanceLb.hidden = YES;
  194. }
  195. [cell addSubview:balanceLb];
  196. [balanceLb mas_makeConstraints:^(MASConstraintMaker *make) {
  197. make.left.equalTo(nameLb.mas_right).offset(5);
  198. make.centerY.equalTo(nameLb.mas_centerY);
  199. }];
  200. [PublicObj lineViewWithFrame:CGRectMake(0, 49, _window_width-30, 1) andColor:RGB(240, 240, 240) andView:cell];
  201. UIImageView *duihaoImg = [[UIImageView alloc]init];
  202. duihaoImg.frame = CGRectMake(cell.width-30, 50/2-10, 18, 13);
  203. duihaoImg.image = [UIImage imageNamed:@"pay_选中"];
  204. duihaoImg.hidden = YES;
  205. [cell addSubview:duihaoImg];
  206. if (index == indexPath.row) {
  207. duihaoImg.hidden = NO;
  208. }else{
  209. duihaoImg.hidden = YES;
  210. }
  211. return cell;
  212. }
  213. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  214. index = indexPath.row;
  215. NSDictionary *payDic = self.payArr[indexPath.row];
  216. if ([minstr([payDic valueForKey:@"id"]) isEqual:@"ali"]) {
  217. typeStr = @"1";
  218. }else if([minstr([payDic valueForKey:@"id"]) isEqual:@"wx"]){
  219. typeStr = @"2";
  220. }else if([minstr([payDic valueForKey:@"id"]) isEqual:@"balance"]){
  221. typeStr = @"3";
  222. }else if([minstr([payDic valueForKey:@"id"]) isEqual:@"paypal"]){
  223. typeStr = minstr([payDic valueForKey:@"type"]);
  224. }
  225. [payTable reloadData];
  226. }
  227. //paypal***************
  228. /*payPal支付*/
  229. -(void)dopayPal{
  230. NSLog(@"paypal支付");
  231. [MBProgressHUD showMessage:@""];
  232. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"orderid":_orderIdStr,@"type":typeStr,@"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  233. NSString *sign = [PublicObj sortString:signdic];
  234. NSDictionary *subdic = @{
  235. @"uid":[Config getOwnID],
  236. @"token":[Config getOwnToken],
  237. @"orderid":_orderIdStr,
  238. @"type":typeStr,
  239. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  240. @"sign":sign
  241. };
  242. [YBNetworking postWithUrl:@"Buyer.goodsOrderPay" Dic:subdic Suc:^(int code, id info, NSString *msg) {
  243. [MBProgressHUD hideHUD];
  244. if (code == 0) {
  245. NSDictionary *dict = [info firstObject];
  246. NSDictionary *payDic = @{@"money":_priceStr,
  247. @"orderid":minstr([dict valueForKey:@"orderid"]),
  248. };
  249. [[YBRechargeType chargeManeger] selPayPalAndPatameter:payDic rechargeType:rechargeType_Goods complete:^(int stateCode, int payType, NSString *msg) {
  250. dispatch_async(dispatch_get_main_queue(), ^{
  251. if (stateCode == 0) {
  252. if (self.hideEvent) {
  253. self.hideEvent(YES);
  254. }
  255. }
  256. });
  257. }];
  258. }
  259. else{
  260. [MBProgressHUD showError:msg];
  261. }
  262. } Fail:^(id fail) {
  263. [MBProgressHUD hideHUD];
  264. }];
  265. }
  266. #pragma mark - PayPal
  267. //- (PayPalConfiguration *)paypalConfiguration {
  268. // if (!_paypalConfiguration) {
  269. // _paypalConfiguration = [[PayPalConfiguration alloc] init];
  270. // _paypalConfiguration.merchantName = [PublicObj getAppName];
  271. // _paypalConfiguration.acceptCreditCards = NO;//不支持信用卡
  272. // _paypalConfiguration.payPalShippingAddressOption = PayPalShippingAddressOptionPayPal;
  273. // _paypalConfiguration.languageOrLocale = lagType;
  274. // }
  275. // return _paypalConfiguration;
  276. //}
  277. //-(void)dopayPal{
  278. // NSLog(@"paypal支付");
  279. // [MBProgressHUD showMessage:@""];
  280. //
  281. // NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"orderid":_orderIdStr,@"type":@"5",@"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  282. // NSString *sign = [PublicObj sortString:signdic];
  283. //
  284. // NSDictionary *subdic = @{
  285. // @"uid":[Config getOwnID],
  286. // @"token":[Config getOwnToken],
  287. // @"orderid":_orderIdStr,
  288. // @"type":@"5",
  289. // @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  290. // @"sign":sign
  291. // };
  292. // [YBToolClass postNetworkWithUrl:@"Buyer.goodsOrderPay" andParameter:subdic success:^(int code, id _Nonnull info, NSString * _Nonnull msg) {
  293. // [MBProgressHUD hideHUD];
  294. // if (code == 0) {
  295. // NSDictionary *dict = [info firstObject];
  296. // //调起paypal支付
  297. // [self selPaypalParameter:dict];
  298. // }
  299. // else{
  300. // [MBProgressHUD showError:msg];
  301. // }
  302. //
  303. // } fail:^{
  304. // [MBProgressHUD hideHUD];
  305. //
  306. // }];
  307. //}
  308. //-(void)selPaypalParameter:(NSDictionary *)parameter{
  309. // NSString *sandBox = minstr([parameter valueForKey:@"paypal_sandbox"]);//0-沙盒 1正式
  310. // NSString *client_id = minstr([parameter valueForKey:@"product_clientid"]);
  311. // NSString *paypal_sandbox_id = minstr([parameter valueForKey:@"sandbox_clientid"]);
  312. //
  313. // if ([sandBox isEqual:@"1"]) {
  314. // if ([PublicObj checkNull:client_id] ) {
  315. // [MBProgressHUD showError:YZMsg(@"贝宝未配置")];
  316. //
  317. // return;
  318. // }
  319. // [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction:client_id,PayPalEnvironmentSandbox:paypal_sandbox_id}];
  320. //
  321. // [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentProduction];
  322. // }else{
  323. // if ([PublicObj checkNull:paypal_sandbox_id] ) {
  324. // [MBProgressHUD showError:YZMsg(@"贝宝未配置")];
  325. //
  326. // return;
  327. // }
  328. // [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction:client_id,PayPalEnvironmentSandbox:paypal_sandbox_id}];
  329. //
  330. // [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
  331. // }
  332. //
  333. // NSString *orderStr = minstr([parameter valueForKey:@"orderid"]);
  334. // PayPalPayment *payment = [[PayPalPayment alloc] init];
  335. // payment.amount = [[NSDecimalNumber alloc] initWithString:_priceStr];
  336. // payment.currencyCode = @"USD";
  337. // payment.invoiceNumber = orderStr;
  338. // payment.shortDescription = minstr([parameter valueForKey:@"goods_name"]); //YZMsg(@"直播小店支付");//
  339. // payment.custom = @"order_pay";//
  340. // payment.items = nil; // if not including multiple items, then leave payment.items as nil
  341. // payment.paymentDetails = nil; // if not including payment details, then leave payment.paymentDetails as nil
  342. // payment.intent = PayPalPaymentIntentSale;
  343. // if (!payment.processable) {
  344. // NSLog(@"-------------");
  345. // }
  346. // PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.paypalConfiguration delegate:self];
  347. // [[YBBaseAppDelegate sharedAppDelegate].topViewController presentViewController:paymentViewController animated:YES completion:nil];
  348. //
  349. //}
  350. //#pragma mark - PayPalPaymentDelegate methods
  351. //- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
  352. // [self verifyCompletedPayment:completedPayment];
  353. // [[YBBaseAppDelegate sharedAppDelegate].topViewController dismissViewControllerAnimated:YES completion:nil];
  354. //}
  355. //
  356. //- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
  357. // NSLog(@"支付有错误 稍后重试");
  358. // [[YBBaseAppDelegate sharedAppDelegate].topViewController dismissViewControllerAnimated:YES completion:nil];
  359. //}
  360. //
  361. //- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
  362. // // Send the entire confirmation dictionary
  363. // NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation options:0 error:nil];
  364. // NSLog(@"=================%@",completedPayment.confirmation);
  365. // NSLog(@"---------------------------------");
  366. // NSLog(@"==================%@",confirmation);
  367. // if (self.hideEvent) {
  368. // self.hideEvent(YES);
  369. // }
  370. //
  371. //
  372. //
  373. //}
  374. //微信支付*****************************************************************************************************************
  375. -(void)WeiXinPay{
  376. NSLog(@"微信支付");
  377. [MBProgressHUD showMessage:@""];
  378. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"orderid":_orderIdStr,@"type":@"2",@"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  379. NSString *sign = [PublicObj sortString:signdic];
  380. NSDictionary *subdic = @{
  381. @"uid":[Config getOwnID],
  382. @"token":[Config getOwnToken],
  383. @"orderid":_orderIdStr,
  384. @"type":@"2",
  385. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  386. @"sign":sign
  387. };
  388. [YBNetworking postWithUrl:@"Buyer.goodsOrderPay" Dic:subdic Suc:^(int code, id info, NSString *msg) {
  389. if (code == 0) {
  390. [MBProgressHUD hideHUD];
  391. NSDictionary *dict = [info firstObject];
  392. //调起微信支付
  393. NSString *times = [dict objectForKey:@"timestamp"];
  394. PayReq* req = [[PayReq alloc] init];
  395. req.partnerId = [dict objectForKey:@"partnerid"];
  396. NSString *pid = [NSString stringWithFormat:@"%@",[dict objectForKey:@"prepayid"]];
  397. if ([pid isEqual:[NSNull null]] || pid == NULL || [pid isEqual:@"null"]) {
  398. pid = @"123";
  399. }
  400. req.prepayId = pid;
  401. req.nonceStr = [dict objectForKey:@"noncestr"];
  402. req.timeStamp = times.intValue;
  403. req.package = [dict objectForKey:@"package"];
  404. req.sign = [dict objectForKey:@"sign"];
  405. [WXApi sendReq:req completion:^(BOOL success) {
  406. NSLog(@"wxapi调用 %d",success);
  407. }];
  408. }
  409. else{
  410. [MBProgressHUD hideHUD];
  411. }
  412. } Fail:^(id fail) {
  413. [MBProgressHUD hideHUD];
  414. }];
  415. }
  416. -(void)onResp:(BaseResp *)resp{
  417. //支付返回结果,实际支付结果需要去微信服务器端查询
  418. NSString *strMsg = [NSString stringWithFormat:@"支付结果"];
  419. switch (resp.errCode) {
  420. case WXSuccess:
  421. strMsg = @"支付结果:成功!";
  422. NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
  423. // [self requestData];
  424. [MBProgressHUD hideHUD];
  425. [MBProgressHUD showError:YZMsg(@"支付成功")];
  426. // [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  427. if (self.hideEvent) {
  428. self.hideEvent(YES);
  429. }
  430. break;
  431. default:
  432. strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
  433. NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
  434. [MBProgressHUD hideHUD];
  435. [self closeClick];
  436. break;
  437. }
  438. }
  439. //微信支付*****************************************************************************************************************
  440. //支付宝支付*****************************************************************************************************************
  441. - (void)doAlipayPay
  442. {
  443. NSString *partner = _aliapp_partner;
  444. NSString *seller = _aliapp_seller_id;
  445. NSString *privateKey = _aliapp_key_ios;
  446. //partner和seller获取失败,提示
  447. if ([partner length] == 0 ||
  448. [seller length] == 0 ||
  449. [privateKey length] == 0){
  450. [MBProgressHUD showError:YZMsg(@"缺少partner或者seller或者私钥")];
  451. return;
  452. }
  453. /*
  454. *生成订单信息及签名
  455. */
  456. //将商品信息赋予AlixPayOrder的成员变量
  457. Order *order = [[Order alloc] init];
  458. order.partner = partner;
  459. order.seller = seller;
  460. //获取订单id
  461. //将商品信息拼接成字符串
  462. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"orderid":_orderIdStr,@"type":@"1",@"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  463. NSString *sign = [PublicObj sortString:signdic];
  464. NSDictionary *subdic = @{
  465. @"uid":[Config getOwnID],
  466. @"token":[Config getOwnToken],
  467. @"orderid":_orderIdStr,
  468. @"type":@"1",
  469. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  470. @"sign":sign
  471. };
  472. [YBNetworking postWithUrl:@"Buyer.goodsOrderPay" Dic:subdic Suc:^(int code, id info, NSString *msg) {
  473. if (code == 0) {
  474. NSString *infos = [[info firstObject] valueForKey:@"orderid"];
  475. order.tradeNO = infos;
  476. order.notifyURL = [h5url stringByAppendingString:@"/appapi/shoppay/notify_ali"];
  477. order.amount = _priceStr;
  478. order.productName = [NSString stringWithFormat:@"%@%@",_priceStr,_shopNameStr];
  479. order.productDescription = @"productDescription";
  480. //以下配置信息是默认信息,不需要更改.
  481. order.service = @"mobile.securitypay.pay";
  482. order.paymentType = @"1";
  483. order.inputCharset = @"utf-8";
  484. order.itBPay = @"30m";
  485. order.showUrl = @"m.alipay.com";
  486. //应用注册scheme,在AlixPayDemo-Info.plist定义URL types,用于快捷支付成功后重新唤起商户应用
  487. NSString *appScheme = [[NSBundle mainBundle] bundleIdentifier];
  488. //将商品信息拼接成字符串
  489. NSString *orderSpec = [order description];
  490. NSLog(@"orderSpec = %@",orderSpec);
  491. //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
  492. id<DataSigner> signer = CreateRSADataSigner(privateKey);
  493. NSString *signedString = [signer signString:orderSpec];
  494. //将签名成功字符串格式化为订单字符串,请严格按照该格式
  495. NSString *orderString = nil;
  496. if (signedString != nil) {
  497. orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
  498. orderSpec, signedString, @"RSA"];
  499. [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
  500. NSLog(@"reslut = %@",resultDic);
  501. NSInteger resultStatus = [resultDic[@"resultStatus"] integerValue];
  502. NSLog(@"#######%ld",(long)resultStatus);
  503. // NSString *publicKey = alipaypublicKey;
  504. NSLog(@"支付状态信息---%ld---%@",resultStatus,[resultDic valueForKey:@"memo"]);
  505. // 是否支付成功
  506. if (9000 == resultStatus) {
  507. /*
  508. *用公钥验证签名
  509. */
  510. [MBProgressHUD showError:YZMsg(@"支付成功")];
  511. if (self.hideEvent) {
  512. self.hideEvent(YES);
  513. }
  514. }else{
  515. [self closeClick];
  516. }
  517. }];
  518. }
  519. }
  520. } Fail:^(id fail) {
  521. }];
  522. }
  523. /*余额支付*/
  524. -(void)doBalance{
  525. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"orderid":_orderIdStr,@"type":@"3",@"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  526. NSString *sign = [PublicObj sortString:signdic];
  527. NSDictionary *subdic = @{
  528. @"uid":[Config getOwnID],
  529. @"token":[Config getOwnToken],
  530. @"orderid":_orderIdStr,
  531. @"type":@"3",
  532. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  533. @"sign":sign
  534. };
  535. [YBNetworking postWithUrl:@"Buyer.goodsOrderPay" Dic:subdic Suc:^(int code, id info, NSString *msg) {
  536. if (code == 0) {
  537. [MBProgressHUD showError:msg];
  538. if (self.hideEvent) {
  539. self.hideEvent(YES);
  540. }
  541. }else{
  542. [MBProgressHUD showError:msg];
  543. }
  544. } Fail:^(id fail) {
  545. }];
  546. }
  547. @end