JXWebLoginVC.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // JXWebLoginVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/5/28.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXWebLoginVC.h"
  9. @interface JXWebLoginVC ()
  10. @end
  11. @implementation JXWebLoginVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. // Do any additional setup after loading the view.
  15. self.heightFooter = 0;
  16. self.heightHeader = JX_SCREEN_TOP;
  17. // self.title = Localized(@"JX_Login");
  18. self.isGotoBack = NO;
  19. [self createHeadAndFoot];
  20. self.tableBody.backgroundColor = [UIColor whiteColor];
  21. //icon
  22. UIImageView * kuliaoIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"web_icon"]];
  23. kuliaoIconView.frame = CGRectMake((JX_SCREEN_WIDTH-104)/2, 50, 104, 91);
  24. [self.tableBody addSubview:kuliaoIconView];
  25. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(kuliaoIconView.frame) + 20, JX_SCREEN_WIDTH, 18)];
  26. label.textAlignment = NSTextAlignmentCenter;
  27. label.text = @"web 登录确认";
  28. label.font = [UIFont systemFontOfSize:18.0];
  29. label.textColor = HEXCOLOR(0x333333);
  30. [self.tableBody addSubview:label];
  31. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(35, CGRectGetMaxY(label.frame)+50, JX_SCREEN_WIDTH-70, LINE_WH)];
  32. line.backgroundColor = THE_LINE_COLOR;
  33. [self.tableBody addSubview:line];
  34. label = [[UILabel alloc] initWithFrame:CGRectMake(60, CGRectGetMaxY(line.frame) + 37, 130, 16)];
  35. label.text = g_myself.userNickname;
  36. label.font = [UIFont systemFontOfSize:16.0];
  37. label.textColor = HEXCOLOR(0x333333);
  38. [self.tableBody addSubview:label];
  39. label = [[UILabel alloc] initWithFrame:CGRectMake(60, CGRectGetMaxY(label.frame) + 20, 130, 14)];
  40. label.text = g_myself.telephone;
  41. label.font = [UIFont systemFontOfSize:14.0];
  42. label.textColor = HEXCOLOR(0x999999);
  43. [self.tableBody addSubview:label];
  44. UIImageView *userIcon = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 62-50, CGRectGetMaxY(line.frame) + 37, 50, 50)];
  45. userIcon.layer.cornerRadius = 50 / 2;
  46. userIcon.layer.masksToBounds = YES;
  47. [g_server getHeadImageLarge:g_myself.userId userName:g_myself.userNickname imageView:userIcon];
  48. [self.tableBody addSubview:userIcon];
  49. UIButton *btn = [UIFactory createCommonButton:Localized(@"JX_ConfirmTheLogin") target:self action:@selector(onLogin)];
  50. [btn setBackgroundImage:nil forState:UIControlStateHighlighted];
  51. [btn setBackgroundImage:nil forState:UIControlStateNormal];
  52. btn.custom_acceptEventInterval = 1.f;
  53. btn.frame = CGRectMake(15,CGRectGetMaxY(label.frame) + 37, JX_SCREEN_WIDTH-30, 40);
  54. [btn.titleLabel setFont:SYSFONT(16)];
  55. btn.layer.masksToBounds = YES;
  56. btn.layer.cornerRadius = 7.f;
  57. btn.backgroundColor = THEMECOLOR;
  58. [self.tableBody addSubview:btn];
  59. //取消登录
  60. btn = [UIFactory createCommonButton:@"取消登录" target:self action:@selector(quiteCurVC)];
  61. [btn setBackgroundImage:nil forState:UIControlStateHighlighted];
  62. [btn setBackgroundImage:nil forState:UIControlStateNormal];
  63. btn.custom_acceptEventInterval = 1.f;
  64. btn.frame = CGRectMake(JX_SCREEN_WIDTH/2-30,CGRectGetMaxY(label.frame) +37+40+ 32, 60, 30);
  65. [btn.titleLabel setFont:SYSFONT(14)];
  66. [btn setTitleColor:HEXCOLOR(0x999999) forState:UIControlStateNormal];
  67. btn.backgroundColor = [UIColor clearColor];
  68. [self.tableBody addSubview:btn];
  69. }
  70. - (void)actionQuit {
  71. [self dismissViewControllerAnimated:YES completion:nil];
  72. }
  73. - (void)quiteCurVC {
  74. [super actionQuit];
  75. }
  76. - (void)onLogin {
  77. if (self.isQRLogin) {
  78. if ([self.delegate respondsToSelector:@selector(webLoginSuccess)]) {
  79. [self.delegate webLoginSuccess];
  80. [super actionQuit];
  81. }
  82. }else {
  83. NSString *url = [NSString stringWithFormat:@"%@?data=%@",self.callbackUrl,[self getData]];
  84. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  85. [self dismissViewControllerAnimated:YES completion:nil];
  86. }
  87. }
  88. - (NSString *)getData {
  89. NSDictionary *dic = @{
  90. @"accessToken" : g_server.access_token,
  91. @"telephone" : g_myself.telephone,
  92. @"password" : [g_default objectForKey:kMY_USER_PASSWORD]
  93. };
  94. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
  95. NSString *json = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  96. NSString *key = [g_server getMD5String:APIKEY];
  97. NSString *encrypted = [DESUtil encryptDESStr:json key:key];
  98. NSString *encodedString = (NSString *)
  99. CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
  100. (CFStringRef)encrypted,
  101. NULL,
  102. (CFStringRef)@"!*'();:@&=+$,/?%#[]",
  103. kCFStringEncodingUTF8));
  104. return encodedString;
  105. }
  106. /*
  107. #pragma mark - Navigation
  108. // In a storyboard-based application, you will often want to do a little preparation before navigation
  109. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  110. // Get the new view controller using [segue destinationViewController].
  111. // Pass the selected object to the new view controller.
  112. }
  113. */
  114. @end