APViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. //
  2. // APViewController.m
  3. // AliSDKDemo
  4. //
  5. // Created by 方彬 on 11/29/13.
  6. // Copyright (c) 2013 Alipay.com. All rights reserved.
  7. //
  8. #import "APViewController.h"
  9. #import "EvaluationAndPayVC.h"
  10. #import "InputPasswordVC.h"
  11. #import "Order.h"
  12. #import "DataSigner.h"
  13. #import <AlipaySDK/AlipaySDK.h>
  14. #import "WXApi.h"
  15. //----
  16. #import "payRequsestHandler.h"
  17. @implementation Product
  18. @end
  19. @interface APViewController ()<UIAlertViewDelegate>
  20. {
  21. UIView *skipView;
  22. UIImageView *aliImg;
  23. UIImageView *webImg;
  24. UIImageView *balanceImg;
  25. UIScrollView *mainScrollView;
  26. UILabel *balanceLabel;
  27. NSInteger whichPay;
  28. CGFloat useMoney;
  29. }
  30. @end
  31. @implementation APViewController
  32. - (void)viewDidLoad
  33. {
  34. [super viewDidLoad];
  35. [self myInit];
  36. [self getMyAccount];
  37. }
  38. #pragma mark -
  39. -(void)myInit
  40. {
  41. self.view.backgroundColor = backGroundColor;
  42. self.title = @"支付";
  43. [self configNavigationBar];
  44. whichPay = 0;
  45. NSString *timeLength = _orderDic[@"MINUTE"];
  46. int hour = [timeLength intValue]/60;
  47. int min = [timeLength intValue]%60;
  48. timeLength = [NSString stringWithFormat:@"%d时%d分",hour,min];
  49. NSString *moneyString = _orderDic[@"RO_MONEY"];
  50. if (moneyString.length < 1) {
  51. moneyString = @"0";
  52. }
  53. mainScrollView = [[UIScrollView alloc] initWithFrame:kFrame];
  54. mainScrollView.height -= kNavOffSet;
  55. mainScrollView.backgroundColor = backGroundColor;
  56. [self.view addSubview:mainScrollView];
  57. NSArray *titleString = @[@"开始时间",@"结束时间",@"练车时长",@"教练姓名",@"练车单价",@"应付金额"];
  58. NSArray *contentString = @[_orderDic[@"RO_START_TIME"],_orderDic[@"RO_END_TIME"],timeLength,_orderDic[@"RO_COACH_NAME"],[NSString stringWithFormat:@"%@元/小时",_orderDic[@"PRICE"]],[NSString stringWithFormat:@"%@元",moneyString]];
  59. CGFloat x,y,w,h;
  60. x = 20;
  61. y = 10;
  62. w = 100;
  63. h = 41;
  64. UIView *labelBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h*6)];
  65. labelBar.backgroundColor = [UIColor whiteColor];
  66. [mainScrollView addSubview:labelBar];
  67. y = 0;
  68. for (int i = 0; i < 6; i ++) {
  69. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + i*h, w, h)];
  70. [label setText:titleString[i] Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  71. [labelBar addSubview:label];
  72. label = [[UILabel alloc] initWithFrame:CGRectMake(x + w, y + i*h, kSize.width - x - w - 20, h)];
  73. [label setText:contentString[i] Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentRight];
  74. [labelBar addSubview:label];
  75. if (i != 5) {
  76. //i == 5的时候 不用画线了
  77. [label addViewWithRect:CGRectMake(10, y + 40*(i+1) - 1, kSize.width - 20, 1)];
  78. }
  79. }
  80. //支付
  81. y += 6*h + 40;
  82. UIView *btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 60)];
  83. btnBar.backgroundColor = [UIColor whiteColor];
  84. [mainScrollView addSubview:btnBar];
  85. //scroll的长度
  86. [mainScrollView setContentSize:CGSizeMake(kSize.width, btnBar.y + btnBar.height)];
  87. //余额支付
  88. y = 5;
  89. w = h = 50;
  90. UIImageView *balancePayImage = [[UIImageView alloc] setxywh];
  91. balancePayImage.image = [UIImage imageNamed:@"BalancePay.png"];
  92. [btnBar addSubview:balancePayImage];
  93. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, kSize.width - x - 80, h)];
  94. [label setText:@"余额" Font:Font17 TextColor:contentTextColor];
  95. [btnBar addSubview:label];
  96. balanceLabel = label;
  97. //支付按钮
  98. UIButton *payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  99. payBtn.frame = CGRectMake(0, kSize.height - 60 - kNavOffSet, kSize.width, 60);
  100. payBtn.backgroundColor = defGreen;
  101. [payBtn setTitle:@"支付" textColor:[UIColor whiteColor] font:FontLarger fotState:UIControlStateNormal];
  102. [payBtn target:self tag:7];
  103. [self.view addSubview:payBtn];
  104. /*
  105. //支付方式
  106. y += 6*h + 20;
  107. UIView *btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 300)];
  108. btnBar.backgroundColor = [UIColor whiteColor];
  109. [mainScrollView addSubview:btnBar];
  110. y = 5;
  111. h = 36;
  112. w = kSize.width - 60;
  113. UILabel *label = [[UILabel alloc] setxywh];
  114. [label setText:@"请选择支付方式" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  115. [btnBar addSubview:label];
  116. [label addViewWithRect:CGRectMake(10, y + h - 1, kSize.width - 20, 1)];
  117. //余额支付
  118. y += h + 5;
  119. w = h = 50;
  120. UIImageView *balancePayImage = [[UIImageView alloc] setxywh];
  121. balancePayImage.image = [UIImage imageNamed:@"BalancePay.png"];
  122. [btnBar addSubview:balancePayImage];
  123. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, 200, h)];
  124. [label setText:@"余额" Font:Font17 TextColor:contentTextColor];
  125. [btnBar addSubview:label];
  126. balanceLabel = label;
  127. balanceImg = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 50, y + 10, 30, 30)];
  128. balanceImg.image = [UIImage imageNamed:@"paySelect.png"];
  129. [btnBar addSubview:balanceImg];
  130. UIButton *payBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, y - 5, kSize.width, 60)];
  131. [payBtn setBackgroundColor:[UIColor clearColor]];
  132. [payBtn target:self tag:6];
  133. [btnBar addSubview:payBtn];
  134. //支付宝
  135. y += 61;
  136. [label addViewWithRect:CGRectMake(10, y - 6, kSize.width - 20, 1)];
  137. UIImageView *aliImage = [[UIImageView alloc] setxywh];
  138. aliImage.image = [UIImage imageNamed:@"AliPay.png"];
  139. [btnBar addSubview:aliImage];
  140. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, 100, h)];
  141. [label setText:@"支付宝" Font:Font17 TextColor:contentTextColor];
  142. [btnBar addSubview:label];
  143. aliImg = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 50, y + 10, 30, 30)];
  144. aliImg.image = [UIImage imageNamed:@"paySelect.png"];
  145. [btnBar addSubview:aliImg];
  146. payBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, y - 5, kSize.width, 60)];
  147. [payBtn setBackgroundColor:[UIColor clearColor]];
  148. [payBtn target:self tag:4];
  149. [btnBar addSubview:payBtn];
  150. //微信
  151. y += 61;
  152. [label addViewWithRect:CGRectMake(10, y - 6, kSize.width - 20, 1)];
  153. UIImageView *webImage = [[UIImageView alloc] setxywh];
  154. webImage.image = [UIImage imageNamed:@"WebPay.png"];
  155. [btnBar addSubview:webImage];
  156. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 60, y, 100, h)];
  157. [label setText:@"微信" Font:Font17 TextColor:contentTextColor];
  158. [btnBar addSubview:label];
  159. webImg = [[UIImageView alloc] initWithFrame:CGRectMake(kSize.width - 50, y + 10, 30, 30)];
  160. webImg.image = [UIImage imageNamed:@"paySelect.png"];
  161. [btnBar addSubview:webImg];
  162. payBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, y - 5, kSize.width, 60)];
  163. [payBtn setBackgroundColor:[UIColor clearColor]];
  164. [payBtn target:self tag:5];
  165. [btnBar addSubview:payBtn];
  166. y += 55;
  167. [label addViewWithRect:CGRectMake(0, y, kSize.width, 17) Color:backGroundColor];
  168. y += 17;
  169. //支付按钮
  170. payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  171. payBtn.frame = CGRectMake(0, y, kSize.width, 60);
  172. payBtn.backgroundColor = defGreen;
  173. [payBtn setTitle:@"支付" textColor:[UIColor whiteColor] font:FontLarger fotState:UIControlStateNormal];
  174. [payBtn target:self tag:7];
  175. [btnBar addSubview:payBtn];
  176. */
  177. //搞不懂 这15的距离哪里来的
  178. // [mainScrollView setContentSize:CGSizeMake(kSize.width, btnBar.y + btnBar.height + 15)];
  179. }
  180. -(void)clickToWebPay
  181. {
  182. // NSString *res = [self jumpToBizPay];
  183. // //如果返回有文字 支付失败
  184. // if( ![@"" isEqual:res] ){
  185. // ShowMsg(res);
  186. // }
  187. //这里调用我自己写的catagoary中的方法,方法里集成了微信支付的步骤,并会发送一个通知,用来传递是否支付成功的信息
  188. //这里填写的两个参数是后台会返回给你的
  189. [self payTheMoneyUseWeChatPayWithPrepay_id:@"这里填写后台返回的Prepay_id" nonce_str:@"这里填写后台给你返回的nonce_str"];
  190. //所以这里添加一个监听,用来接收是否成功的消息
  191. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weChatPayResultNoti:) name:WX_PAY_RESULT object:nil];
  192. }
  193. //微信支付付款成功失败
  194. -(void)weChatPayResultNoti:(NSNotification *)noti{
  195. if ([[noti object] isEqualToString:IS_SUCCESSED]) {
  196. //NSLog(@"支付成功");
  197. //在这里填写支付成功之后你要做的事情
  198. }else{
  199. //NSLog(@"支付失败");
  200. }
  201. //上边添加了监听,这里记得移除
  202. [[NSNotificationCenter defaultCenter] removeObserver:self name:WX_PAY_RESULT object:nil];
  203. }
  204. - (void)payTheMoneyUseWeChatPayWithPrepay_id:(NSString *)prepay_id nonce_str:(NSString *)nonce_str
  205. {
  206. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  207. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  208. // 设置时间格式
  209. formatter.dateFormat = @"yyyyMMddHHmmss";
  210. NSString *str = [formatter stringFromDate:[NSDate date]];
  211. //NSLog(@"%@",str);
  212. //调起微信支付···
  213. PayReq* req = [[PayReq alloc] init];
  214. req.partnerId = MCH_ID;
  215. req.prepayId = [NSString stringWithFormat:@"%@",prepay_id];
  216. req.nonceStr = [NSString stringWithFormat:@"%@",nonce_str];
  217. req.timeStamp = [str intValue];
  218. req.package = @"Sign=WXpay";
  219. //创建支付签名对象
  220. payRequsestHandler *req1 =[[payRequsestHandler alloc] init];
  221. //初始化支付签名对象
  222. [req1 init:APP_ID mch_id:MCH_ID];
  223. //设置密钥
  224. [req1 setKey:PARTNER_ID];
  225. //第二次签名参数列表
  226. NSMutableDictionary *signParams = [NSMutableDictionary dictionary];
  227. [signParams setObject: APP_ID forKey:@"appid"];
  228. [signParams setObject: [NSString stringWithFormat:@"%@",nonce_str] forKey:@"noncestr"];
  229. [signParams setObject: @"Sign=WXpay" forKey:@"package"];
  230. [signParams setObject: MCH_ID forKey:@"partnerid"];
  231. [signParams setObject: [NSString stringWithFormat:@"%d",str.intValue] forKey:@"timestamp"];
  232. [signParams setObject: [NSString stringWithFormat:@"%@",prepay_id] forKey:@"prepayid"];
  233. //生成签名
  234. NSString *signStr = [req1 createMd5Sign:signParams];
  235. //NSLog(@"%@",signStr);
  236. req.sign =signStr;
  237. //NSLog(@"%@",req);
  238. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noti:) name:@"weixin_pay_result" object:nil];
  239. [WXApi sendReq:req completion:nil];
  240. }
  241. //微信付款成功失败
  242. -(void)noti:(NSNotification *)noti{
  243. //NSLog(@"%@",noti);
  244. if ([[noti object] isEqualToString:@"成功"]) {
  245. [[NSNotificationCenter defaultCenter] postNotificationName:WX_PAY_RESULT object:IS_SUCCESSED];
  246. }else{
  247. [[NSNotificationCenter defaultCenter] postNotificationName:WX_PAY_RESULT object:IS_FAILED];
  248. }
  249. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"weixin_pay_result" object:nil];
  250. }
  251. - (NSString *)jumpToBizPay {
  252. //判断用户是否安装微信 是否支持微信支付
  253. if (![WXApi isWXAppInstalled]) {
  254. return @"您还未安装微信,无法发起微信支付";
  255. }
  256. if (![WXApi isWXAppSupportApi]){
  257. return @"您的微信暂不支持支付";
  258. }
  259. //============================================================
  260. // V3&V4支付流程实现
  261. // 注意:参数配置请查看服务器端Demo
  262. // 更新时间:2015年11月20日
  263. //============================================================
  264. //http://218.6.66.181:9999/jxglpt/admin/weixinPay/appNotify
  265. NSString *urlString = @"http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=ios";
  266. //解析服务端返回json数据
  267. NSError *error;
  268. //加载一个NSURL对象
  269. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
  270. //将请求的url数据放到NSData对象中
  271. NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  272. if ( response != nil) {
  273. NSMutableDictionary *dict = NULL;
  274. //IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中
  275. dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
  276. //NSLog(@"url:%@",urlString);
  277. if(dict != nil){
  278. NSMutableString *retcode = [dict objectForKey:@"retcode"];
  279. if (retcode.intValue == 0){
  280. NSMutableString *stamp = [dict objectForKey:@"timestamp"];
  281. //调起微信支付
  282. PayReq* req = [[PayReq alloc] init];
  283. req.partnerId = [dict objectForKey:@"partnerid"];
  284. req.prepayId = [dict objectForKey:@"prepayid"];
  285. req.nonceStr = [dict objectForKey:@"noncestr"];
  286. req.timeStamp = stamp.intValue;
  287. req.package = [dict objectForKey:@"package"];
  288. req.sign = [dict objectForKey:@"sign"];
  289. [WXApi sendReq:req completion:nil];
  290. //日志输出
  291. //NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@",[dict objectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign );
  292. return @"";
  293. }else{
  294. return [dict objectForKey:@"retmsg"];
  295. }
  296. }else{
  297. return @"服务器返回错误,未获取到json对象";
  298. }
  299. }else{
  300. return @"服务器返回错误";
  301. }
  302. }
  303. -(void)clickToAliPay
  304. {
  305. /*
  306. *商户的唯一的parnter和seller。
  307. *签约后,支付宝会为每个商户分配一个唯一的 parnter 和 seller。
  308. */
  309. /*============================================================================*/
  310. /*=======================需要填写商户app申请的===================================*/
  311. /*============================================================================*/
  312. //这个要写在一个按钮的方法中
  313. NSString *partner = aliPartner;
  314. NSString *seller = aliSeller;
  315. NSString *privateKey = aliPrivateKey;
  316. /*============================================================================*/
  317. /*============================================================================*/
  318. /*============================================================================*/
  319. //partner和seller获取失败,提示
  320. if ([partner length] == 0 ||
  321. [seller length] == 0 ||
  322. [privateKey length] == 0)
  323. {
  324. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
  325. message:@"支付发生错误 错误码1000"
  326. delegate:nil
  327. cancelButtonTitle:@"确定"
  328. otherButtonTitles:nil];
  329. [alert show];
  330. return;
  331. }
  332. /*
  333. *生成订单信息及签名
  334. */
  335. //将商品信息赋予AlixPayOrder的成员变量
  336. Order *order = [[Order alloc] init];
  337. order.partner = partner;
  338. order.sellerID = seller;
  339. order.outTradeNO = _orderDic[@"RO_ORDER_NO"]; //订单ID(由商家自行制定)
  340. // order.subject = [NSString stringWithCString:[sub UTF8String] encoding:NSUnicodeStringEncoding]; //商品标题
  341. // order.body = [bod stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];; //商品描述
  342. order.subject = @"优易学车,先学后付交易"; //商品标题
  343. order.body = @"详细描述"; //商品描述
  344. //dansonmark 上架前一定要改正 商品价格 和通知地址 都是钱啊
  345. //_orderDic[@"RO_MONEY"]
  346. order.totalFee = _orderDic[@"RO_MONEY"]; //商品价格
  347. order.notifyURL = aliPayNotify; //回调URL
  348. order.service = @"mobile.securitypay.pay";
  349. order.paymentType = @"1";
  350. order.inputCharset = @"utf-8";
  351. order.itBPay = @"30m";
  352. order.showURL = @"m.alipay.com";
  353. //应用注册scheme,在AlixPayDemo-Info.plist定义URL types 原来支付宝这个是自己定义的、、
  354. NSString *appScheme = aliPayScheme;
  355. //将商品信息拼接成字符串
  356. NSString *orderSpec = [order description];
  357. //NSLog(@"orderSpec = %@",orderSpec);
  358. //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
  359. id<DataSigner> signer = CreateRSADataSigner(privateKey);
  360. NSString *signedString = [signer signString:orderSpec];
  361. //将签名成功字符串格式化为订单字符串,请严格按照该格式
  362. NSString *orderString = nil;
  363. if (signedString != nil) {
  364. orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
  365. orderSpec, signedString, @"RSA"];
  366. //NSLog(@"---->%@",orderString);
  367. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AliPayResultNoti:) name:ALI_PAY_RESULT object:nil];
  368. [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
  369. //NSLog(@"reslutAP页面 = %@",resultDic);
  370. //是9000代表支付成功
  371. if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
  372. //支付成功
  373. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
  374. }else{
  375. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
  376. }
  377. }];
  378. }
  379. }
  380. //支付宝支付成功失败
  381. -(void)AliPayResultNoti:(NSNotification *)noti
  382. {
  383. //NSLog(@"%@",noti);
  384. skipView = [[UIView alloc] initWithFrame:kFrame];
  385. skipView.backgroundColor = backGroundColor;
  386. [self.view addSubview:skipView];
  387. if ([[noti object] isEqualToString:ALIPAY_SUCCESSED]) {
  388. //在这里填写支付成功之后你要做的事情
  389. UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paySuccess.png"]];
  390. img.frame = CGRectMake(kSize.width *0.375, 100, kSize.width *0.25, kSize.width *0.25);
  391. [skipView addSubview:img];
  392. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100+kSize.width *0.25, kSize.width, 40)];
  393. [label setText:@"支付成功" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  394. [skipView addSubview:label];
  395. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200+kSize.width *0.25, kSize.width - 40, 50)];
  396. [btn setTitle:@"确定" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
  397. btn.backgroundColor=[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1];
  398. [btn target:self tag:1];
  399. [skipView addSubview:btn];
  400. }else{
  401. //支付失败
  402. UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"payFault.png"]];
  403. img.frame = CGRectMake(kSize.width *0.375, 100, kSize.width *0.25, kSize.width *0.25);
  404. [skipView addSubview:img];
  405. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100+kSize.width *0.25, kSize.width, 40)];
  406. [label setText:@"支付失败,请重新支付" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  407. [skipView addSubview:label];
  408. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200+kSize.width *0.25, kSize.width/2.0 - 35, 50)];
  409. [btn setTitle:@"查看订单" textColor:[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1] font:Font17 fotState:UIControlStateNormal];
  410. [btn borderColor:[UIColor colorWithRed:230/255.0 green:84/255.0 blue:112/255.0 alpha:1] width:1 cornorRadios:5];
  411. [btn target:self tag:2];
  412. [skipView addSubview:btn];
  413. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 15, 200+kSize.width *0.25, kSize.width/2.0 - 35, 50)];
  414. [btn setTitle:@"重新支付" textColor:contentTextColor font:Font17 fotState:UIControlStateNormal];
  415. [btn borderColor:contentTextColor width:1 cornorRadios:5];
  416. [btn target:self tag:3];
  417. [skipView addSubview:btn];
  418. }
  419. //上边添加了监听,这里记得移除
  420. [[NSNotificationCenter defaultCenter] removeObserver:self name:ALI_PAY_RESULT object:nil];
  421. }
  422. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  423. {
  424. if (buttonIndex == alertView.cancelButtonIndex) {
  425. [self.navigationController popViewControllerAnimated:YES];
  426. }else{
  427. EvaluationAndPayVC *vc = [[EvaluationAndPayVC alloc] init];
  428. vc.isFinishEva = NO;
  429. //vc.isFromPayVC = YES;
  430. vc.dataDic = _orderDic;
  431. [self navPushHideTabbarToVC:vc];
  432. }
  433. }
  434. -(void)btnClick:(UIButton *)sender
  435. {
  436. if (sender.tag < 4) {
  437. [skipView removeFromSuperview];
  438. }
  439. if (sender.tag == 1) {
  440. //支付成功的返回按钮1
  441. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"支付成功,是否评价?" delegate:self cancelButtonTitle:@"暂不评价" otherButtonTitles:@"确认", nil];
  442. [alertView show];
  443. }
  444. if (sender.tag == 2) {
  445. //支付失败查看订单的页面3
  446. [self.navigationController popViewControllerAnimated:YES];
  447. }
  448. if (sender.tag == 3) {
  449. //支付失败重新支付
  450. switch (whichPay) {
  451. case 4:
  452. [self clickToAliPay];
  453. break;
  454. case 5:
  455. [self clickToWebPay];
  456. break;
  457. default:
  458. //这里返回到订单页面 并且提示
  459. break;
  460. }
  461. }
  462. if (sender.tag == 4) {
  463. //支付宝
  464. whichPay = 4;
  465. aliImg.image = [UIImage imageNamed:@"paySelected.png"];
  466. webImg.image = [UIImage imageNamed:@"paySelect.png"];
  467. balanceImg.image = [UIImage imageNamed:@"paySelect.png"];
  468. }
  469. if (sender.tag == 5) {
  470. //微信
  471. whichPay = 5;
  472. aliImg.image = [UIImage imageNamed:@"paySelect.png"];
  473. webImg.image = [UIImage imageNamed:@"paySelected.png"];
  474. balanceImg.image = [UIImage imageNamed:@"paySelect.png"];
  475. }
  476. if (sender.tag == 6) {
  477. //余额
  478. whichPay = 6;
  479. aliImg.image = [UIImage imageNamed:@"paySelect.png"];
  480. webImg.image = [UIImage imageNamed:@"paySelect.png"];
  481. balanceImg.image = [UIImage imageNamed:@"paySelected.png"];
  482. }
  483. if (sender.tag == 7){
  484. if ([_orderDic[@"RO_MONEY"] floatValue] > useMoney) {
  485. ShowMsg(@"余额不足,请充值");
  486. }else{
  487. InputPasswordVC *inputVC = [[InputPasswordVC alloc] init];
  488. [inputVC finishInput:^(NSString *yesorno) {
  489. if ([yesorno isEqualToString:@"TRUE"]) {
  490. [self saveAccountRecharge];
  491. }
  492. }];
  493. [self navPushHideTabbarToVC:inputVC];
  494. }
  495. // switch (whichPay){
  496. // case 4:
  497. // [self clickToAliPay];
  498. // break;
  499. // case 5:
  500. // ShowMsg(@"暂不支持微信支付,敬请期待");
  501. // //[self clickToWebPay];
  502. // break;
  503. // case 6://余额支付
  504. // {
  505. // if ([_orderDic[@"RO_MONEY"] floatValue] > useMoney) {
  506. // ShowMsg(@"余额不足,请充值或使用其他方式付款");
  507. // }else{
  508. // [self saveAccountRechargeAsync];
  509. // }
  510. // }
  511. // break;
  512. //
  513. // default:
  514. // ShowMsg(@"请选择支付方式!");
  515. // break;
  516. // }
  517. }
  518. }
  519. #pragma mark 数据请求
  520. //获取我的账户
  521. -(void)getMyAccount
  522. {
  523. if (![Util connectedToNetWork]) {
  524. showMsgUnconnect();
  525. return;
  526. }
  527. NSMutableArray *arr=[NSMutableArray array];
  528. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  529. NSString* method = @"getMyAccount";
  530. [MBProgressHUD showLoadToView:self.view];
  531. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  532. [MBProgressHUD hideHUDForView:self.view];
  533. if (!root) {
  534. ShowMsgFailed();
  535. return;
  536. }
  537. if ([root[@"code"] isEqualToString:@"1"]) {
  538. ShowMsg(root[@"body"]);
  539. return;
  540. }
  541. /**
  542. LOCKMONEY = 20,
  543. OVERMONEY = 22,
  544. */
  545. if (![root[@"body"] isKindOfClass:[NSDictionary class]])
  546. {
  547. return;
  548. }
  549. CGFloat allF = [[root[@"body"] objectForKey:@"moneyIn"] floatValue];
  550. CGFloat consumeF = [[root[@"body"] objectForKey:@"moneyOut"] floatValue];
  551. useMoney = allF - consumeF;//可用余额
  552. balanceLabel.text = [NSString stringWithFormat:@"我的账户(账户金额%.2f元)",useMoney];
  553. }];
  554. }
  555. //余额支付
  556. -(void)saveAccountRecharge
  557. {
  558. if (![Util connectedToNetWork]) {
  559. showMsgUnconnect();
  560. return;
  561. }
  562. NSMutableArray *arr=[NSMutableArray array];
  563. [arr addPro:@"orderNo" Value:_orderDic[@"RO_ORDER_NO"]];//订单编号
  564. [arr addPro:@"user" Value:defUser.sfzmhm];
  565. [arr addPro:@"money" Value:_orderDic[@"RO_MONEY"]];
  566. NSString* method = @"saveAccountRecharge";
  567. [MBProgressHUD showLoadToView:self.view];
  568. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  569. [MBProgressHUD hideHUDForView:self.view];
  570. if (!root) {
  571. ShowMsg(@"交易异常,请查看账户余额");
  572. return;
  573. }
  574. if ([root[@"code"] isEqualToString:@"1"]) {
  575. ShowMsg(root[@"body"]);
  576. return;
  577. }
  578. ShowMsg(root[@"body"]);
  579. [self.navigationController popViewControllerAnimated:YES];
  580. }];
  581. }
  582. @end;