JXPayViewController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. //
  2. // JXPayViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/3/6.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXPayViewController.h"
  9. #import "JXCollectMoneyVC.h"
  10. #import "QRImage.h"
  11. #import "JXScanQRViewController.h"
  12. #import "JXInputMoneyVC.h"
  13. #import "JXVerifyPayVC.h"
  14. #import "JXPayPasswordVC.h"
  15. #define HEIGHT 50
  16. @interface JXPayViewController ()<JXPayPasswordVCDelegate>
  17. @property (nonatomic, strong) UIButton *payBtn;
  18. @property (nonatomic, strong) UIButton *getBtn;
  19. @property (nonatomic, strong) UIButton *scanBtn;
  20. @property (nonatomic, strong) UIImageView *backImageView;
  21. @property (nonatomic, strong) UIView *btnBaseView;
  22. @property (nonatomic, strong) UILabel *titleLab;
  23. // 付款
  24. @property (nonatomic, strong) UIImageView *barCode;// 条形码
  25. @property (nonatomic, strong) UIImageView *payQrCode;// 二维码
  26. @property (nonatomic, strong) NSString *codeStr;
  27. @property (nonatomic, strong) NSTimer *timer;
  28. @property (nonatomic, strong) UIView *payBaseView;
  29. // 收款
  30. @property (nonatomic, strong) NSString *money;
  31. @property (nonatomic, strong) NSString *desStr;
  32. @property (nonatomic, strong) UIImageView *getQrCode;
  33. @property (nonatomic, strong) UILabel *leftLabel;
  34. @property (nonatomic, strong) UILabel *rigLabel;
  35. @property (nonatomic, strong) UIView *baseView;
  36. @property (nonatomic, strong) UILabel *moneyLab;
  37. @property (nonatomic, strong) UILabel *descLab;
  38. @property (nonatomic, strong) UILabel *barCodeLab;
  39. @property (nonatomic, strong) JXVerifyPayVC * verVC;
  40. @end
  41. @implementation JXPayViewController
  42. // GCD定时器
  43. static dispatch_source_t _timer;
  44. - (instancetype)init {
  45. if (self = [super init]) {
  46. }
  47. return self;
  48. }
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. self.heightHeader = 0;
  52. self.heightFooter = 0;
  53. [self createHeadAndFoot];
  54. [self setupNav];
  55. [self setupViews];
  56. [self setupGetMoneyViews];
  57. [self setupFootView];
  58. [g_notify addObserver:self selector:@selector(notifyPaymentGet:) name:kXMPPMessageQrPaymentNotification object:nil];
  59. self.tableBody.scrollEnabled = !BIG_DEVICE;
  60. }
  61. - (void)notifyPaymentGet:(NSNotification *)noti {
  62. JXMessageObject *msg = noti.object;
  63. if ([msg.type intValue] == kWCMessageTypePaymentOut) {
  64. [g_server showMsg:Localized(@"JX_PaymentToFriend")];
  65. [self updatePayQrCode];
  66. }
  67. if ([msg.type intValue] == kWCMessageTypeReceiptGet) {
  68. [g_server showMsg:Localized(@"JX_PaymentReceived")];
  69. [self updateGetQrCode];
  70. }
  71. }
  72. - (void)viewWillAppear:(BOOL)animated {
  73. [super viewWillAppear:animated];
  74. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  75. }
  76. - (void)viewDidAppear:(BOOL)animated {
  77. [super viewDidAppear:animated];
  78. // [self startTimer];
  79. }
  80. - (void)viewDidDisappear:(BOOL)animated {
  81. [super viewDidDisappear:animated];
  82. [self stopTimer];
  83. }
  84. - (void)setupFootView {
  85. CGFloat w = JX_SCREEN_WIDTH/3;
  86. CGFloat h = 48;
  87. CGFloat y = CGRectGetMaxY(_payBaseView.frame)+33;
  88. _payBtn = [self createButtonWithFrame:CGRectMake(0,y, w, h) title:@"付款码" icon:@"payment_code_icon" selected:@"payment_code_select_icon" click:@selector(onCurrentVC:)];
  89. _getBtn = [self createButtonWithFrame:CGRectMake(CGRectGetMaxX(_payBtn.frame), y, w, h) title:@"收款码" icon:@"collection_code_icon" selected:@"collection_code_selecet_icon" click:@selector(onCollectMoney:)];
  90. _scanBtn = [self createButtonWithFrame:CGRectMake(CGRectGetMaxX(_getBtn.frame),y, w, h) title:@"扫码付" icon:@"sweep_code_icon" selected:@"sweep_code_selecet_icon" click:@selector(onScanQrCodeVC)];
  91. self.tableBody.backgroundColor = [UIColor clearColor];
  92. _backImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
  93. _backImageView.image = [UIImage imageNamed:@"background_green"];
  94. [self.view insertSubview:_backImageView belowSubview:self.tableBody];
  95. if (!BIG_DEVICE) {
  96. if (y > self.tableBody.frame.size.height) {
  97. self.tableBody.contentSize = CGSizeMake(0, y);
  98. }
  99. }
  100. [self onCurrentVC:_payBtn];
  101. }
  102. - (void)setupNav {
  103. UIView *nav = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_TOP)];
  104. nav.backgroundColor = [UIColor clearColor];
  105. [self.view addSubview:nav];
  106. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 46, 46, 46)];
  107. [btn setBackgroundImage:[[UIImage imageNamed:@"title_back_black_big"] imageWithTintColor:[UIColor whiteColor]] forState:UIControlStateNormal];
  108. [btn addTarget:self action:@selector(actionQuit) forControlEvents:UIControlEventTouchUpInside];
  109. [self.view addSubview:btn];
  110. UILabel *p = [[UILabel alloc]initWithFrame:CGRectMake(40, JX_SCREEN_TOP - 32, JX_SCREEN_WIDTH-40*2, 20)];
  111. p.backgroundColor = [UIColor clearColor];
  112. p.textAlignment = NSTextAlignmentCenter;
  113. p.textColor = [UIColor whiteColor];
  114. p.text = Localized(@"JX_Receiving");
  115. p.font = SYSFONT(18);
  116. [nav addSubview:p];
  117. _titleLab = p;
  118. }
  119. - (void)setupViews {
  120. _payBaseView = [[UIView alloc] initWithFrame:CGRectMake(28, JX_SCREEN_TOP+60, JX_SCREEN_WIDTH-28*2, 440)];
  121. _payBaseView.backgroundColor = [UIColor whiteColor];
  122. _payBaseView.layer.masksToBounds = YES;
  123. _payBaseView.layer.cornerRadius = 7.f;
  124. _payBaseView.clipsToBounds = NO;
  125. [self.tableBody addSubview:_payBaseView];
  126. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake((_payBaseView.frame.size.width-80)/2, -40, 80, 80)];
  127. [_payBaseView addSubview:icon];
  128. [g_server getHeadImageLarge:g_server.myself.userId userName:g_server.myself.userNickname imageView:icon];
  129. // 添加圆角
  130. CAShapeLayer *circleShape = [CAShapeLayer layer];
  131. circleShape.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 80, 80)].CGPath;
  132. icon.layer.mask = circleShape;
  133. // 添加边距
  134. CAShapeLayer *circleBorder= [CAShapeLayer layer];
  135. circleBorder.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 80, 80)].CGPath;
  136. circleBorder.strokeColor = [UIColor whiteColor].CGColor;
  137. circleBorder.fillColor = [UIColor clearColor].CGColor;
  138. circleBorder.lineWidth = 7.f;
  139. [icon.layer addSublayer:circleBorder];
  140. // 条形码
  141. _barCode = [[UIImageView alloc] initWithFrame:CGRectMake(18, 60, _payBaseView.frame.size.width- 36, 83)];
  142. [_payBaseView addSubview:_barCode];
  143. UILabel *barCodeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_barCode.frame)+15, _payBaseView.frame.size.width, 15)];
  144. barCodeLab.text = Localized(@"JX_PaymentBarCode");
  145. barCodeLab.textColor = HEXCOLOR(0x666666);
  146. barCodeLab.font = SYSFONT(14);
  147. barCodeLab.textAlignment = NSTextAlignmentCenter;
  148. [_payBaseView addSubview:barCodeLab];
  149. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(barCodeLab.frame)+25, _payBaseView.frame.size.width, LINE_WH)];
  150. [_payBaseView addSubview:line];
  151. [self addBorderToLayer2:line];
  152. int lRW = 30;
  153. UIView *leftV = [[UIView alloc] initWithFrame:CGRectMake(-lRW/2-5, CGRectGetMaxY(line.frame)-lRW/2, lRW, lRW)];
  154. leftV.backgroundColor = HEXCOLOR(0x5fcec7);
  155. leftV.layer.masksToBounds = YES;
  156. leftV.layer.cornerRadius = lRW/2;
  157. [_payBaseView addSubview:leftV];
  158. UIView *rightV = [[UIView alloc] initWithFrame:CGRectMake(_payBaseView.frame.size.width - lRW/2+5, CGRectGetMaxY(line.frame)-lRW/2, lRW, lRW)];
  159. rightV.backgroundColor = HEXCOLOR(0x5fcec7);
  160. rightV.layer.masksToBounds = YES;
  161. rightV.layer.cornerRadius = lRW/2;
  162. [_payBaseView addSubview:rightV];
  163. // 二维码
  164. _payQrCode = [[UIImageView alloc] initWithFrame:CGRectMake((_payBaseView.frame.size.width - 190)/2, CGRectGetMaxY(line.frame)+25, 190, 190)];
  165. [_payBaseView addSubview:_payQrCode];
  166. NSData *qrKey = [g_default objectForKey:kMyQRKey];
  167. if (qrKey && qrKey.length > 0) {
  168. long time = (long)[[NSDate date] timeIntervalSince1970];
  169. time = (time *1000 + g_server.timeDifference);
  170. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  171. // 验签
  172. NSMutableString *value = [NSMutableString string];
  173. [value appendString:APIKEY];
  174. [value appendString:g_myself.userId];
  175. [value appendString:g_server.access_token];
  176. [value appendString:salt];
  177. NSData *macData = [g_securityUtil getHMACMD5:[value dataUsingEncoding:NSUTF8StringEncoding] key:qrKey];
  178. NSString *mac = [macData base64EncodedStringWithOptions:0];
  179. [g_server payVerifyQrKeyWithSalt:salt mac:mac toView:self];
  180. // [self updatePayQrCode];
  181. }else {
  182. if ([g_server.myself.isPayPassword boolValue]) {
  183. self.verVC = [JXVerifyPayVC alloc];
  184. self.verVC.type = JXVerifyTypePaymentCode;
  185. self.verVC.RMB = @"";
  186. self.verVC.delegate = self;
  187. self.verVC.didDismissVC = @selector(dismissVerifyPayVC);
  188. self.verVC.didVerifyPay = @selector(didVerifyPay:);
  189. self.verVC = [self.verVC init];
  190. [self.view addSubview:self.verVC.view];
  191. } else {
  192. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  193. JXPayPasswordVC *payPswVC = [JXPayPasswordVC alloc];
  194. payPswVC.delegate = self;
  195. payPswVC.type = JXPayTypeSetupPassword;
  196. payPswVC.enterType = JXEnterTypePayQr;
  197. payPswVC = [payPswVC init];
  198. [g_navigation pushViewController:payPswVC animated:YES];
  199. });
  200. }
  201. }
  202. // 第一次进入更新一下二维码、条形码
  203. // [self updatePayQrCode];
  204. }
  205. - (void)didVerifyPay:(NSString *)sender {
  206. long time = (long)[[NSDate date] timeIntervalSince1970];
  207. time = (time *1000 + g_server.timeDifference)/1000;
  208. NSMutableArray *arr =[NSMutableArray array];
  209. [g_payServer payServerWithAction:act_payGetQrKey param:arr payPassword:sender time:time toView:self];
  210. }
  211. - (void)dismissVerifyPayVC {
  212. [self.verVC.view removeFromSuperview];
  213. }
  214. #pragma mark - 付款
  215. - (void)onCurrentVC:(UIButton *)button {
  216. if (button.selected) {
  217. return;
  218. }
  219. _baseView.hidden = YES;
  220. _btnBaseView.hidden = YES;
  221. _payBaseView.hidden = NO;
  222. [self selectedBtn:_payBtn normal:_getBtn];
  223. _backImageView.image = [UIImage imageNamed:@"background_green"];
  224. self.titleLab.text = @"付款码";
  225. }
  226. #pragma mark - 收钱
  227. - (void)onCollectMoney:(UIButton *)button {
  228. if (button.selected) {
  229. return;
  230. }
  231. _payBaseView.hidden = YES;
  232. _baseView.hidden = NO;
  233. _btnBaseView.hidden = NO;
  234. [self selectedBtn:_getBtn normal:_payBtn];
  235. _backImageView.image = [UIImage imageNamed:@"background_yellow"];
  236. self.titleLab.text = @"收款码";
  237. }
  238. - (void)selectedBtn:(UIButton *)sBtn normal:(UIButton *)nBtn {
  239. sBtn.selected = YES;
  240. nBtn.selected = NO;
  241. for (UIView *sub in sBtn.subviews) {
  242. if ([sub isKindOfClass:[UILabel class]]) {
  243. UILabel *lab = (UILabel *)sub;
  244. lab.textColor = [UIColor whiteColor];
  245. }
  246. if ([sub isKindOfClass:[UIButton class]]) {
  247. UIButton *btn = (UIButton *)sub;
  248. btn.selected = YES;
  249. }
  250. }
  251. for (UIView *sub in nBtn.subviews) {
  252. if ([sub isKindOfClass:[UILabel class]]) {
  253. UILabel *lab = (UILabel *)sub;
  254. lab.textColor = [HEXCOLOR(0xFFFFFF) colorWithAlphaComponent:0.5];
  255. }
  256. if ([sub isKindOfClass:[UIButton class]]) {
  257. UIButton *btn = (UIButton *)sub;
  258. btn.selected = NO;
  259. }
  260. }
  261. }
  262. #pragma mark - 扫一扫
  263. - (void)onScanQrCodeVC {
  264. JXScanQRViewController *vc = [[JXScanQRViewController alloc] init];
  265. [g_navigation pushViewController:vc animated:YES];
  266. }
  267. #pragma mark - 更新 付款 二维码 && 条形码
  268. - (void)updatePayQrCode {
  269. [self dismissVerifyPayVC];
  270. self.codeStr = [self getPayQrCodeStr];
  271. _barCode.image = [QRImage barCodeWithString:self.codeStr BCSize:_barCode.frame.size];
  272. _payQrCode.image = [QRImage qrImageForString:self.codeStr imageSize:200];
  273. }
  274. - (void)startTimer {
  275. //设置时间间隔 一分钟
  276. self.timer = [NSTimer scheduledTimerWithTimeInterval:60.0
  277. target:self
  278. selector:@selector(updatePayQrCode) userInfo:nil
  279. repeats:YES];
  280. }
  281. - (void)stopTimer {
  282. if (_timer){
  283. // 关闭定时器
  284. [_timer invalidate];
  285. }
  286. }
  287. - (UIButton *)createButtonWithFrame:(CGRect)frame title:(NSString*)title icon:(NSString*)icon selected:(NSString *)selected click:(SEL)click{
  288. UIButton* btn = [[UIButton alloc] initWithFrame:frame];
  289. btn.backgroundColor = [UIColor clearColor];
  290. btn.userInteractionEnabled = YES;
  291. [btn addTarget:self action:click forControlEvents:UIControlEventTouchUpInside];
  292. [self.tableBody addSubview:btn];
  293. UIButton* image = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width/2-10, 0, 20, 20)];
  294. [image setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
  295. [image setImage:[UIImage imageNamed:selected] forState:UIControlStateSelected];
  296. image.userInteractionEnabled = NO;
  297. [btn addSubview:image];
  298. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(image.frame)+15, frame.size.width, 13)];
  299. p.text = title;
  300. p.font = g_factory.font13;
  301. p.textAlignment = NSTextAlignmentCenter;
  302. p.backgroundColor = [UIColor clearColor];
  303. p.textColor = [HEXCOLOR(0xFFFFFF) colorWithAlphaComponent:0.5];
  304. [btn addSubview:p];
  305. return btn;
  306. }
  307. #pragma mark - 生成二维码数据
  308. - (NSString *)getPayQrCodeStr {
  309. // int n = 9;
  310. // int opt = [self getRandomNumber:100 to:101];
  311. //
  312. // NSString *str = [NSString stringWithFormat:@"%d",[MY_USER_ID intValue]+n+opt];
  313. //
  314. // NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
  315. // long timeOpt = time/opt;
  316. // // 如果小于8位数
  317. // if (timeOpt < 10000000) {
  318. // timeOpt = time/(opt - 100);
  319. // }
  320. //
  321. // NSString *code = [NSString stringWithFormat:@"%ld%@%d%ld",str.length,str,opt,timeOpt];
  322. //
  323. // NSLog(@"length = %lu code = %@",code.length,code);
  324. NSString *qrCode = [g_payServer getQrCode];
  325. return qrCode;
  326. }
  327. //获取一个随机整数,范围在[from,to),包括from,不包括to
  328. -(int)getRandomNumber:(int)from to:(int)to {
  329. return (from + (arc4random() % (to - from + 1)));
  330. }
  331. #pragma mark - --------------以下是收款逻辑处理--------------
  332. - (void)setupGetMoneyViews {
  333. // [self setupView:self.view colors:@[(__bridge id)HEXCOLOR(0x449ad4).CGColor,(__bridge id)HEXCOLOR(0x1953AF).CGColor]];
  334. _baseView = [[UIView alloc] initWithFrame:CGRectMake(28, JX_SCREEN_TOP+60, JX_SCREEN_WIDTH-28*2, 318)];
  335. _baseView.backgroundColor = [UIColor whiteColor];
  336. _baseView.layer.masksToBounds = YES;
  337. _baseView.layer.cornerRadius = 7.f;
  338. _baseView.hidden = YES;
  339. _baseView.clipsToBounds = NO;
  340. [self.tableBody addSubview:_baseView];
  341. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake((_payBaseView.frame.size.width-80)/2, -40, 80, 80)];
  342. [_baseView addSubview:icon];
  343. [g_server getHeadImageLarge:g_server.myself.userId userName:g_server.myself.userNickname imageView:icon];
  344. // 添加圆角
  345. CAShapeLayer *circleShape = [CAShapeLayer layer];
  346. circleShape.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 80, 80)].CGPath;
  347. icon.layer.mask = circleShape;
  348. // 添加边距
  349. CAShapeLayer *circleBorder= [CAShapeLayer layer];
  350. circleBorder.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 80, 80)].CGPath;
  351. circleBorder.strokeColor = [UIColor whiteColor].CGColor;
  352. circleBorder.fillColor = [UIColor clearColor].CGColor;
  353. circleBorder.lineWidth = 7.f;
  354. [icon.layer addSublayer:circleBorder];
  355. _barCodeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 60, _baseView.frame.size.width, 15)];
  356. _barCodeLab.text = Localized(@"JX_ScanQrCodeToPayMe");
  357. _barCodeLab.textColor = HEXCOLOR(0x666666);
  358. _barCodeLab.font = SYSFONT(14);
  359. _barCodeLab.textAlignment = NSTextAlignmentCenter;
  360. [_baseView addSubview:_barCodeLab];
  361. //金额
  362. _moneyLab = [[UILabel alloc] init];
  363. _moneyLab.font = SYSFONT(20);
  364. _moneyLab.textAlignment = NSTextAlignmentCenter;
  365. [_baseView addSubview:_moneyLab];
  366. //说明
  367. _descLab = [[UILabel alloc] init];
  368. _descLab.font = SYSFONT(14);
  369. _descLab.textColor = [UIColor lightGrayColor];
  370. _descLab.textAlignment = NSTextAlignmentCenter;
  371. [_baseView addSubview:_descLab];
  372. // 二维码
  373. _getQrCode = [[UIImageView alloc] init];
  374. [_baseView addSubview:_getQrCode];
  375. _btnBaseView = [[UIView alloc] initWithFrame:CGRectMake(28, CGRectGetMaxY(_baseView.frame)+27, JX_SCREEN_WIDTH-28*2, 90)];
  376. _btnBaseView.layer.masksToBounds = YES;
  377. _btnBaseView.layer.cornerRadius = 7.f;
  378. _btnBaseView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2];
  379. [self.tableBody addSubview:_btnBaseView];
  380. // 设置金额
  381. _leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, _btnBaseView.frame.size.width-15, 45)];
  382. _leftLabel.font = SYSFONT(16);
  383. _leftLabel.textColor = [UIColor whiteColor];
  384. _leftLabel.userInteractionEnabled = YES;
  385. [_btnBaseView addSubview:_leftLabel];
  386. UITapGestureRecognizer *tapL = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(setMoneyCount)];
  387. [_leftLabel addGestureRecognizer:tapL];
  388. UIImageView* iv;
  389. iv = [[UIImageView alloc] initWithFrame:CGRectMake(_leftLabel.frame.size.width-15-7, (_leftLabel.frame.size.height-13)/2, 7, 13)];
  390. iv.image = [[UIImage imageNamed:@"new_icon_>"] imageWithTintColor:[UIColor whiteColor]];
  391. [_leftLabel addSubview:iv];
  392. UIView *botLine = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_leftLabel.frame), _btnBaseView.frame.size.width-15, LINE_WH)];
  393. botLine.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.3];
  394. [_btnBaseView addSubview:botLine];
  395. // 保存收款码
  396. _rigLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(botLine.frame), _btnBaseView.frame.size.width-15, 45)];
  397. _rigLabel.text = Localized(@"JX_SaveCollectionCode");
  398. _rigLabel.font = SYSFONT(16);
  399. _rigLabel.textColor = [UIColor whiteColor];
  400. _rigLabel.userInteractionEnabled = YES;
  401. [_btnBaseView addSubview:_rigLabel];
  402. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(saveQr)];
  403. [_rigLabel addGestureRecognizer:tap];
  404. iv = [[UIImageView alloc] initWithFrame:CGRectMake(_rigLabel.frame.size.width-15-7, (_rigLabel.frame.size.height-13)/2, 7, 13)];
  405. iv.image = [[UIImage imageNamed:@"new_icon_>"] imageWithTintColor:[UIColor whiteColor]];
  406. [_rigLabel addSubview:iv];
  407. [self updateViews];
  408. }
  409. #pragma mark - 更新界面
  410. - (void)updateViews {
  411. //金额
  412. CGSize mSize = [self.money sizeWithAttributes:@{NSFontAttributeName:SYSFONT(20)}];
  413. _moneyLab.text = [NSString stringWithFormat:@"¥%.2f",[self.money doubleValue]];
  414. _moneyLab.frame = CGRectMake(0, CGRectGetMaxY(_barCodeLab.frame)+10, _baseView.frame.size.width, mSize.height);
  415. //说明
  416. CGSize dSize = [self.desStr sizeWithAttributes:@{NSFontAttributeName:SYSFONT(14)}];
  417. _descLab.text = self.desStr;
  418. _descLab.frame = CGRectMake(0, CGRectGetMaxY(_moneyLab.frame)+10, _baseView.frame.size.width, dSize.height);
  419. //二维码
  420. _getQrCode.frame = CGRectMake((_baseView.frame.size.width - 190)/2, CGRectGetMaxY(_descLab.frame)+10, 190, 190);
  421. //设置金额
  422. _leftLabel.text = self.money.length > 0 ? Localized(@"JX_RemoveTheAmount") : Localized(@"JX_SetTheAmount");
  423. // _leftLabel.frame = CGRectMake(0, CGRectGetMaxY(_getQrCode.frame)+30, _baseView.frame.size.width*0.5, 15);
  424. // // 保存收款码
  425. // _rigLabel.frame = CGRectMake(CGRectGetMaxX(_leftLabel.frame), _leftLabel.frame.origin.y, _baseView.frame.size.width*0.5, 15);
  426. _baseView.frame = CGRectMake(_baseView.frame.origin.x, _baseView.frame.origin.y, _baseView.frame.size.width, CGRectGetMaxY(_getQrCode.frame)+23);
  427. _btnBaseView.frame = CGRectMake(_btnBaseView.frame.origin.x, CGRectGetMaxY(_baseView.frame)+38, _btnBaseView.frame.size.width, _btnBaseView.frame.size.height);
  428. _payBtn.frame = CGRectMake(_payBtn.frame.origin.x, CGRectGetMaxY(_btnBaseView.frame)+38, _payBtn.frame.size.width, _payBtn.frame.size.height);
  429. _getBtn.frame = CGRectMake(_getBtn.frame.origin.x, CGRectGetMinY(_payBtn.frame), _getBtn.frame.size.width, _getBtn.frame.size.height);
  430. _scanBtn.frame = CGRectMake(_scanBtn.frame.origin.x, CGRectGetMinY(_payBtn.frame), _scanBtn.frame.size.width, _scanBtn.frame.size.height);
  431. if (!BIG_DEVICE) {
  432. if (CGRectGetMaxY(_scanBtn.frame)+10 > self.tableBody.frame.size.height) {
  433. self.tableBody.contentSize = CGSizeMake(0, CGRectGetMaxY(_scanBtn.frame)+10);
  434. }
  435. }
  436. [self updateGetQrCode];
  437. }
  438. - (void)setMoneyCount {
  439. if (self.money.length > 0) {
  440. self.money = nil;
  441. self.desStr = nil;
  442. [self updateViews];
  443. return;
  444. }
  445. JXInputMoneyVC *inputVC = [[JXInputMoneyVC alloc] init];
  446. inputVC.type = JXInputMoneyTypeSetMoney;
  447. inputVC.delegate = self;
  448. inputVC.onInputMoney = @selector(onInputMoney:);
  449. [g_navigation pushViewController:inputVC animated:YES];
  450. }
  451. - (void)onInputMoney:(NSDictionary *)dict {
  452. if ([dict objectForKey:@"money"]) {
  453. self.money = [dict objectForKey:@"money"];
  454. }
  455. if ([dict objectForKey:@"desc"]) {
  456. self.desStr = [dict objectForKey:@"desc"];
  457. }
  458. [self updateViews];
  459. }
  460. #pragma mark - 保存二维码到相册
  461. - (void)saveQr {
  462. UIImageWriteToSavedPhotosAlbum(self.getQrCode.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  463. }
  464. -(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
  465. if(error){
  466. [g_server showMsg:Localized(@"ImageBrowser_saveFaild")];
  467. }else{
  468. [g_server showMsg:Localized(@"ImageBrowser_saveSuccess")];
  469. }
  470. }
  471. #pragma mark - 更新收款二维码
  472. - (void)updateGetQrCode {
  473. UIImageView *imageView = [[UIImageView alloc] init];
  474. [g_server getHeadImageLarge:MY_USER_ID userName:MY_USER_NAME imageView:imageView];
  475. _getQrCode.image = [QRImage qrImageForString:[self getQrCodeStr] imageSize:_getQrCode.frame.size.width logoImage:imageView.image logoImageSize:30];
  476. }
  477. - (NSString *)getQrCodeStr {
  478. NSMutableDictionary *dict = @{@"userId":MY_USER_ID,@"userName":MY_USER_NAME}.mutableCopy;
  479. if (self.money.length > 0) {
  480. [dict addEntriesFromDictionary:@{@"money":self.money}];
  481. }
  482. if (self.desStr.length > 0) {
  483. [dict addEntriesFromDictionary:@{@"description":self.desStr}];
  484. }
  485. SBJsonWriter * OderJsonwriter = [SBJsonWriter new];
  486. NSString * jsonString = [OderJsonwriter stringWithObject:dict];
  487. return jsonString;
  488. }
  489. - (void)setupView:(UIView *)view colors:(NSArray *)colors {
  490. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  491. gradientLayer.frame = CGRectMake(0, THE_DEVICE_HAVE_HEAD ? -44 : -20, JX_SCREEN_WIDTH, THE_DEVICE_HAVE_HEAD ? JX_SCREEN_HEIGHT+44 : JX_SCREEN_HEIGHT+20); // 设置显示的frame
  492. gradientLayer.colors = colors; // 设置渐变颜色
  493. gradientLayer.startPoint = CGPointMake(0, 0);
  494. gradientLayer.endPoint = CGPointMake(0, 1);
  495. [view.layer addSublayer:gradientLayer];
  496. }
  497. // 画虚线
  498. - (void)addBorderToLayer2:(UIView *)view {
  499. CAShapeLayer *shapeLayer = [CAShapeLayer layer];
  500. [shapeLayer setBounds:view.bounds];
  501. [shapeLayer setPosition:CGPointMake(CGRectGetWidth(view.frame) / 2, CGRectGetHeight(view.frame)/2)];
  502. [shapeLayer setStrokeColor:[UIColor lightGrayColor].CGColor];
  503. [shapeLayer setLineWidth:0.5];
  504. // 设置线宽,线间距
  505. [shapeLayer setLineDashPattern:@[@5,@3]];
  506. // 设置路径
  507. CGMutablePathRef path = CGPathCreateMutable();
  508. CGPathMoveToPoint(path, NULL, 0, 0);
  509. if (CGRectGetWidth(view.frame) > CGRectGetHeight(view.frame)) {
  510. CGPathAddLineToPoint(path, NULL, CGRectGetWidth(view.frame),0);
  511. }else{
  512. CGPathAddLineToPoint(path, NULL, 0,CGRectGetHeight(view.frame));
  513. }
  514. [shapeLayer setPath:path];
  515. CGPathRelease(path);
  516. // 把绘制好的虚线添加上来
  517. [view.layer addSublayer:shapeLayer];
  518. }
  519. - (void)updatePayPasswordSuccess:(NSString *)payPassword {
  520. [self didVerifyPay:payPassword];
  521. }
  522. //服务端返回数据
  523. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  524. [_wait stop];
  525. if ([aDownload.action isEqualToString:act_payGetQrKey]) {
  526. [self updatePayQrCode];
  527. [self startTimer];
  528. }
  529. if ([aDownload.action isEqualToString:act_payVerifyQrKey]) {
  530. [self updatePayQrCode];
  531. [self startTimer];
  532. }
  533. }
  534. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  535. [_wait stop];
  536. if ([aDownload.action isEqualToString:act_payVerifyQrKey]) {
  537. if ([g_server.myself.isPayPassword boolValue]) {
  538. self.verVC = [JXVerifyPayVC alloc];
  539. self.verVC.type = JXVerifyTypePaymentCode;
  540. self.verVC.RMB = @"";
  541. self.verVC.delegate = self;
  542. self.verVC.didDismissVC = @selector(dismissVerifyPayVC);
  543. self.verVC.didVerifyPay = @selector(didVerifyPay:);
  544. self.verVC = [self.verVC init];
  545. [self.view addSubview:self.verVC.view];
  546. } else {
  547. JXPayPasswordVC *payPswVC = [JXPayPasswordVC alloc];
  548. payPswVC.delegate = self;
  549. payPswVC.type = JXPayTypeSetupPassword;
  550. payPswVC.enterType = JXEnterTypePayQr;
  551. payPswVC = [payPswVC init];
  552. [g_navigation pushViewController:payPswVC animated:YES];
  553. }
  554. return hide_error;
  555. }
  556. if ([aDownload.action isEqualToString:act_payGetQrKey] || [aDownload.action isEqualToString:act_TransactionGetCode]) {
  557. [self.verVC clearUpPassword];
  558. }
  559. return show_error;
  560. }
  561. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  562. [_wait stop];
  563. if ([aDownload.action isEqualToString:act_payVerifyQrKey]) {
  564. if ([g_server.myself.isPayPassword boolValue]) {
  565. self.verVC = [JXVerifyPayVC alloc];
  566. self.verVC.type = JXVerifyTypePaymentCode;
  567. self.verVC.RMB = @"";
  568. self.verVC.delegate = self;
  569. self.verVC.didDismissVC = @selector(dismissVerifyPayVC);
  570. self.verVC.didVerifyPay = @selector(didVerifyPay:);
  571. self.verVC = [self.verVC init];
  572. [self.view addSubview:self.verVC.view];
  573. } else {
  574. JXPayPasswordVC *payPswVC = [JXPayPasswordVC alloc];
  575. payPswVC.delegate = self;
  576. payPswVC.type = JXPayTypeSetupPassword;
  577. payPswVC.enterType = JXEnterTypePayQr;
  578. payPswVC = [payPswVC init];
  579. [g_navigation pushViewController:payPswVC animated:YES];
  580. }
  581. return hide_error;
  582. }
  583. return show_error;
  584. }
  585. -(void) didServerConnectStart:(JXConnection*)aDownload{
  586. [_wait start];
  587. }
  588. @end