123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- //
- // ModifyPhoneChangeController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/22.
- //
- #import "ModifyPhoneChangeController.h"
- #import "PhoneChangeBodyView.h"
- #import "VeriCheckView.h"
- #import "LoginViewController.h"
- #import "AppDelegate.h"
- #import "CustomNavViewController.h"
- #import "JPUSHService.h"
- #import "RCConnectionManager.h"
- #import "NSString+phone.h"
- @interface ModifyPhoneChangeController ()
- {
- NSTimer *_time;
- int _count;
- }
- @property (nonatomic, strong) PhoneChangeBodyView *bodyView;
- @end
- @implementation ModifyPhoneChangeController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"新手机号绑定"];
- [self configUI];
- }
- - (void)configUI {
- self.bodyView = [PhoneChangeBodyView shareInstance];
- [self.scrollView addSubview:_bodyView];
- [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.right.left.mas_equalTo(self.view);
- make.height.mas_equalTo(kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
- }];
- MJWeakSelf;
- [self.bodyView changePhoneCallback:^(CHANGEACTION action, NSDictionary * _Nonnull parm) {
- [weakSelf operationWithAction:action parm:parm];
- }];
- }
- - (void)operationWithAction:(CHANGEACTION)action parm:(NSDictionary *)parm {
- if (![NSString isMobilePhoneNumber:[parm stringValueForKey:@"phone"]]) {
- [self MBPShow:@"手机号码输入有误"];
- return;
- }
- if (action == CHANGEACTION_CODE) {
- // 图形化验证
- [self veriCheckWithParm:parm];
- }
- else if (action == CHANGEACTION_SURE) {
- [self modifyPhoneWithParm:parm];
- }
- }
- #pragma mark --- 修改手机号
- - (void)modifyPhoneWithParm:(NSDictionary *)parm {
-
- [self showhud];
- [KSNetworkingManager updatePhoneRequest:KS_POST oldPhone:self.prePhone authCode:[parm stringValueForKey:@"code"] newPhone:[parm stringValueForKey:@"phone"] success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- MJWeakSelf;
- [self KSShowMsg:@"修改成功" promptCompletion:^{
- UserDefaultSet([parm stringValueForKey:@"phone"], PHONEKEY);
- [[NSUserDefaults standardUserDefaults] synchronize];
- [weakSelf successChangeBack];
- }];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
-
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
-
- }
- - (void)successChangeBack {
-
- [RCConnectionManager shareManager].isNeedJoin = NO;
- [RCConnectionManager shareManager].isNeedShowMessage = NO;
- [[RCIM sharedRCIM] logout];
- [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
- // 取消推送别名
- [JPUSHService deleteAlias:nil seq:0];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:TokenKey];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:Token_type];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:RefreshToken];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:RongTokenKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
- [KSNetworkingManager clearRequestHeader];
- LoginViewController *loginVC = [[LoginViewController alloc] init];
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:loginVC];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- appDelegate.window.rootViewController = navCtrl;
- }
- #pragma mark --- 验证码
- - (void)veriCheckWithParm:(NSDictionary *)parm {
- NSString *phoneNo = [parm stringValueForKey:@"phone"];
- // 图形化验证
- VeriCheckView *view = [VeriCheckView shareInstanceShowInView:self.view];
- __weak typeof(view) weakView = view;
- [view showViewCallback:^(NSDictionary * _Nonnull parm) {
- [self veriImageCodeWithParm:parm checkView:weakView];
- }];
- [view disPlayImageWithPhone:phoneNo];
- }
- - (void)veriImageCodeWithParm:(NSDictionary *)parm checkView:(VeriCheckView *)checkView {
- [self showhud];
- [KSNetworkingManager verifyLoginImageRequest:KS_POST phone:[parm stringValueForKey:@"phone"] code:[parm stringValueForKey:@"code"] success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- [checkView hiddView];
- [self sendSMSRequestWithParm:parm];
- }
- else {
- [self removehub];
- [self MBShowInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- // 发送短信
- - (void)sendSMSRequestWithParm:(NSDictionary *)parm {
- [KSNetworkingManager sendSmsRequest:KS_POST mobile:[parm stringValueForKey:@"phone"] type:@"PHONE" success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- [self MBPShow:@"验证码已发送"];
- [self codeButtonCountDown];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- - (void)codeButtonCountDown {
- _bodyView.codeButton.userInteractionEnabled = NO;
- [_bodyView.codeButton setTitleColor:HexRGB(0xe5e5e5) forState:UIControlStateNormal];
- __weak typeof(self) weakSelf = self;
- _time = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(buttonChangeAction) userInfo:nil repeats:YES];
- [[NSRunLoop mainRunLoop] addTimer:_time forMode:NSRunLoopCommonModes];
- _count = 89;
- }
- - (void)clearButtonState {
- [_time invalidate];
- _time = nil;
- _count = 0;
- [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
- [_bodyView.codeButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- _bodyView.codeButton.userInteractionEnabled = YES;
- }
- #pragma mark ---- 验证码按钮状态
- - (void)buttonChangeAction {
- _bodyView.codeButton.userInteractionEnabled = NO;
- NSString *title = [NSString stringWithFormat:@"%ds",_count];
- [_bodyView.codeButton setTitle:title forState:UIControlStateNormal];
- _count--;
- if(_count == -1){
- [_time invalidate];
- _time = nil;
- [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
- [_bodyView.codeButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- _bodyView.codeButton.userInteractionEnabled = YES; }
- }
- - (void)dealloc {
- [_time invalidate];
- _time = nil;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|