JXRechargeViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // JXRechargeViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 17/10/30.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "JXRechargeViewController.h"
  9. #import "JXRechargeCell.h"
  10. #import "UIImage+Color.h"
  11. #import <AlipaySDK/AlipaySDK.h>
  12. #import "JXQRCodeViewController.h"
  13. @interface JXRechargeViewController ()<UIAlertViewDelegate,UITextFieldDelegate>
  14. @property (nonatomic, assign) NSInteger checkIndex;
  15. @property (atomic, assign) NSInteger payType;
  16. //@property (nonatomic, strong) NSArray * rechargeArray;
  17. @property (nonatomic, strong) NSArray * rechargeMoneyArray;
  18. @property (nonatomic, strong) UILabel * totalMoney;
  19. @property (nonatomic, strong) UIButton * wxPayBtn;
  20. @property (nonatomic, strong) UIButton * aliPayBtn;
  21. @property (atomic, assign) NSInteger btnIndex;
  22. @property (nonatomic, strong) UIView *baseView;
  23. @property (nonatomic, strong) UITextField *moneyTextField;
  24. @end
  25. static NSString * JXRechargeCellID = @"JXRechargeCellID";
  26. @implementation JXRechargeViewController
  27. -(instancetype)init{
  28. if (self = [super init]) {
  29. self.heightHeader = JX_SCREEN_TOP;
  30. self.heightFooter = 0;
  31. self.isGotoBack = YES;
  32. self.title = Localized(@"JXLiveVC_Recharge");
  33. self.rechargeMoneyArray = @[@10,
  34. @20,
  35. @50,
  36. @100,
  37. @200,
  38. @500];
  39. _checkIndex = -1;
  40. [g_notify addObserver:self selector:@selector(receiveWXPayFinishNotification:) name:kWxPayFinishNotification object:nil];
  41. [g_notify addObserver:self selector:@selector(receiveAliPayFinishNotification:) name:kWCMessageTypeOpenPaySuccessRefresh object:nil];
  42. }
  43. return self;
  44. }
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. [self createHeadAndFoot];
  48. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH,56*2)];
  49. [self.tableBody addSubview:self.baseView];
  50. [self setupViews];
  51. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.baseView.frame)+20, JX_SCREEN_WIDTH-30, LINE_WH)];
  52. line.backgroundColor = THE_LINE_COLOR;
  53. [self.tableBody addSubview:line];
  54. UILabel *tinLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(line.frame)+20, 130, 14)];
  55. tinLabel.textColor = HEXCOLOR(0x999999);
  56. tinLabel.font = SYSFONT(14);
  57. tinLabel.text = @"请选择充值方式";
  58. [self.tableBody addSubview:tinLabel];
  59. UILabel *leftLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 48, 16)];
  60. leftLab.font = SYSFONT(16);
  61. leftLab.text = @"合计: ";
  62. UILabel *rigLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
  63. rigLab.font = SYSFONT(24);
  64. rigLab.textColor = THEMECOLOR;
  65. rigLab.text = @"元";
  66. self.moneyTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(tinLabel.frame)+24, JX_SCREEN_WIDTH-30, 24)];
  67. self.moneyTextField.placeholder = @"请输入金额";
  68. self.moneyTextField.textColor = THEMECOLOR;
  69. self.moneyTextField.font = SYSFONT(24);
  70. self.moneyTextField.leftView = leftLab;
  71. self.moneyTextField.leftViewMode = UITextFieldViewModeAlways;
  72. self.moneyTextField.rightView = rigLab;
  73. self.moneyTextField.rightViewMode = UITextFieldViewModeAlways;
  74. self.moneyTextField.delegate = self;
  75. self.moneyTextField.keyboardType = UIKeyboardTypeDecimalPad;
  76. self.moneyTextField.text = [NSString stringWithFormat:@"%.2f",[self.rechargeMoneyArray[self.btnIndex] doubleValue]];
  77. [self.moneyTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  78. [self.tableBody addSubview:self.moneyTextField];
  79. [self setTextFieldWidth:self.moneyTextField.text];
  80. // self.wxPayBtn = [self payTypeBtn:CGRectMake(0, CGRectGetMaxY(self.moneyTextField.frame)+30, JX_SCREEN_WIDTH, 56) title:@"微信支付" image:@"weixin_logo" drawTop:NO drawBottom:YES action:@selector(wxPayBtnAction:)];
  81. // self.aliPayBtn = [self payTypeBtn:CGRectMake(0, CGRectGetMaxY(self.wxPayBtn.frame), JX_SCREEN_WIDTH, 56) title:@"支付宝支付" image:@"aliPay_logo" drawTop:NO drawBottom:NO action:@selector(aliPayBtnAction:)];
  82. self.aliPayBtn = [self payTypeBtn:CGRectMake(0, CGRectGetMaxY(self.moneyTextField.frame)+30, JX_SCREEN_WIDTH, 56) title:@"支付宝支付" image:@"aliPay_logo" drawTop:NO drawBottom:NO action:@selector(aliPayBtnAction:)];
  83. UILabel *tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.aliPayBtn.frame)+20, JX_SCREEN_WIDTH - 15, 14)];
  84. tipsLabel.textColor = [UIColor redColor];
  85. tipsLabel.font = SYSFONT(14);
  86. tipsLabel.text = @"提醒:请根据界面操作,请勿修改金额和重复扫码";
  87. [self.tableBody addSubview:tipsLabel];
  88. // self.isShowHeaderPull = NO;
  89. // self.isShowFooterPull = NO;
  90. // _table.backgroundColor = HEXCOLOR(0xefeff4);
  91. // [_table registerClass:[JXRechargeCell class] forCellReuseIdentifier:JXRechargeCellID];
  92. // _table.showsVerticalScrollIndicator = NO;
  93. // _table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  94. }
  95. - (void)textFieldDidChange:(UITextField *)textField {
  96. if (textField == self.moneyTextField) {
  97. if ([textField.text doubleValue] >= 10000) {
  98. textField.text = @"10000";
  99. }
  100. }
  101. [self setTextFieldWidth:textField.text];
  102. }
  103. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  104. NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  105. if (textField == self.moneyTextField) {
  106. // 首位不能输入 .
  107. if (IsStringNull(textField.text) && [string isEqualToString:@"."]) {
  108. return NO;
  109. }
  110. //限制.后面最多有两位,且不能再输入.
  111. if ([textField.text rangeOfString:@"."].location != NSNotFound) {
  112. //有.了 且.后面输入了两位 停止输入
  113. if (toBeString.length > [toBeString rangeOfString:@"."].location+3) {
  114. return NO;
  115. }
  116. //有.了,不允许再输入.
  117. if ([string isEqualToString:@"."]) {
  118. return NO;
  119. }
  120. }
  121. //限制首位0,后面只能输入. 和 删除
  122. if ([textField.text isEqualToString:@"0"]) {
  123. if (![string isEqualToString:@"."] && ![string isEqualToString:@""]) {
  124. return NO;
  125. }
  126. }
  127. //限制只能输入:1234567890.
  128. NSCharacterSet * characterSet = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890."] invertedSet];
  129. NSString * filtered = [[string componentsSeparatedByCharactersInSet:characterSet] componentsJoinedByString:@""];
  130. return [string isEqualToString:filtered];
  131. }
  132. return YES;
  133. }
  134. - (void)setupViews {
  135. UIButton *btn;
  136. CGFloat w = 89;
  137. int inset = (JX_SCREEN_WIDTH-w*3)/4;
  138. for (int i = 0; i < self.rechargeMoneyArray.count; i++) {
  139. CGFloat x = (w+inset)*(i % 3)+inset;
  140. int m = i / 3;
  141. btn = [self createButtonWihtFrame:CGRectMake(x, m*41+(15 * (m +1)), w, 41) title:[NSString stringWithFormat:@"%.2f元",[self.rechargeMoneyArray[i] doubleValue]] index:i];
  142. }
  143. }
  144. - (void)onDidMoney:(UIButton *)button {
  145. if ([self.moneyTextField isFirstResponder]) {
  146. [self.moneyTextField resignFirstResponder];
  147. }
  148. self.btnIndex = button.tag;
  149. self.moneyTextField.text = [NSString stringWithFormat:@"%.2f",[self.rechargeMoneyArray[self.btnIndex] doubleValue]];
  150. [self setTextFieldWidth:self.moneyTextField.text];
  151. for (UIView *view in self.baseView.subviews) {
  152. [view removeFromSuperview];
  153. }
  154. [self setupViews];
  155. }
  156. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  157. self.btnIndex = self.rechargeMoneyArray.count+1;
  158. textField.text = @"";
  159. [self setTextFieldWidth:textField.text];
  160. for (UIView *view in self.baseView.subviews) {
  161. [view removeFromSuperview];
  162. }
  163. [self setupViews];
  164. return YES;
  165. }
  166. - (void)setTextFieldWidth:(NSString *)s {
  167. CGSize size = [s sizeWithAttributes:@{NSFontAttributeName:SYSFONT(24)}];
  168. CGRect frame = self.moneyTextField.frame;
  169. if (s.length > 0) {
  170. frame.size.width = size.width+48+24;
  171. }else {
  172. frame.size.width = 130+48+24;
  173. }
  174. self.moneyTextField.frame = frame;
  175. }
  176. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  177. if ([textField.text doubleValue] > 0) {
  178. self.moneyTextField.text = [NSString stringWithFormat:@"%.2f元",[textField.text doubleValue]];
  179. }
  180. return YES;
  181. }
  182. -(void)dealloc{
  183. [g_notify removeObserver:self];
  184. }
  185. //-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  186. // return _rechargeMoneyArray.count;
  187. //}
  188. //
  189. //-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  190. // return 65;
  191. //}
  192. //
  193. //-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  194. // JXRechargeCell * cell = [tableView dequeueReusableCellWithIdentifier:JXRechargeCellID forIndexPath:indexPath];
  195. // NSString * money = [NSString stringWithFormat:@"%@%@",_rechargeMoneyArray[indexPath.row],Localized(@"JX_ChinaMoney")];
  196. // cell.textLabel.text = money;
  197. // if(_checkIndex == indexPath.row){
  198. // cell.checkButton.selected = YES;
  199. // }
  200. // return cell;
  201. //}
  202. //
  203. //-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  204. // _checkIndex = indexPath.row;
  205. // NSString * money = [NSString stringWithFormat:@"%@",_rechargeMoneyArray[indexPath.row]];
  206. // [self setTotalMoneyText:money];
  207. // NSArray * cellArray = [tableView visibleCells];
  208. // for (JXRechargeCell * cell in cellArray) {
  209. // cell.checkButton.selected = NO;
  210. // }
  211. //
  212. // JXRechargeCell * selCell = [tableView cellForRowAtIndexPath:indexPath];
  213. // selCell.checkButton.selected = YES;
  214. //}
  215. //
  216. //-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  217. // return 200;
  218. //}
  219. //
  220. //-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  221. // UIView * paySelView = [[UIView alloc] init];
  222. // paySelView.backgroundColor = HEXCOLOR(0xefeff4);
  223. // UILabel * payStyleLabel = [UIFactory createLabelWith:CGRectMake(20, 0, JX_SCREEN_WIDTH-20*2, 40) text:Localized(@"JXMoney_choosePayType") font:g_factory.font14 textColor:[UIColor lightGrayColor] backgroundColor:[UIColor clearColor]];
  224. // [paySelView addSubview:payStyleLabel];
  225. //
  226. // UIView * whiteView = [[UIView alloc] init];
  227. // whiteView.backgroundColor = [UIColor whiteColor];
  228. // whiteView.frame = CGRectMake(0, CGRectGetMaxY(payStyleLabel.frame), JX_SCREEN_WIDTH, 200-CGRectGetMaxY(payStyleLabel.frame));
  229. // [paySelView addSubview:whiteView];
  230. //
  231. // UILabel * totalTitle = [UIFactory createLabelWith:CGRectZero text:nil font:g_factory.font14 textColor:[UIColor lightGrayColor] backgroundColor:[UIColor clearColor]];
  232. // NSString * totalStr = Localized(@"JXMoney_total");
  233. // CGFloat totalWidth = [totalStr sizeWithAttributes:@{NSFontAttributeName:totalTitle.font}].width;
  234. // totalTitle.frame = CGRectMake(20, 20, totalWidth+5, 18);
  235. // totalTitle.text = totalStr;
  236. // [whiteView addSubview:totalTitle];
  237. //
  238. //
  239. // _totalMoney = [UIFactory createLabelWith:CGRectZero text:nil font:g_factory.font20 textColor:[UIColor lightGrayColor] backgroundColor:[UIColor clearColor]];
  240. // NSString * totalMoneyStr = @"¥--";
  241. // CGFloat moneyWidth = [totalMoneyStr sizeWithAttributes:@{NSFontAttributeName:_totalMoney.font}].width;
  242. // _totalMoney.frame = CGRectMake(CGRectGetMaxX(totalTitle.frame), 20, moneyWidth+5, 18);
  243. // _totalMoney.text = totalMoneyStr;
  244. // _totalMoney.textColor = [UIColor redColor];
  245. // [whiteView addSubview:_totalMoney];
  246. //
  247. // _wxPayBtn = [UIFactory createButtonWithRect:CGRectZero title:Localized(@"JXMoney_wxPay") titleFont:g_factory.font17 titleColor:[UIColor whiteColor] normal:nil selected:nil selector:@selector(wxPayBtnAction:) target:self];
  248. // _wxPayBtn.frame = CGRectMake(20, CGRectGetMaxY(_totalMoney.frame)+20, JX_SCREEN_WIDTH-20*2, 40);
  249. // [_wxPayBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0x1aad19)] forState:UIControlStateNormal];
  250. // [_wxPayBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0xa2dea3)] forState:UIControlStateDisabled];
  251. // _wxPayBtn.layer.cornerRadius = 5;
  252. // _wxPayBtn.clipsToBounds = YES;
  253. // [whiteView addSubview:_wxPayBtn];
  254. //
  255. //
  256. // _aliPayBtn = [UIFactory createButtonWithRect:CGRectZero title:Localized(@"JXMoney_aliPay") titleFont:g_factory.font17 titleColor:[UIColor whiteColor] normal:nil selected:nil selector:@selector(aliPayBtnAction:) target:self];
  257. // _aliPayBtn.frame = CGRectMake(20, CGRectGetMaxY(_wxPayBtn.frame)+15, JX_SCREEN_WIDTH-20*2, 40);
  258. // [_aliPayBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0x1aad19)] forState:UIControlStateNormal];
  259. // [_aliPayBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0xa2dea3)] forState:UIControlStateDisabled];
  260. // _aliPayBtn.layer.cornerRadius = 5;
  261. // _aliPayBtn.clipsToBounds = YES;
  262. // [whiteView addSubview:_aliPayBtn];
  263. //
  264. //
  265. // return paySelView;
  266. //}
  267. -(void)setTotalMoneyText:(NSString *)money{
  268. NSString * totalMoneyStr = [NSString stringWithFormat:@"¥%@",money];
  269. CGFloat moneyWidth = [totalMoneyStr sizeWithAttributes:@{NSFontAttributeName:_totalMoney.font}].width;
  270. CGRect frame = _totalMoney.frame;
  271. frame.size.width = moneyWidth;
  272. _totalMoney.frame = frame;
  273. _totalMoney.text = totalMoneyStr;
  274. }
  275. - (void)didReceiveMemoryWarning {
  276. [super didReceiveMemoryWarning];
  277. // Dispose of any resources that can be recreated.
  278. }
  279. #pragma mark Action
  280. -(void)wxPayBtnAction:(UIButton *)button{
  281. // if (_checkIndex >=0 && _checkIndex <_rechargeMoneyArray.count) {
  282. // NSString * money = [NSString stringWithFormat:@"%@",_rechargeMoneyArray[_checkIndex]];
  283. // _payType = 2;
  284. // [g_server getSign:money payType:2 toView:self];
  285. // }
  286. if ([self.moneyTextField.text doubleValue] > 0) {
  287. _payType = 2;
  288. [g_server getSign:self.moneyTextField.text payType:2 toView:self];
  289. }
  290. }
  291. -(void)aliPayBtnAction:(UIButton *)button{
  292. // if (_checkIndex >=0 && _checkIndex <_rechargeMoneyArray.count) {
  293. // NSString * money = [NSString stringWithFormat:@"%@",_rechargeMoneyArray[_checkIndex]];
  294. // _payType = 1;
  295. // [g_server getSign:money payType:1 toView:self];
  296. // }
  297. if ([self.moneyTextField.text doubleValue] > 0) {
  298. _payType = 1;
  299. // [g_server getSign:self.moneyTextField.text payType:1 toView:self];
  300. [g_server paymentByThirdAmount:self.moneyTextField.text type:@"1" ToView:self];
  301. }
  302. }
  303. -(void)tuningWxWith:(NSDictionary *)dict{
  304. PayReq *req = [[PayReq alloc] init];
  305. req.partnerId = [dict objectForKey:@"partnerId"];
  306. req.prepayId = [dict objectForKey:@"prepayId"];
  307. req.nonceStr = [dict objectForKey:@"nonceStr"];
  308. req.timeStamp = [[dict objectForKey:@"timeStamp"] intValue];
  309. req.package = @"Sign=WXPay";//[dict objectForKey:@"package"];
  310. req.sign = [dict objectForKey:@"sign"];
  311. [WXApi sendReq:req];
  312. }
  313. - (void)tuningAlipayWithOrder:(NSString *)signedString {
  314. // NOTE: 如果加签成功,则继续执行支付
  315. if (signedString != nil) {
  316. //应用注册scheme,在AliSDKDemo-Info.plist定义URL types
  317. NSString *appScheme = @"shikuimapp";
  318. // NOTE: 调用支付结果开始支付
  319. [[AlipaySDK defaultService] payOrder:signedString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
  320. SBJsonParser * resultParser = [[SBJsonParser alloc] init] ;
  321. NSDictionary *resultObject = [resultParser objectWithString:resultDic[@"result"]];
  322. NSDictionary *response = [resultObject objectForKey:@"alipay_trade_app_pay_response"];
  323. if ([response[@"msg"] isEqualToString:@"Success"]) {
  324. [g_App showAlert:@"充值成功" delegate:self tag:1001 onlyConfirm:YES];
  325. }else {
  326. [g_App showAlert:@"充值失败" delegate:self tag:1001 onlyConfirm:YES];
  327. }
  328. [self actionQuit];
  329. NSLog(@"reslut = %@",resultDic);
  330. }];
  331. }
  332. }
  333. -(void)receiveWXPayFinishNotification:(NSNotification *)notifi{
  334. PayResp *resp = notifi.object;
  335. switch (resp.errCode) {
  336. case WXSuccess:{
  337. [g_App showAlert:Localized(@"JXMoney_PaySuccess") delegate:self tag:1001 onlyConfirm:YES];
  338. if (self.rechargeDelegate && [self.rechargeDelegate respondsToSelector:@selector(rechargeSuccessed)]) {
  339. [self.rechargeDelegate performSelector:@selector(rechargeSuccessed)];
  340. }
  341. if (_isQuitAfterSuccess) {
  342. [self actionQuit];
  343. }
  344. break;
  345. }
  346. case WXErrCodeUserCancel:{
  347. //取消了支付
  348. break;
  349. }
  350. default:{
  351. //支付错误
  352. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"支付失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr] message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  353. [alert show];
  354. break;
  355. }
  356. }
  357. }
  358. - (void)receiveAliPayFinishNotification:(NSNotification *)notifi {
  359. // JXMessageObject *msg = notifi.object;
  360. // msg.content;
  361. // SBJsonParser * resultParser = [[SBJsonParser alloc] init] ;
  362. //
  363. // NSDictionary *response = [self dictionaryWithJsonString: msg.content];
  364. // int status = (int)response[@"status"];
  365. // if (status == 1) {
  366. // [g_App showAlert:@"充值成功" delegate:self tag:1001 onlyConfirm:YES];
  367. // }else {
  368. //
  369. // [g_App showAlert:@"充值失败" delegate:self tag:1001 onlyConfirm:YES];
  370. // }
  371. // [self actionQuit];
  372. }
  373. //json格式字符串转字典:
  374. - (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
  375. if (jsonString == nil) {
  376. return nil;
  377. }
  378. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  379. NSError *err;
  380. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
  381. options:NSJSONReadingMutableContainers
  382. error:&err];
  383. if(err) {
  384. NSLog(@"json解析失败:%@",err);
  385. return nil;
  386. }
  387. return dic;
  388. }
  389. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  390. if (alertView.tag == 1001) {
  391. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  392. [g_server getUserMoenyToView:self];
  393. });
  394. }
  395. }
  396. - (void)didServerResultSucces:(JXConnection *)aDownload dict:(NSDictionary *)dict array:(NSArray *)array1{
  397. [_wait stop];
  398. if ([aDownload.action isEqualToString:act_getSign]) {
  399. if ([[dict objectForKey:@"package"] isEqualToString:@"Sign=WXPay"]) {
  400. [self tuningWxWith:dict];
  401. }else {
  402. [self tuningAlipayWithOrder:[dict objectForKey:@"orderInfo"]];
  403. }
  404. }else if ([aDownload.action isEqualToString:act_getUserMoeny]) {
  405. g_App.myMoney = [dict[@"balance"] doubleValue];
  406. [g_notify postNotificationName:kUpdateUserNotifaction object:nil];
  407. [self actionQuit];
  408. }
  409. if ([aDownload.action isEqualToString:act_paymentByThird]) {
  410. if (dict == nil) {
  411. return;
  412. }
  413. NSString *qrString = dict[@"data"][@"codeOriginal"];
  414. // 显示二维码
  415. JXQRCodeViewController * qrVC = [[JXQRCodeViewController alloc] init];
  416. qrVC.type = QRAliPayType;
  417. qrVC.qrString = qrString;
  418. qrVC.nickName = [NSString stringWithFormat:@"支付金额: %@元",self.moneyTextField.text];
  419. qrVC.amount = self.moneyTextField.text;
  420. // qrVC.qrString =
  421. // qrVC.userId = user.userId;
  422. // qrVC.account = user.account;
  423. // qrVC.nickName = user.userNickname;
  424. // qrVC.sex = user.sex;
  425. // [g_window addSubview:qrVC.view];
  426. [g_navigation pushViewController:qrVC animated:YES];
  427. }
  428. }
  429. - (int)didServerResultFailed:(JXConnection *)aDownload dict:(NSDictionary *)dict{
  430. [_wait stop];
  431. // if ([aDownload.action isEqualToString:]) {
  432. // return hide_error
  433. // }
  434. // [self tuningAlipayWithOrder:[dict objectForKey:@"resultMsg"][@"data"][@""]];
  435. return show_error;
  436. }
  437. - (int)didServerConnectError:(JXConnection *)aDownload error:(NSError *)error{
  438. [_wait stop];
  439. // if ([aDownload.action isEqualToString:]) {
  440. // [self refreshAfterConnectError];
  441. // }
  442. return hide_error;
  443. }
  444. -(void) didServerConnectStart:(JXConnection*)aDownload{
  445. [_wait start];
  446. }
  447. - (UIButton *)createButtonWihtFrame:(CGRect)frame title:(NSString *)title index:(NSInteger)index {
  448. UIButton *btn = [[UIButton alloc] initWithFrame:frame];
  449. [btn setTag:index];
  450. UIImageView *imgV = [[UIImageView alloc] initWithFrame:btn.bounds];
  451. imgV.image = [[UIImage imageNamed:@"Recharge_normal"] imageWithTintColor:THEMECOLOR];
  452. [btn addSubview:imgV];
  453. UILabel *label = [[UILabel alloc] initWithFrame:btn.bounds];
  454. label.text = title;
  455. label.backgroundColor = [UIColor clearColor];
  456. label.textColor = THEMECOLOR;
  457. label.textAlignment = NSTextAlignmentCenter;
  458. label.font = SYSFONT(14);
  459. [btn addSubview:label];
  460. if (self.btnIndex == index) {
  461. imgV.image = [[UIImage imageNamed:@"Recharge_seleted"] imageWithTintColor:THEMECOLOR];
  462. label.textColor = [UIColor whiteColor];
  463. }
  464. [btn addTarget:self action:@selector(onDidMoney:) forControlEvents:UIControlEventTouchUpInside];
  465. [self.baseView addSubview:btn];
  466. return btn;
  467. }
  468. - (UIButton *)payTypeBtn:(CGRect)frame title:(NSString *)title image:(NSString *)image drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom action:(SEL)action {
  469. UIButton *btn = [[UIButton alloc] initWithFrame:frame];
  470. UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width-19-36, (frame.size.height-19)/2, 19, 19)];
  471. imgV.image = [UIImage imageNamed:image];
  472. [btn addSubview:imgV];
  473. if (action == @selector(wxPayBtnAction:)) {
  474. imgV.frame = CGRectMake(frame.size.width-20-36, (frame.size.height-16)/2, 20, 16);
  475. }
  476. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 100, frame.size.height)];
  477. label.text = title;
  478. label.backgroundColor = [UIColor clearColor];
  479. label.textColor = HEXCOLOR(0x222222);
  480. label.font = SYSFONT(16);
  481. [btn addSubview:label];
  482. [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
  483. [self.tableBody addSubview:btn];
  484. if(drawTop){
  485. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,0,JX_SCREEN_WIDTH-15,LINE_WH)];
  486. line.backgroundColor = THE_LINE_COLOR;
  487. [btn addSubview:line];
  488. }
  489. if(drawBottom){
  490. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(15, frame.size.height-LINE_WH,JX_SCREEN_WIDTH-15,LINE_WH)];
  491. line.backgroundColor = THE_LINE_COLOR;
  492. [btn addSubview:line];
  493. }
  494. UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, frame.size.height/2-13/2, 7, 13)];
  495. iv.image = [UIImage imageNamed:@"new_icon_>"];
  496. [btn addSubview:iv];
  497. return btn;
  498. }
  499. @end