BogoSetAccountViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. //
  2. // BogoSetAccountViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/9/26.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoSetAccountViewController.h"
  9. #import "SetTableViewCell.h"
  10. #import "BogoSetAccountModel.h"
  11. #import "BogoLoginViewController.h"
  12. #import <UMShare/UMShare.h>
  13. #import "BogoYoungModeVideoViewController.h"
  14. #import "BogoYouthModeViewController.h"
  15. //青少年模式弹窗
  16. #import "BogoYounthModePopView.h"
  17. #import "BogoYouthModePassWordViewController.h"
  18. //注销账户
  19. #import "BogoLogoutTextViewController.h"
  20. //第三方登录-绑定手机号
  21. #import "BogoThirdLoginViewController.h"
  22. @interface BogoSetAccountViewController ()<UITableViewDelegate,UITableViewDataSource>
  23. @property(nonatomic, strong) UITableView *tableView;
  24. @property(nonatomic, strong) NSMutableArray *listArr;
  25. @property(nonatomic, strong) NSMutableArray *thirdArr;
  26. @property(nonatomic, strong) BogoSetAccountModel *model;
  27. @property(nonatomic, strong) BogoYounthModePopView *youthView;
  28. @end
  29. @implementation BogoSetAccountViewController
  30. - (void)viewWillAppear:(BOOL)animated {
  31. [super viewWillAppear:animated];
  32. self.navigationController.navigationBar.hidden = YES;
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. // Do any additional setup after loading the view.
  37. self.view.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
  38. UIImageView * navView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationHeight)];
  39. navView.image = [UIImage imageNamed:@"mine_navbg"];
  40. navView.userInteractionEnabled = YES;
  41. [self.view addSubview:navView];
  42. UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  43. [backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  44. backBtn.frame = CGRectMake(10, StatusBarHeight, 44, 44);
  45. [backBtn addTarget:self action:@selector(backLastVC) forControlEvents:UIControlEventTouchUpInside];
  46. [navView addSubview:backBtn];
  47. UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
  48. titleLabel.centerX = SCREEN_WIDTH/2;
  49. titleLabel.centerY = backBtn.centerY;
  50. titleLabel.text = ASLocalizedString(@"账号与安全");
  51. titleLabel.textColor = UIColor.blackColor;
  52. titleLabel.font = [UIFont boldSystemFontOfSize:18];
  53. titleLabel.textAlignment = NSTextAlignmentCenter;
  54. [navView addSubview:titleLabel];
  55. [self setupBackBtnWithBlock:nil];
  56. [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kBlackColor,
  57. NSFontAttributeName:[UIFont systemFontOfSize:15]
  58. } forState:UIControlStateNormal];
  59. self.thirdArr = [NSMutableArray array];
  60. if ([GlobalVariables sharedInstance].appModel.has_qq_login == 1)//QQ
  61. {
  62. [self.thirdArr addObject:ASLocalizedString(@"QQ")];
  63. }
  64. if ([GlobalVariables sharedInstance].appModel.has_wx_login == 1)//微信
  65. {
  66. [self.thirdArr addObject:ASLocalizedString(@"微信")];
  67. }
  68. if (self.thirdArr.count > 0) {
  69. _listArr = [NSMutableArray arrayWithObjects:@[ASLocalizedString(@"手机号"),ASLocalizedString(@"登录密码") ],self.thirdArr,@[ASLocalizedString(@"青少年模式"),ASLocalizedString(@"注销账号")], nil];
  70. }else{
  71. _listArr = [NSMutableArray arrayWithObjects:@[ASLocalizedString(@"手机号"),ASLocalizedString(@"登录密码")],@[ASLocalizedString(@"青少年模式"),ASLocalizedString(@"注销账号")], nil];
  72. }
  73. [self setModel];
  74. [self.view addSubview:self.tableView];
  75. }
  76. - (void)backLastVC {
  77. [self.navigationController popViewControllerAnimated:YES];
  78. }
  79. - (void)setupBackBtnWithBlock:(BackBlock)backBlock
  80. {
  81. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(onReturnBtnPress) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  82. }
  83. -(void)setModel{
  84. NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
  85. [paramDic setObject:@"account_security" forKey:@"act"];
  86. [paramDic setObject:@"login" forKey:@"ctl"];
  87. [paramDic setObject:[BGIMLoginManager sharedInstance].loginParam.identifier forKey:@"uid"];
  88. [[NetHttpsManager manager] POSTWithParameters:paramDic SuccessBlock:^(NSDictionary *responseJson) {
  89. if ([[responseJson valueForKey:@"status"] integerValue] == 1) {
  90. self.model = [BogoSetAccountModel modelWithDictionary:[responseJson valueForKey:@"data"]];
  91. [self.tableView reloadData];
  92. }else{
  93. [FanweMessage alertHUD:[responseJson valueForKey:@"error"]];
  94. }
  95. } FailureBlock:^(NSError *error) {
  96. }];
  97. }
  98. #pragma mark - UITableView Datasource
  99. #pragma mark -- 返回区头的高度
  100. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  101. {
  102. return section == 0 ? 0 : 30;
  103. }
  104. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  105. {
  106. UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 30)];
  107. headView.backgroundColor = kAppSpaceColor2;
  108. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, kScreenW / 2, 30)];
  109. if (section == 1 && self.thirdArr.count > 0) {
  110. label.text = ASLocalizedString(@"绑定第三方账号");
  111. }else{
  112. label.text = ASLocalizedString(@"安全");
  113. }
  114. label.textColor = [UIColor colorWithHexString:@"#AAAAAA"];
  115. label.font = [UIFont systemFontOfSize:11];
  116. [headView addSubview:label];
  117. return headView;
  118. }
  119. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  120. return nil;
  121. }
  122. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  123. return 0.01;
  124. }
  125. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  126. return self.listArr.count;
  127. }
  128. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  129. if (section == 0) return 2;
  130. if (self.thirdArr.count > 0 && section == 1) return self.thirdArr.count;
  131. if (section == 1 || section == 2) return 2;
  132. return 0;
  133. }
  134. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  135. // if (self.thirdArr.count > 0 && indexPath.section == 1){
  136. // return 0;
  137. // }
  138. return kRealValue(44);
  139. }
  140. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  141. SetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SetTableViewCell" forIndexPath:indexPath];
  142. NSArray *sectionArr = self.listArr[indexPath.section];
  143. // cell.setText.text = [NSString stringWithFormat:@"%@", sectionArr[indexPath.row]];
  144. cell.setText.text = sectionArr[indexPath.row];
  145. cell.nobleOpenSwitch.hidden = YES;
  146. cell.comeBackIMG.hidden = NO;
  147. cell.labOutLogin.hidden = YES;
  148. cell.memoryText.hidden = NO;
  149. if (indexPath.row == 0) {
  150. cell.line.hidden = NO;
  151. }
  152. if (indexPath.section == 1 && self.thirdArr.count == 1) {
  153. cell.line.hidden = YES;
  154. }
  155. [self setCellMemoryTextWithCell:cell indexPath:indexPath];
  156. return cell;
  157. }
  158. -(void)setCellMemoryTextWithCell:(SetTableViewCell *)cell indexPath:(NSIndexPath *)indexPath{
  159. if (!self.model) {
  160. return;
  161. }
  162. if (indexPath.section == 0 && indexPath.row == 0) {
  163. NSString *phoneNum = self.model.mobile;
  164. if (phoneNum.length < 10) {
  165. return;
  166. }
  167. cell.memoryText.text = [NSString stringWithFormat:@"%@****%@",[phoneNum substringToIndex:3],[phoneNum substringFromIndex:phoneNum.length - 4]];
  168. }
  169. if (indexPath.section == 0 && indexPath.row == 1) {
  170. cell.memoryText.text = ASLocalizedString(@"修改");
  171. return;
  172. }
  173. BOOL isHaveQQ = NO;
  174. BOOL isHaveWeiXin = NO;
  175. if ([GlobalVariables sharedInstance].appModel.has_qq_login == 1)//QQ
  176. {
  177. isHaveQQ = YES;
  178. }
  179. if ([GlobalVariables sharedInstance].appModel.has_wx_login == 1)//微信
  180. {
  181. isHaveWeiXin = YES;
  182. }
  183. if (isHaveQQ) {
  184. if (indexPath.section == 1 && indexPath.row == 0) {
  185. cell.memoryText.text = StrValid(self.model.QQ) ? self.model.QQ : ASLocalizedString(@"去绑定");
  186. cell.memoryText.textColor = StrValid(self.model.QQ) ? [UIColor colorWithHexString:@"#AAAAAA"] : [UIColor colorWithHexString:@"#F42416"];
  187. }
  188. }
  189. if (isHaveQQ && isHaveWeiXin) {
  190. if (indexPath.section == 1 && indexPath.row == 0) {
  191. cell.memoryText.text = StrValid(self.model.QQ) ? self.model.QQ : ASLocalizedString(@"去绑定");
  192. cell.memoryText.textColor = StrValid(self.model.QQ) ? [UIColor colorWithHexString:@"#AAAAAA"] : [UIColor colorWithHexString:@"#F42416"];
  193. }
  194. if (indexPath.section == 1 && indexPath.row == 1) {
  195. cell.memoryText.text = StrValid(self.model.wx) ? self.model.wx : ASLocalizedString(@"去绑定");
  196. cell.memoryText.textColor = StrValid(self.model.wx) ? [UIColor colorWithHexString:@"#AAAAAA"] : [UIColor colorWithHexString:@"#F42416"];
  197. }
  198. }else if (isHaveWeiXin){
  199. if (indexPath.section == 1 && indexPath.row == 0) {
  200. cell.memoryText.text = StrValid(self.model.wx) ? self.model.wx : ASLocalizedString(@"去绑定");
  201. cell.memoryText.textColor = StrValid(self.model.wx) ? [UIColor colorWithHexString:@"#AAAAAA"] : [UIColor colorWithHexString:@"#F42416"];
  202. }
  203. }
  204. NSInteger thirdIndex = self.thirdArr.count > 0 ? 2 : 1 ;
  205. if (indexPath.section == thirdIndex && indexPath.row == 0) {
  206. cell.memoryText.text = self.model.is_young.integerValue == 0 ? ASLocalizedString(@"未开启"): ASLocalizedString(@"已开启");
  207. cell.memoryText.textColor = [UIColor colorWithHexString:@"#AAAAAA"];
  208. }else if (indexPath.section == thirdIndex && indexPath.row == 1) {
  209. cell.memoryText.text = ASLocalizedString(@"注销账号后无法恢复,请谨慎操作");
  210. cell.memoryText.textColor = [UIColor colorWithHexString:@"#AAAAAA"];
  211. }
  212. }
  213. #pragma mark - UITableView Delegate methods
  214. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  215. SetTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  216. if ([cell.setText.text isEqualToString:ASLocalizedString(@"手机号")]) {
  217. BogoLoginViewController *vc = [BogoLoginViewController new];
  218. vc.loginType = BOGO_LOGIN_TYPE_PHONE_CONFIRM;
  219. vc.phoneNum = self.model.mobile;
  220. vc.tel_code = [self.model.tel_code containsString:@"?"] ? self.model.tel_code : [NSString stringWithFormat:@"+%@",self.model.tel_code];
  221. [self.navigationController pushViewController:vc animated:YES];
  222. return;
  223. }
  224. if ([cell.setText.text isEqualToString:ASLocalizedString(@"登录密码")]) {
  225. BogoLoginViewController *vc = [BogoLoginViewController new];
  226. vc.loginType = BOGO_LOGIN_TYPE_FORGET_CODE;
  227. vc.phoneNum = self.model.mobile;
  228. [self.navigationController pushViewController:vc animated:YES];
  229. return;
  230. }
  231. if ([cell.setText.text isEqualToString:ASLocalizedString(@"QQ")]) {
  232. }
  233. if ([cell.setText.text isEqualToString:ASLocalizedString(@"微信")]) {
  234. [self getWxLoginUserinfo];
  235. }
  236. if ([cell.setText.text isEqualToString:ASLocalizedString(@"青少年模式")]) {
  237. [self.youthView show:self.view type:FDPopTypeCenter];
  238. }
  239. if ([cell.setText.text isEqualToString:ASLocalizedString(@"注销账号")]) {
  240. BogoLogoutTextViewController *vc = [BogoLogoutTextViewController new];
  241. vc.phoneNum = self.model.mobile;
  242. [self.navigationController pushViewController:vc animated:YES];
  243. }
  244. }
  245. -(void)getWxLoginUserinfo{
  246. if (StrValid(self.model.wx)) {
  247. [FanweMessage alert:ASLocalizedString(@"提示") message:ASLocalizedString(@"确定解除账号与微信的关联吗?") destructiveAction:^{
  248. [self unBlindWXWithType:@"2"];
  249. } cancelAction:^{
  250. }];
  251. return;
  252. }
  253. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) {
  254. if (error) {
  255. NSDictionary *dic = error.userInfo;
  256. if (dic) {
  257. [FanweMessage alertHUD:[dic objectForKey:@"message"]];
  258. }else{
  259. [FanweMessage alertHUD:ASLocalizedString(@"操作失败")];
  260. }
  261. } else {
  262. UMSocialUserInfoResponse *resp = result;
  263. // 授权信息
  264. NSLog(@"Wechat uid: %@", resp.uid);
  265. NSLog(@"Wechat openid: %@", resp.openid);
  266. NSLog(@"Wechat unionid: %@", resp.unionId);
  267. NSLog(@"Wechat accessToken: %@", resp.accessToken);
  268. NSLog(@"Wechat refreshToken: %@", resp.refreshToken);
  269. NSLog(@"Wechat expiration: %@", resp.expiration);
  270. // 用户信息
  271. NSLog(@"Wechat name: %@", resp.name);
  272. NSLog(@"Wechat iconurl: %@", resp.iconurl);
  273. NSLog(@"Wechat gender: %@", resp.unionGender);
  274. // 第三方平台SDK源数据
  275. NSLog(@"Wechat originalResponse: %@", resp.originalResponse);
  276. [self blindWXName:resp.name openID:resp.openid];
  277. }
  278. }];
  279. }
  280. //解除微信绑定
  281. -(void)unBlindWXWithType:(NSString *)type{
  282. NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
  283. [paramDic setObject:@"unbound_account" forKey:@"act"];
  284. [paramDic setObject:@"login" forKey:@"ctl"];
  285. [paramDic setObject:[BGIMLoginManager sharedInstance].loginParam.identifier forKey:@"uid"];
  286. [paramDic setObject:type forKey:@"type"];//解绑类型【1QQ;2微信】
  287. [[NetHttpsManager manager] POSTWithParameters:paramDic SuccessBlock:^(NSDictionary *responseJson) {
  288. // if ([[responseJson valueForKey:@"status"] integerValue] == 1) {
  289. // self.model = [BogoSetAccountModel modelWithDictionary:[responseJson valueForKey:@"data"]];
  290. // [FanweMessage alertHUD:[responseJson valueForKey:@"error"]];
  291. //
  292. // }else{
  293. [FanweMessage alertHUD:[responseJson valueForKey:@"error"]];
  294. // }
  295. [self setModel];
  296. } FailureBlock:^(NSError *error) {
  297. [FanweMessage alertHUD:error.description];
  298. }];
  299. }
  300. //微信绑定
  301. -(void)blindWXName:(NSString *)wxName openID:(NSString *)openID{
  302. NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
  303. [paramDic setObject:@"wxopenid" forKey:@"act"];
  304. [paramDic setObject:@"login" forKey:@"ctl"];
  305. [paramDic setObject:wxName forKey:@"wx_name"];
  306. [paramDic setObject:openID forKey:@"wx_openid"];
  307. [[NetHttpsManager manager] POSTWithParameters:paramDic SuccessBlock:^(NSDictionary *responseJson) {
  308. // if ([[responseJson valueForKey:@"status"] integerValue] == 1) {
  309. // self.model = [BogoSetAccountModel modelWithDictionary:[responseJson valueForKey:@"data"]];
  310. // [FanweMessage alertHUD:[responseJson valueForKey:@"error"]];
  311. //
  312. // }else{
  313. [FanweMessage alertHUD:[responseJson valueForKey:@"error"]];
  314. // }
  315. [self setModel];
  316. } FailureBlock:^(NSError *error) {
  317. [FanweMessage alertHUD:error.description];
  318. }];
  319. }
  320. -(UITableView *)tableView{
  321. if (!_tableView) {
  322. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavigationHeight, kScreenW, kScreenH - NavigationHeight) style:UITableViewStyleGrouped];
  323. _tableView.delegate = self;
  324. _tableView.dataSource = self;
  325. [_tableView registerNib:[UINib nibWithNibName:@"SetTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SetTableViewCell"];
  326. _tableView.tableFooterView = [UIView new];
  327. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  328. }
  329. return _tableView;
  330. }
  331. -(BogoYounthModePopView *)youthView{
  332. if (!_youthView) {
  333. _youthView = [[BogoYounthModePopView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(331))];
  334. WeakSelf
  335. _youthView.clickInYounthBlock = ^(BOOL isComeIn) {
  336. // BogoYouthModeViewController *vc = [BogoYouthModeViewController new];
  337. // [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  338. BogoYouthModePassWordViewController *vc = [[BogoYouthModePassWordViewController alloc]initWithYounthType:BOGO_YOUNTH_TYPE_PASSWORD_SET];
  339. [[AppDelegate sharedAppDelegate]pushViewController:vc animated:YES];
  340. [weakSelf.youthView hide];
  341. };
  342. }
  343. return _youthView;
  344. }
  345. /*
  346. #pragma mark - Navigation
  347. // In a storyboard-based application, you will often want to do a little preparation before navigation
  348. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  349. // Get the new view controller using [segue destinationViewController].
  350. // Pass the selected object to the new view controller.
  351. }
  352. */
  353. @end