123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- //
- // JXAcccountAnQuanVc.m
- // shiku_im
- //
- // Created by 123 on 2020/5/26.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXAcccountAnQuanVc.h"
- #import "forgetPwdVC.h"
- #import "JXSheBenListVc.h"
- #import "JXXIuGaiJiXinHaoVc.h"
- #import "JXAccountPwd.h"
- #import "WXApi.h"
- #import <TencentOpenAPI/TencentOAuth.h>
- #import <TencentOpenAPI/QQApiInterface.h>
- #import "JXGenXinPhoneVc.h"
- #define HEIGHT 50
- #define MY_INSET 0 // 每行左右间隙
- #define TOP_ADD_HEIGHT 400 // 顶部添加的高度,防止下拉顶部空白
- typedef NS_ENUM(NSInteger, JXBindAccType) {
- JXBindQQ = 1, // QQ绑定
- JXBindWX, // 微信绑定
- };
- @interface JXAcccountAnQuanVc () <UIAlertViewDelegate,WXApiDelegate,WXApiManagerDelegate,TencentSessionDelegate,TencentLoginDelegate>
- @property (nonatomic, strong) UIButton *wxBindStatus;
- @property (nonatomic, strong) UIButton *qqBindStatus;
- @property (nonatomic, retain)TencentOAuth *oauth;
- @property (nonatomic, assign) JXBindAccType type;
-
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewH;
- @property (weak, nonatomic) IBOutlet UIView *weiXinView;
- @property (weak, nonatomic) IBOutlet UIView *QQView;
- @property (weak, nonatomic) IBOutlet UIView *jiXinPwdView;
- @property (weak, nonatomic) IBOutlet UIView *sheBeiView;
- /**微信绑定后的 值*/
- @property (weak, nonatomic) IBOutlet UILabel *weiXinL;
- /*QQ绑定后的 值*/
- @property (weak, nonatomic) IBOutlet UILabel *qqL;
- @property (weak, nonatomic) IBOutlet UIView *jixinNumberView;
- @property (weak, nonatomic) IBOutlet UILabel *jixinL;
- @property (weak, nonatomic) IBOutlet UILabel *phoneL;
- @property (weak, nonatomic) IBOutlet UIView *shoujiView;
- @end
- @implementation JXAcccountAnQuanVc
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- self.topViewH.constant=JX_SCREEN_TOP+10;
- [self defineNavBar:@"账号安全与绑定" andRinghtBtnImg:@""];
-
- NSString *messs=[[NSUserDefaults standardUserDefaults] objectForKey:@"membershipAccount_ID"];
-
-
- self.jixinL.text=messs;
- JXUserObject *obj = [[JXUserObject sharedInstance] getUserById:MY_USER_ID];
- self.phoneL.text=obj.telephone;
- [_weiXinView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(weiXinViewGuest)]];
- [_QQView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(QQViewGuest)]];
-
- [_jiXinPwdView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jiXinPwdViewGuest)]];
- [_sheBeiView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sheBeiViewGuest)]];
-
- [_jixinNumberView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jixinNumberViewGuest)]];
-
- [_shoujiView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shoujiViewXXX)]];
-
- [SVProgressHUD showWithStatus:@"正在加载"];
- [g_server getBindInfo:self];
- }
- - (void)shoujiViewXXX{
-
- JXGenXinPhoneVc *vc=[JXGenXinPhoneVc new];
- vc.strURL=_phoneL.text;
- [g_navigation pushViewController:vc animated:YES];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
- //[g_notify addObserver:self selector:@selector(doRefresh:) name:kUpdateUserNotifaction object:nil];
- // [g_notify addObserver:self selector:@selector(updateUserInfo:) name:kXMPPMessageUpadteUserInfoNotification object:nil];
- //[g_notify addObserver:self selector:@selector(doRefresh:) name:kOfflineOperationUpdateUserSet object:nil];
- [g_server getUser:g_server.myself.userId toView:self];
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server getUserVipInformation:salt andToView:self];
- }
- //-------------------------
- -(void)jixinNumberViewGuest{
-
- JXXIuGaiJiXinHaoVc *vc=[JXXIuGaiJiXinHaoVc new];
- [g_navigation pushViewController:vc animated:YES];
-
- }
- -(void)jiXinPwdViewGuest{
-
- JXAccountPwd *forgetVC = [[JXAccountPwd alloc]init];
- [g_navigation pushViewController:forgetVC animated:YES];
- }
- -(void)sheBeiViewGuest{
-
- JXSheBenListVc *vc=[JXSheBenListVc new];
- [g_navigation pushViewController:vc animated:YES];
-
- }
- /**
- * 绑定微信账号
- */
- -(void)weiXinViewGuest{
- self.type = JXBindWX;
- if (self.wxBindStatus.selected) {
- [g_App showAlert:Localized(@"JX_UnbindWeChat?") delegate:self tag:1001 onlyConfirm:NO];
- }else {
- [g_App showAlert:Localized(@"JX_BindWeChat?") delegate:self tag:1002 onlyConfirm:NO];
- }
- }
- /**
- * 绑定QQ 账号
- */
- -(void)QQViewGuest{
-
- self.type = JXBindQQ;
- if (self.qqBindStatus.selected) {
- [g_App showAlert:@"是否确认解绑QQ" delegate:self tag:1003 onlyConfirm:NO];
- }else {
- [g_App showAlert:@"是否确认绑定QQ" delegate:self tag:1004 onlyConfirm:NO];
- }
- }
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
- if (buttonIndex == 1) {
- if (alertView.tag == 1001) {
- [g_server setAccountUnbind:2 toView:self];
- }
- if (alertView.tag == 1002) {
- SendAuthReq* req = [[SendAuthReq alloc] init];
- req.scope = @"snsapi_userinfo"; // @"post_timeline,sns"
- req.state = @"login";
- req.openID = @"";
-
- [WXApi sendAuthReq:req
- viewController:self
- delegate:[WXApiManager sharedManager]];
- }
-
- if (alertView.tag == 1003) {
- [g_server setAccountUnbind:1 toView:self];
- }
- if (alertView.tag == 1004) {
- NSString *appid = g_App.QQ_LOGIN_APPID;
- _oauth = [[TencentOAuth alloc] initWithAppId:appid
- andDelegate:self];
-
- _oauth.authMode = kAuthModeClientSideToken;
- [_oauth authorize:[self getPermissions] inSafari:NO];
- }
- }
- }
- - (void)authRespNotification:(NSNotification *)notif {
- SendAuthResp *response = notif.object;
- NSString *strMsg = [NSString stringWithFormat:@"Auth结果 code:%@,state:%@,errcode:%d", response.code, response.state, response.errCode];
- // NSLog(@"-------%@",strMsg);
- [g_server getWxOpenId:response.code toView:self];
- }
- // QQ登录成功回调
- - (void)tencentDidLogin {
- NSString *qqOpenId = _oauth.openId;
- g_server.openId = qqOpenId;
-
- if (qqOpenId.length > 0) {
- [self bindTel];
- }
- }
- - (NSMutableArray *)getPermissions {
- NSMutableArray * g_permissions = [[NSMutableArray alloc] initWithObjects:kOPEN_PERMISSION_GET_USER_INFO,
- kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,
- kOPEN_PERMISSION_ADD_ALBUM,
- kOPEN_PERMISSION_ADD_TOPIC,
- kOPEN_PERMISSION_CHECK_PAGE_FANS,
- kOPEN_PERMISSION_GET_INFO,
- kOPEN_PERMISSION_GET_OTHER_INFO,
- kOPEN_PERMISSION_LIST_ALBUM,
- kOPEN_PERMISSION_UPLOAD_PIC,
- kOPEN_PERMISSION_GET_VIP_INFO,
- kOPEN_PERMISSION_GET_VIP_RICH_INFO, nil];
- return g_permissions;
- }
- - (void)bindTel {
- JXUserObject *user = [[JXUserObject alloc] init];
- if ([g_default objectForKey:kMY_USER_PASSWORD]) {
- user.password = [g_default objectForKey:kMY_USER_PASSWORD];
- }
- NSString *areaCode = [g_default objectForKey:kMY_USER_AREACODE];
- user.areaCode = areaCode.length > 0 ? areaCode : @"86";
- if ([g_default objectForKey:kMY_USER_LoginName]) {
- user.telephone = [g_default objectForKey:kMY_USER_LoginName];
- }
-
-
- // [g_server thirdLogin:user type:2 openId:g_server.openId isLogin:YES toView:self];
- [g_server userBindWXAccount:user type:self.type openId:g_server.openId isLogin:YES toView:self];
- }
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
- [SVProgressHUD dismiss];
-
- if([aDownload.action isEqualToString:act_UserGet]){
- JXUserObject *obj = [[JXUserObject sharedInstance] getUserById:MY_USER_ID] ;
- [obj updateTelephone];
- self.phoneL.text=[dict objectForKey:@"telephone"];
- }
-
- if([aDownload.action isEqualToString:act_GetUserVipInformation]){
-
-
- }
- if([aDownload.action isEqualToString:act_unbind]){
- if (self.type == JXBindWX) {
- self.wxBindStatus.selected = NO;
- }else {
- self.qqBindStatus.selected = NO;
- }
- //[g_server showMsg:Localized(@"JX_UnboundSuccessfully")];
- }
- if ([aDownload.action isEqualToString:act_UserBindWXAccount]) {
- g_server.openId = nil;
- if (self.type == JXBindWX) {
- self.wxBindStatus.selected = YES;
- }else {
- self.qqBindStatus.selected = YES;
- }
- //[g_server showMsg:Localized(@"JX_BindingSuccessfully")];
- }
- if ([aDownload.action isEqualToString:act_GetWxOpenId]) {
-
- g_server.openId = [dict objectForKey:@"openid"];
- [self bindTel];
- }
- if( [aDownload.action isEqualToString:act_getBindInfo] ){
- if (array1.count > 0) {
- for (NSDictionary *dict in array1) {
- if ([[dict objectForKey:@"type"] intValue] == 2) {
- //微信绑定
- self.wxBindStatus.selected = YES;
- }
- if ([[dict objectForKey:@"type"] intValue] == 1) {
- //QQ绑定
- self.qqBindStatus.selected = YES;
- }
- }
- }
- }
- }
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
- [SVProgressHUD dismiss];
- if ([aDownload.action isEqualToString:act_UserBindWXAccount]) {
- g_server.openId = nil;
- }
- return 1;
- }
- -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
- [SVProgressHUD dismiss];
- if ([aDownload.action isEqualToString:act_UserBindWXAccount]) {
- g_server.openId = nil;
- }
- return 1;
- }
- -(void) didServerConnectStart:(JXConnection*)aDownload{
- [SVProgressHUD showWithStatus:@"正在加载"];
- }
- @end
|