JXAcccountAnQuanVc.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. //
  2. // JXAcccountAnQuanVc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/26.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXAcccountAnQuanVc.h"
  9. #import "forgetPwdVC.h"
  10. #import "JXSheBenListVc.h"
  11. #import "JXXIuGaiJiXinHaoVc.h"
  12. #import "JXAccountPwd.h"
  13. #import "WXApi.h"
  14. #import <TencentOpenAPI/TencentOAuth.h>
  15. #import <TencentOpenAPI/QQApiInterface.h>
  16. #import "JXGenXinPhoneVc.h"
  17. #define HEIGHT 50
  18. #define MY_INSET 0 // 每行左右间隙
  19. #define TOP_ADD_HEIGHT 400 // 顶部添加的高度,防止下拉顶部空白
  20. typedef NS_ENUM(NSInteger, JXBindAccType) {
  21. JXBindQQ = 1, // QQ绑定
  22. JXBindWX, // 微信绑定
  23. };
  24. @interface JXAcccountAnQuanVc () <UIAlertViewDelegate,WXApiDelegate,WXApiManagerDelegate,TencentSessionDelegate,TencentLoginDelegate>
  25. @property (nonatomic, strong) UIButton *wxBindStatus;
  26. @property (nonatomic, strong) UIButton *qqBindStatus;
  27. @property (nonatomic, retain)TencentOAuth *oauth;
  28. @property (nonatomic, assign) JXBindAccType type;
  29. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewH;
  30. @property (weak, nonatomic) IBOutlet UIView *weiXinView;
  31. @property (weak, nonatomic) IBOutlet UIView *QQView;
  32. @property (weak, nonatomic) IBOutlet UIView *jiXinPwdView;
  33. @property (weak, nonatomic) IBOutlet UIView *sheBeiView;
  34. /**微信绑定后的 值*/
  35. @property (weak, nonatomic) IBOutlet UILabel *weiXinL;
  36. /*QQ绑定后的 值*/
  37. @property (weak, nonatomic) IBOutlet UILabel *qqL;
  38. @property (weak, nonatomic) IBOutlet UIView *jixinNumberView;
  39. @property (weak, nonatomic) IBOutlet UILabel *jixinL;
  40. @property (weak, nonatomic) IBOutlet UILabel *phoneL;
  41. @property (weak, nonatomic) IBOutlet UIView *shoujiView;
  42. @end
  43. @implementation JXAcccountAnQuanVc
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. // Do any additional setup after loading the view from its nib.
  47. self.topViewH.constant=JX_SCREEN_TOP+10;
  48. [self defineNavBar:@"账号安全与绑定" andRinghtBtnImg:@""];
  49. NSString *messs=[[NSUserDefaults standardUserDefaults] objectForKey:@"membershipAccount_ID"];
  50. self.jixinL.text=messs;
  51. JXUserObject *obj = [[JXUserObject sharedInstance] getUserById:MY_USER_ID];
  52. self.phoneL.text=obj.telephone;
  53. [_weiXinView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(weiXinViewGuest)]];
  54. [_QQView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(QQViewGuest)]];
  55. [_jiXinPwdView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jiXinPwdViewGuest)]];
  56. [_sheBeiView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sheBeiViewGuest)]];
  57. [_jixinNumberView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jixinNumberViewGuest)]];
  58. [_shoujiView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shoujiViewXXX)]];
  59. [SVProgressHUD showWithStatus:@"正在加载"];
  60. [g_server getBindInfo:self];
  61. }
  62. - (void)shoujiViewXXX{
  63. JXGenXinPhoneVc *vc=[JXGenXinPhoneVc new];
  64. vc.strURL=_phoneL.text;
  65. [g_navigation pushViewController:vc animated:YES];
  66. }
  67. - (void)viewWillAppear:(BOOL)animated{
  68. [super viewWillAppear:animated];
  69. //[g_notify addObserver:self selector:@selector(doRefresh:) name:kUpdateUserNotifaction object:nil];
  70. // [g_notify addObserver:self selector:@selector(updateUserInfo:) name:kXMPPMessageUpadteUserInfoNotification object:nil];
  71. //[g_notify addObserver:self selector:@selector(doRefresh:) name:kOfflineOperationUpdateUserSet object:nil];
  72. [g_server getUser:g_server.myself.userId toView:self];
  73. long time = (long)[[NSDate date] timeIntervalSince1970];
  74. time = (time *1000 + g_server.timeDifference);
  75. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  76. [g_server getUserVipInformation:salt andToView:self];
  77. }
  78. //-------------------------
  79. -(void)jixinNumberViewGuest{
  80. JXXIuGaiJiXinHaoVc *vc=[JXXIuGaiJiXinHaoVc new];
  81. [g_navigation pushViewController:vc animated:YES];
  82. }
  83. -(void)jiXinPwdViewGuest{
  84. JXAccountPwd *forgetVC = [[JXAccountPwd alloc]init];
  85. [g_navigation pushViewController:forgetVC animated:YES];
  86. }
  87. -(void)sheBeiViewGuest{
  88. JXSheBenListVc *vc=[JXSheBenListVc new];
  89. [g_navigation pushViewController:vc animated:YES];
  90. }
  91. /**
  92. * 绑定微信账号
  93. */
  94. -(void)weiXinViewGuest{
  95. self.type = JXBindWX;
  96. if (self.wxBindStatus.selected) {
  97. [g_App showAlert:Localized(@"JX_UnbindWeChat?") delegate:self tag:1001 onlyConfirm:NO];
  98. }else {
  99. [g_App showAlert:Localized(@"JX_BindWeChat?") delegate:self tag:1002 onlyConfirm:NO];
  100. }
  101. }
  102. /**
  103. * 绑定QQ 账号
  104. */
  105. -(void)QQViewGuest{
  106. self.type = JXBindQQ;
  107. if (self.qqBindStatus.selected) {
  108. [g_App showAlert:@"是否确认解绑QQ" delegate:self tag:1003 onlyConfirm:NO];
  109. }else {
  110. [g_App showAlert:@"是否确认绑定QQ" delegate:self tag:1004 onlyConfirm:NO];
  111. }
  112. }
  113. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  114. if (buttonIndex == 1) {
  115. if (alertView.tag == 1001) {
  116. [g_server setAccountUnbind:2 toView:self];
  117. }
  118. if (alertView.tag == 1002) {
  119. SendAuthReq* req = [[SendAuthReq alloc] init];
  120. req.scope = @"snsapi_userinfo"; // @"post_timeline,sns"
  121. req.state = @"login";
  122. req.openID = @"";
  123. [WXApi sendAuthReq:req
  124. viewController:self
  125. delegate:[WXApiManager sharedManager]];
  126. }
  127. if (alertView.tag == 1003) {
  128. [g_server setAccountUnbind:1 toView:self];
  129. }
  130. if (alertView.tag == 1004) {
  131. NSString *appid = g_App.QQ_LOGIN_APPID;
  132. _oauth = [[TencentOAuth alloc] initWithAppId:appid
  133. andDelegate:self];
  134. _oauth.authMode = kAuthModeClientSideToken;
  135. [_oauth authorize:[self getPermissions] inSafari:NO];
  136. }
  137. }
  138. }
  139. - (void)authRespNotification:(NSNotification *)notif {
  140. SendAuthResp *response = notif.object;
  141. NSString *strMsg = [NSString stringWithFormat:@"Auth结果 code:%@,state:%@,errcode:%d", response.code, response.state, response.errCode];
  142. NSLog(@"-------%@",strMsg);
  143. [g_server getWxOpenId:response.code toView:self];
  144. }
  145. // QQ登录成功回调
  146. - (void)tencentDidLogin {
  147. NSString *qqOpenId = _oauth.openId;
  148. g_server.openId = qqOpenId;
  149. if (qqOpenId.length > 0) {
  150. [self bindTel];
  151. }
  152. }
  153. - (NSMutableArray *)getPermissions {
  154. NSMutableArray * g_permissions = [[NSMutableArray alloc] initWithObjects:kOPEN_PERMISSION_GET_USER_INFO,
  155. kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,
  156. kOPEN_PERMISSION_ADD_ALBUM,
  157. kOPEN_PERMISSION_ADD_TOPIC,
  158. kOPEN_PERMISSION_CHECK_PAGE_FANS,
  159. kOPEN_PERMISSION_GET_INFO,
  160. kOPEN_PERMISSION_GET_OTHER_INFO,
  161. kOPEN_PERMISSION_LIST_ALBUM,
  162. kOPEN_PERMISSION_UPLOAD_PIC,
  163. kOPEN_PERMISSION_GET_VIP_INFO,
  164. kOPEN_PERMISSION_GET_VIP_RICH_INFO, nil];
  165. return g_permissions;
  166. }
  167. - (void)bindTel {
  168. JXUserObject *user = [[JXUserObject alloc] init];
  169. if ([g_default objectForKey:kMY_USER_PASSWORD]) {
  170. user.password = [g_default objectForKey:kMY_USER_PASSWORD];
  171. }
  172. NSString *areaCode = [g_default objectForKey:kMY_USER_AREACODE];
  173. user.areaCode = areaCode.length > 0 ? areaCode : @"86";
  174. if ([g_default objectForKey:kMY_USER_LoginName]) {
  175. user.telephone = [g_default objectForKey:kMY_USER_LoginName];
  176. }
  177. // [g_server thirdLogin:user type:2 openId:g_server.openId isLogin:YES toView:self];
  178. [g_server userBindWXAccount:user type:self.type openId:g_server.openId isLogin:YES toView:self];
  179. }
  180. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  181. [SVProgressHUD dismiss];
  182. if([aDownload.action isEqualToString:act_UserGet]){
  183. JXUserObject *obj = [[JXUserObject sharedInstance] getUserById:MY_USER_ID] ;
  184. [obj updateTelephone];
  185. self.phoneL.text=[dict objectForKey:@"telephone"];
  186. }
  187. if([aDownload.action isEqualToString:act_GetUserVipInformation]){
  188. }
  189. if([aDownload.action isEqualToString:act_unbind]){
  190. if (self.type == JXBindWX) {
  191. self.wxBindStatus.selected = NO;
  192. }else {
  193. self.qqBindStatus.selected = NO;
  194. }
  195. //[g_server showMsg:Localized(@"JX_UnboundSuccessfully")];
  196. }
  197. if ([aDownload.action isEqualToString:act_UserBindWXAccount]) {
  198. g_server.openId = nil;
  199. if (self.type == JXBindWX) {
  200. self.wxBindStatus.selected = YES;
  201. }else {
  202. self.qqBindStatus.selected = YES;
  203. }
  204. //[g_server showMsg:Localized(@"JX_BindingSuccessfully")];
  205. }
  206. if ([aDownload.action isEqualToString:act_GetWxOpenId]) {
  207. g_server.openId = [dict objectForKey:@"openid"];
  208. [self bindTel];
  209. }
  210. if( [aDownload.action isEqualToString:act_getBindInfo] ){
  211. if (array1.count > 0) {
  212. for (NSDictionary *dict in array1) {
  213. if ([[dict objectForKey:@"type"] intValue] == 2) {
  214. //微信绑定
  215. self.wxBindStatus.selected = YES;
  216. }
  217. if ([[dict objectForKey:@"type"] intValue] == 1) {
  218. //QQ绑定
  219. self.qqBindStatus.selected = YES;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  226. [SVProgressHUD dismiss];
  227. if ([aDownload.action isEqualToString:act_UserBindWXAccount]) {
  228. g_server.openId = nil;
  229. }
  230. return 1;
  231. }
  232. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  233. [SVProgressHUD dismiss];
  234. if ([aDownload.action isEqualToString:act_UserBindWXAccount]) {
  235. g_server.openId = nil;
  236. }
  237. return 1;
  238. }
  239. -(void) didServerConnectStart:(JXConnection*)aDownload{
  240. [SVProgressHUD showWithStatus:@"正在加载"];
  241. }
  242. @end