Commit 5da89d23 authored by IOS-张 博's avatar IOS-张 博

微信 apple授权

parent f717792e
......@@ -335,6 +335,7 @@
97CDB66E2292C19700257F77 /* QGAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 97CDB66C2292C18700257F77 /* QGAlertView.m */; };
97CDB6A022967A9700257F77 /* QGBatchRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 97CDB69F22967A9700257F77 /* QGBatchRequestOperation.m */; };
97CDB6A322967F2200257F77 /* QGBatchOperationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 97CDB6A222967F2200257F77 /* QGBatchOperationManager.m */; };
9E0D3029247BCC4000FA0E09 /* QGAppleInfoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E0D3028247BCC4000FA0E09 /* QGAppleInfoModel.m */; };
9E17BD4E2458122A0019F8D0 /* QGMembershipNotificationCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E17BD4D2458122A0019F8D0 /* QGMembershipNotificationCell.m */; };
9E17BD51245817A20019F8D0 /* QGMembershipProfitCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E17BD50245817A20019F8D0 /* QGMembershipProfitCell.m */; };
9E17BD5424582D350019F8D0 /* QGMembershipTaskCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E17BD5324582D350019F8D0 /* QGMembershipTaskCell.m */; };
......@@ -1327,6 +1328,8 @@
97CDB69F22967A9700257F77 /* QGBatchRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QGBatchRequestOperation.m; sourceTree = "<group>"; };
97CDB6A122967F2200257F77 /* QGBatchOperationManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QGBatchOperationManager.h; sourceTree = "<group>"; };
97CDB6A222967F2200257F77 /* QGBatchOperationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QGBatchOperationManager.m; sourceTree = "<group>"; };
9E0D3027247BCC4000FA0E09 /* QGAppleInfoModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QGAppleInfoModel.h; sourceTree = "<group>"; };
9E0D3028247BCC4000FA0E09 /* QGAppleInfoModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QGAppleInfoModel.m; sourceTree = "<group>"; };
9E17BD4C2458122A0019F8D0 /* QGMembershipNotificationCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QGMembershipNotificationCell.h; sourceTree = "<group>"; };
9E17BD4D2458122A0019F8D0 /* QGMembershipNotificationCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QGMembershipNotificationCell.m; sourceTree = "<group>"; };
9E17BD4F245817A20019F8D0 /* QGMembershipProfitCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QGMembershipProfitCell.h; sourceTree = "<group>"; };
......@@ -5290,6 +5293,8 @@
children = (
9EB1DB3B22C1B992008D28CE /* QGCaptchaNewModel.h */,
9EB1DB3A22C1B992008D28CE /* QGCaptchaNewModel.m */,
9E0D3027247BCC4000FA0E09 /* QGAppleInfoModel.h */,
9E0D3028247BCC4000FA0E09 /* QGAppleInfoModel.m */,
);
path = Model;
sourceTree = "<group>";
......@@ -6055,6 +6060,7 @@
9E74E1322382762A006E4926 /* QGBindingCardCell.m in Sources */,
9EB1D14222BC7FC3008D28CE /* QGCardBannerCell.m in Sources */,
9EB1D91922BCEEDD008D28CE /* QNDes.m in Sources */,
9E0D3029247BCC4000FA0E09 /* QGAppleInfoModel.m in Sources */,
7F58DC5122BA5F7000F2A15F /* QGRetrievePasswordCell.m in Sources */,
461B92E32406384A0010ADEA /* QGMallSearchHistorySectionView.m in Sources */,
7F4C810F22CA02AA003B9D07 /* QGMessageCenterVC.m in Sources */,
......
......@@ -13,10 +13,17 @@
#import "QGLoginProtocolCell.h"
#import "QGLoginBottomBtnTableViewCell.h"
#import "QGBindingVerifyCodeCell.h"
#import "QGAlertView.h"
//Tool
#import "QGCountDown.h"
#import "QGSendMessageCodeManger.h"
#import "QGLoginRequestApi.h"
#import "QGPushService.h"
//Model
#import "ZHWeChatTool.h"
#import "QGAppleInfoModel.h"
@interface QGBindingPhoneViewController ()
......@@ -42,20 +49,35 @@
@property (nonatomic, strong) QGCountDown * countDownTimer;
/// 倒计时剩余时间
@property (nonatomic, assign)NSInteger residueTime;
@property (nonatomic, assign) NSInteger residueTime;
///获取短信验证码管理类
@property (nonatomic, strong) QGSendMessageCodeManger * sendVerifyCodeManger;
/// 微信用户信息
@property (nonatomic, strong) QGWechatLoginInfoModel * wechatInfoModel;
/// 苹果用户信息
@property (nonatomic, strong) QGAppleInfoModel * appleInfoModel;
@end
@implementation QGBindingPhoneViewController
- (BOOL)checkParameters:(NSDictionary *)param
{
return YES;
if (param[@"wechatInfoModel"] || param[@"appleInfoModel"]) {
return YES;
}
return NO;
}
- (void)transferParameters:(NSDictionary *)param
{
self.wechatInfoModel = param[@"wechatInfoModel"];
self.appleInfoModel = param[@"appleInfoModel"];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
......@@ -80,6 +102,152 @@
}
#pragma mark - Request
//微信登录验证码校验
-(void)wechatCheckVerifyCodeRequest
{
NSString *urlStr = [QGLoginRequestApi urlWithQGLoginRequestServerMethod:QGLoginRequestServerMethodLoginWechat];
NSMutableDictionary * infoDic = [NSMutableDictionary dictionaryWithCapacity:0];
[infoDic setObject:IsStringNull(self.phoneString) forKey:@"loginName"];
[infoDic setObject:IsStringNull(self.verifyCodeString) forKey:@"smsCode"];
[infoDic setObject:IsStringNull(self.wechatInfoModel.openid) forKey:@"openId"];
[infoDic setObject:IsStringNull(self.wechatInfoModel.unionid) forKey:@"unionId"];
[infoDic setObject:IsStringNull(self.wechatInfoModel.nickname) forKey:@"nickName"];
[infoDic setObject:IsStringNull(self.wechatInfoModel.headimgurl) forKey:@"headImgUrl"];
//1 为男性,2 为女性
if (self.wechatInfoModel.sex.integerValue == 1) {
[infoDic setObject:@"M" forKey:@"sex"];
}
else if (self.wechatInfoModel.sex.integerValue == 2)
{
[infoDic setObject:@"F" forKey:@"sex"];
}
else
{
[infoDic setObject:@"N" forKey:@"sex"];
}
[QGHUDManager showHud:nil];
[[QGTalosNetwork shareManager] POST:urlStr parameters:infoDic success:^(id _Nonnull responseObject) {
[QGHUDManager hideHud];
//业务处理成功
if ([QGBaseNetwork checkBusinessCodeAndCodeWithResponseObjectObject:responseObject]) {
//短验登陆成功
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:@"APP注册" forKey:@"abse_page_name"];
[info setObject:@"验证码登录" forKey:@"abse_action_name"];
[info setObject:@"success" forKey:@"abse_state_value"];
[QGAnalyticsService analyticsTrack:@"AppBusinessStateEvent" withProperties: info];
NSDictionary * dataDic = responseObject[@"data"];
//保存登录信息
[self loginSuccessSaveUserInfo:dataDic];
//关闭页面
[self performSelector:@selector(dismissPressed) withObject:nil afterDelay:0.2];
}
//弹窗处理
else if ([responseObject[@"businessCode"] isEqualToString:@"1010"])
{
QGAlertView * alertView = [[QGAlertView alloc] initWithTitle:nil message:@"该手机号已绑定其他微信账号" cancelButtonTitle:nil sureButtonTitle:@"知道了" clickBlock:nil];
[alertView showInView:nil];
}
//业务处理失败
else
{
[QGHUDManager showHudWithError:responseObject];
}
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
[QGHUDManager showHud:[QGBaseNetwork getMessageWithFailureError:error]];
}];
}
//apple登录验证码校验
-(void)appleCheckVerifyCodeRequest
{
NSString *urlStr = [QGLoginRequestApi urlWithQGLoginRequestServerMethod:QGLoginRequestServerMethodLoginApple];
NSMutableDictionary * infoDic = [NSMutableDictionary dictionaryWithCapacity:0];
[infoDic setObject:IsStringNull(self.phoneString) forKey:@"loginName"];
[infoDic setObject:IsStringNull(self.verifyCodeString) forKey:@"smsCode"];
[infoDic setObject:IsStringNull(self.appleInfoModel.userID) forKey:@"appleUserId"];
[infoDic setObject:IsStringNull(self.appleInfoModel.fullName) forKey:@"appleFullName"];
[infoDic setObject:IsStringNull(self.appleInfoModel.identityToken) forKey:@"identityToken"];
[QGHUDManager showHud:nil];
[[QGTalosNetwork shareManager] POST:urlStr parameters:infoDic success:^(id _Nonnull responseObject) {
[QGHUDManager hideHud];
//业务处理成功
if ([QGBaseNetwork checkBusinessCodeAndCodeWithResponseObjectObject:responseObject]) {
//短验登陆成功
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:@"APP注册" forKey:@"abse_page_name"];
[info setObject:@"验证码登录" forKey:@"abse_action_name"];
[info setObject:@"success" forKey:@"abse_state_value"];
[QGAnalyticsService analyticsTrack:@"AppBusinessStateEvent" withProperties: info];
NSDictionary * dataDic = responseObject[@"data"];
//保存登录信息
[self loginSuccessSaveUserInfo:dataDic];
//关闭页面
[self performSelector:@selector(dismissPressed) withObject:nil afterDelay:0.2];
}
//弹窗处理
else if ([responseObject[@"businessCode"] isEqualToString:@"1010"])
{
QGAlertView * alertView = [[QGAlertView alloc] initWithTitle:nil message:@"该手机号已绑定其他Apple账号" cancelButtonTitle:nil sureButtonTitle:@"知道了" clickBlock:nil];
[alertView showInView:nil];
}
//业务处理失败
else
{
[QGHUDManager showHudWithError:responseObject];
}
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
[QGHUDManager showHud:[QGBaseNetwork getMessageWithFailureError:error]];
}];
}
//完成登录并回调
- (void)loginSuccessSaveUserInfo:(NSDictionary *)responseObject
{
if ([responseObject valueForKey:@"token"]) {
[QGAnalyticsService analyticsLoginWithUUID:[responseObject objectForKey:@"uuid"]];
[QGHUDManager showHud:@"登录成功"];
[QGUserInfo sharedUserInfo].hasPassword = [[responseObject objectForKey:@"hasPassword"] boolValue];
[QGUserInfo sharedUserInfo].userName = responseObject[@"phoneNo"];
[QGUserInfo sharedUserInfo].token = [responseObject objectForKey:@"token"];
[QGUserInfo sharedUserInfo].uuid = [responseObject objectForKey:@"uuid"];
[QGUserInfo sharedUserInfo].vccRefreshToken = [responseObject objectForKey:@"vccRefreshToken"];
[QGUserInfo sharedUserInfo].userId = [NSString stringWithFormat:@"%@", responseObject[@"userId"]];
[QGUserInfo sharedUserInfo].alimamaAuth = [responseObject[@"alimamaAuth"] boolValue];
[QGUserInfo sharedUserInfo].login = YES;
[QGPushService setPushAccount:[QGUserInfo sharedUserInfo].userId];
[[NSNotificationCenter defaultCenter] postNotificationName:ModelCenterUserLoginNotification object:nil];
}
}
//登录完成后取消当前页面
- (void)dismissPressed
{
[self.view endEditing:YES];
[self.navigationController dismissViewControllerAnimated:NO completion:^{
if (self.callBackBlock) {
self.callBackBlock(LoginTag_QGMainLoginViewController_LoginSuccess, nil);
}
}];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
......@@ -239,11 +407,21 @@
return;
}
//绑定微信
if (self.wechatInfoModel) {
[self wechatCheckVerifyCodeRequest];
}
//绑定apple ID
else if (self.appleInfoModel)
{
[self appleCheckVerifyCodeRequest];
}
}
///验证码按钮点击事件
- (void)codeButtonClick
{
......
......@@ -315,7 +315,6 @@
[QGUserInfo sharedUserInfo].userId = [NSString stringWithFormat:@"%@", responseObject[@"userId"]];
[QGUserInfo sharedUserInfo].alimamaAuth = [responseObject[@"alimamaAuth"] boolValue];
[QGUserInfo sharedUserInfo].login = YES;
[QGUserInfo sharedUserInfo].loginTime = [[QGCalendarManager shareInstance] getStringFromDate:[NSDate date] formatter:@"yyyy-MM-dd HH:mm:ss"];
//密码登陆成功,说明有密码
[QGUserInfo sharedUserInfo].hasPassword = YES;
[QGPushService setPushAccount:[QGUserInfo sharedUserInfo].userId];
......
//
// QGAppleInfoModel.h
// VirtualPayment
//
// Created by 张博 on 2020/5/25.
// Copyright © 2020 bo.zhang. All rights reserved.
//
#import "QGBaseModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface QGAppleInfoModel : QGBaseModel
///token, code验证数据,用于传给开发者后台服务器,然后开发者服务器再向苹果的身份验证服务端验证本次授权登录请求数据的有效性和真实性
@property (nonatomic, strong) NSString * authorizationCode;
@property (nonatomic, strong) NSString * identityToken;
/// 苹果用户唯一标识符,该值在同一个开发者账号下的所有 App 下是一样的
@property (nonatomic, strong) NSString * userID;
@property (nonatomic, strong) NSString * fullName;
@end
NS_ASSUME_NONNULL_END
//
// QGAppleInfoModel.m
// VirtualPayment
//
// Created by 张博 on 2020/5/25.
// Copyright © 2020 bo.zhang. All rights reserved.
//
#import "QGAppleInfoModel.h"
@implementation QGAppleInfoModel
@end
......@@ -143,7 +143,6 @@
[QGUserInfo sharedUserInfo].userId = [NSString stringWithFormat:@"%@", responseObject[@"userId"]];
[QGUserInfo sharedUserInfo].alimamaAuth = [responseObject[@"alimamaAuth"] boolValue];
[QGUserInfo sharedUserInfo].login = YES;
[QGUserInfo sharedUserInfo].loginTime = [[QGCalendarManager shareInstance] getStringFromDate:[NSDate date] formatter:@"yyyy-MM-dd HH:mm:ss"];
[QGPushService setPushAccount:[QGUserInfo sharedUserInfo].userId];
[[NSNotificationCenter defaultCenter] postNotificationName:ModelCenterUserLoginNotification object:nil];
}
......
......@@ -12,6 +12,8 @@
#import "QGBasicUITool.h"
#import "QGSendMessageCodeManger.h"
#import "QGThirdPlatformService.h"
#import "QGLoginRequestApi.h"
#import "QGPushService.h"
//View
#import "QGPhoneInputWithTitleCell.h"
......@@ -20,18 +22,28 @@
#import "QGLoginProtocolCell.h"
#import "QGLoginBottomView.h"
//Model
#import "QGAppleInfoModel.h"
#import <AuthenticationServices/AuthenticationServices.h>
@interface QGRegisterViewController ()<UITextViewDelegate, ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>
///header
@property (nonatomic, strong)UIView *tableHeaderView;
///用于记录输入的手机号
@property (nonatomic, copy)NSString *phoneString;
///用于修改底部按钮的可点击状态
@property (nonatomic, copy)void(^changeButtonStatus)(BOOL ableClick);
///是否已同意用户协议
@property (assign, nonatomic) BOOL isSelect;
/// 微信登录模型
@property (nonatomic, strong) QGWechatLoginInfoModel * wechatInfoModel;
/// apple登录模型
@property (nonatomic, strong) QGAppleInfoModel * appleInfoModel;
@end
@implementation QGRegisterViewController
......@@ -43,8 +55,11 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self initNormalUI];
}
- (void)initNormalUI
{
//设置tableHeaderView
UILabel *welcomeLabel = [UIView creatLabelWithSuperView:self.tableHeaderView title:@"欢迎使用真享生活" titleFontSize:[UIFont qg_regularFontOfSize:30] textColor:[UIColor textColor3333] alignment:NSTextAlignmentLeft];
[welcomeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
......@@ -93,12 +108,91 @@
break;
}
};
}
#pragma mark - Reqeust
/// 检测微信是否绑定
- (void)checkWechatBinding
{
if ([NSString isEmpty:self.wechatInfoModel.openid]) {
return;
}
NSString * urlString = [QGLoginRequestApi urlWithQGLoginRequestServerMethod:QGLoginRequestServerMethodCheckWechatBinding];
urlString = @"http://yapi.quantgroups.com/mock/305/vcc/external/login/weChat_opId";
NSDictionary * infoDic = @{@"openId":self.wechatInfoModel.openid};
[QGHUDManager showHud:nil];
[[QGTalosNetwork shareManager] POST:urlString parameters:infoDic success:^(id _Nonnull responseObject) {
[QGHUDManager hideHud];
//请求成功
if ([QGBaseNetwork checkBusinessCodeAndCodeWithResponseObjectObject:responseObject]) {
NSDictionary * dataDic = responseObject[@"data"];
//0:未绑定,1:已绑定
BOOL checkStatus = [dataDic[@"checkStatus"] boolValue];
//已绑定
if (checkStatus){
//保存登录信息
[self loginSuccessSaveUserInfo:dataDic[@"loginInfo"]];
//关闭页面
[self performSelector:@selector(dismissPressed) withObject:nil afterDelay:0.2];
}
//未绑定
else
{
[Mediator performTarget:ClassNameWithHeadType(QGHeaderTypeQGBindingPhoneViewController) parameters:@{@"wechatInfoModel":self.wechatInfoModel} handlerBlock:nil];
}
}
else
{
[QGHUDManager showHudWithError:responseObject];
}
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
[QGHUDManager showHud:[QGBaseNetwork getMessageWithFailureError:error]];
}];
}
- (void)checkAppleBinding
{
NSString * urlString = [QGLoginRequestApi urlWithQGLoginRequestServerMethod:QGLoginRequestServerMethodCheckAppleBinding];
urlString = @"http://yapi.quantgroups.com/mock/305/vcc/external/login/apple_idtoken";
[QGHUDManager showHud:nil];
NSDictionary * infoDic = @{@"identityToken" : self.appleInfoModel.identityToken,
@"authorizationCode" : self.appleInfoModel.authorizationCode,
@"appleUserId" : self.appleInfoModel.userID
};
[QGHUDManager showHud:nil];
[[QGTalosNetwork shareManager] POST:urlString parameters:infoDic success:^(id _Nonnull responseObject) {
[QGHUDManager hideHud];
//请求成功
if ([QGBaseNetwork checkBusinessCodeAndCodeWithResponseObjectObject:responseObject]) {
NSDictionary * dataDic = responseObject[@"data"];
//0:未绑定,1:已绑定
BOOL checkStatus = [dataDic[@"checkStatus"] boolValue];
//已绑定
if (checkStatus){
//保存登录信息
[self loginSuccessSaveUserInfo:dataDic[@"loginInfo"]];
//关闭页面
[self performSelector:@selector(dismissPressed) withObject:nil afterDelay:0.2];
}
//未绑定
else
{
[Mediator performTarget:ClassNameWithHeadType(QGHeaderTypeQGBindingPhoneViewController) parameters:@{@"appleInfoModel":self.appleInfoModel} handlerBlock:nil];
}
}
else
{
[QGHUDManager showHudWithError:responseObject];
}
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
[QGHUDManager showHud:[QGBaseNetwork getMessageWithFailureError:error]];
}];;
}
#pragma mark - UITableViewDataSource
......@@ -253,11 +347,6 @@
}
-(UIView *)tableHeaderView
{
if (!_tableHeaderView) {
......@@ -269,17 +358,51 @@
return _tableHeaderView;
}
#pragma mark - Action
//登录完成后取消当前页面
- (void)dismissPressed
{
[self.view endEditing:YES];
[self.navigationController dismissViewControllerAnimated:NO completion:^{
if (self.callBackBlock) {
self.callBackBlock(LoginTag_QGMainLoginViewController_LoginSuccess, nil);
}
}];
}
//完成登录并回调
- (void)loginSuccessSaveUserInfo:(NSDictionary *)responseObject
{
if ([responseObject valueForKey:@"token"]) {
[QGAnalyticsService analyticsLoginWithUUID:[responseObject objectForKey:@"uuid"]];
[QGHUDManager showHud:@"登录成功"];
[QGUserInfo sharedUserInfo].hasPassword = [[responseObject objectForKey:@"hasPassword"] boolValue];
[QGUserInfo sharedUserInfo].userName = responseObject[@"phoneNo"];
[QGUserInfo sharedUserInfo].token = [responseObject objectForKey:@"token"];
[QGUserInfo sharedUserInfo].uuid = [responseObject objectForKey:@"uuid"];
[QGUserInfo sharedUserInfo].vccRefreshToken = [responseObject objectForKey:@"vccRefreshToken"];
[QGUserInfo sharedUserInfo].userId = [NSString stringWithFormat:@"%@", responseObject[@"userId"]];
[QGUserInfo sharedUserInfo].alimamaAuth = [responseObject[@"alimamaAuth"] boolValue];
[QGUserInfo sharedUserInfo].login = YES;
[QGPushService setPushAccount:[QGUserInfo sharedUserInfo].userId];
[[NSNotificationCenter defaultCenter] postNotificationName:ModelCenterUserLoginNotification object:nil];
}
}
#pragma mark - 微信登录
/// 微信登录
- (void)signInWithWechat
{
[Mediator performTarget:ClassNameWithHeadType(QGHeaderTypeQGBindingPhoneViewController) parameters:nil handlerBlock:nil];
@weakify(self);
//微信登录
// [[QGThirdPlatformService shareInstance] wxAuthWithSuccess:^(NSDictionary *infoDic) {
//
// }];
[[QGThirdPlatformService shareInstance] wxAuthWithSuccess:^(QGWechatLoginInfoModel *infoModel) {
@strongify(self);
self.wechatInfoModel = infoModel;
[self checkWechatBinding];
}];
}
#pragma mark - Apple登录
......@@ -311,19 +434,23 @@
{
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
ASAuthorizationAppleIDCredential *credential = authorization.credential;
//苹果用户唯一标识,同一开发者账号下的APP获取到是一样的
NSString *userID = credential.user;
NSPersonNameComponents *fullName = credential.fullName;
//验证数据,传给后台
NSString *authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding]; // refresh token
NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding]; // access token
NSString *authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding];
NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding];
NSLog(@"userID: %@", userID);
NSLog(@"fullName: %@", fullName);
NSLog(@"authorizationCode: %@", authorizationCode);
NSLog(@"identityToken: %@", identityToken);
// NSLog(@"userID: %@", userID);
// NSLog(@"fullName: %@", fullName);
// NSLog(@"authorizationCode: %@", authorizationCode);
// NSLog(@"identityToken: %@", identityToken);
self.appleInfoModel = [[QGAppleInfoModel alloc] init];
self.appleInfoModel.userID = userID;
self.appleInfoModel.fullName = fullName;
self.appleInfoModel.authorizationCode = authorizationCode;
self.appleInfoModel.identityToken = identityToken;
[self checkAppleBinding];
}
}
......
......@@ -26,7 +26,17 @@ typedef NS_ENUM(NSInteger, QGLoginRequestServerMethod) {
///8.获取图形验证码
QGLoginRequestServerMethodSmsCaptcha,
///9发送验证码的验证类型
QGLoginRequestServerMethodSmsCaptchaType
QGLoginRequestServerMethodSmsCaptchaType,
///微信登录绑定校验
QGLoginRequestServerMethodCheckWechatBinding,
///微信绑定手机号登陆
QGLoginRequestServerMethodLoginWechat,
///apple登录绑定校验
QGLoginRequestServerMethodCheckAppleBinding,
///apple绑定手机号登陆
QGLoginRequestServerMethodLoginApple,
};
/*!
......
......@@ -39,6 +39,22 @@
case QGLoginRequestServerMethodSmsCaptchaType://9发送验证码的验证类型
url = @"vcc/usercenter/captcha_type";
break;
//微信登录绑定校验
case QGLoginRequestServerMethodCheckWechatBinding:
url = @"vcc/external/login/weChat_opId";
break;
//微信登录关联手机号
case QGLoginRequestServerMethodLoginWechat:
url = @"vcc/external/login/weChat";
break;
//apple登录绑定校验
case QGLoginRequestServerMethodCheckAppleBinding:
url = @"vcc/external/login/apple_idtoken";
break;
//苹果登录绑定校验
case QGLoginRequestServerMethodLoginApple:
url = @"vcc/external/login/apple";
break;
default:
break;
}
......
......@@ -35,8 +35,6 @@
///用户是否登录
@property (nonatomic,getter=isLogin) BOOL login;
///登录时间
@property (nonatomic,strong) NSString *loginTime;
///是否已经设置密码
@property (nonatomic, assign)BOOL hasPassword;
......
......@@ -211,12 +211,7 @@ static QGUserInfo *userInfo = nil;
[QGUserInfo archive];
}
-(void)setLoginTime:(NSString *)loginTime
{
_loginTime = loginTime;
[QGUserInfo archive];
}
-(void)setHasPassword:(BOOL)hasPassword
{
......
......@@ -433,10 +433,11 @@
- (void)weChatLoginEvent
{
@weakify(self);
[[QGThirdPlatformService shareInstance] wxAuthWithSuccess:^(NSDictionary *infoDic) {
[[QGThirdPlatformService shareInstance] wxAuthWithSuccess:^(QGWechatLoginInfoModel * infoModel) {
@strongify(self);
NSDictionary *callDic = @{@"event" : @"wxAuthSuccess",
@"data" : infoDic};
@"data" : [infoModel yy_modelToJSONObject]};
[self callJSWithMethod:@"xyqbNativeEvent" callWithArguments:@[callDic]];
}];
}
......
......@@ -7,7 +7,7 @@
//
#import <Foundation/Foundation.h>
#import "ZHWeChatTool.h"
typedef NS_ENUM(NSInteger,QGShareItemType){
QGShareItemTypeWeChat = 1, // 微信好友
......@@ -70,7 +70,7 @@ typedef NS_ENUM(NSInteger,QGShareItemType){
/// 微信登录
/// @param successBlock 成功回调
- (void)wxAuthWithSuccess:(void(^)(NSDictionary * infoDic))successBlock;
- (void)wxAuthWithSuccess:(void(^)(QGWechatLoginInfoModel * infoModel))successBlock;
/**
* 第三方平台回调
......
......@@ -197,14 +197,15 @@ static QGThirdPlatformService * shareService = nil;
/// 微信登录
/// @param successBlock 成功回调
- (void)wxAuthWithSuccess:(void(^)(NSDictionary * infoDic))successBlock
- (void)wxAuthWithSuccess:(void(^)(QGWechatLoginInfoModel * infoModel))successBlock
{
[[ZHWeChatTool share] WXLogin];
[ZHWeChatTool share].authSuccessBlock = ^(NSDictionary *infoDic) {
[ZHWeChatTool share].authSuccessBlock = ^(QGWechatLoginInfoModel *infoModel) {
if (successBlock) {
successBlock(infoDic);
successBlock(infoModel);
}
};
}
......
......@@ -7,6 +7,10 @@
//
#import <Foundation/Foundation.h>
#import "QGBaseModel.h"
@class QGWechatLoginInfoModel;
//#import "WXApi.h"
///支付回调
typedef void(^ZHWeChatPayBlock)(BOOL isSuccess, NSString * errorMsg);
......@@ -14,7 +18,7 @@ typedef void(^ZHWeChatPayBlock)(BOOL isSuccess, NSString * errorMsg);
typedef void(^ZHWeChatShareResultBlock)(BOOL isSuccess);
//登录回调
typedef void(^ZHWeChatAuthSuccessBlock)(NSDictionary * infoDic);
typedef void(^ZHWeChatAuthSuccessBlock)(QGWechatLoginInfoModel * infoModel);
//-----------------------------------------------------------------------/
......@@ -94,3 +98,37 @@ typedef void(^ZHWeChatAuthSuccessBlock)(NSDictionary * infoDic);
- (BOOL)handleOpenURL:(NSURL *) url;
@end
/// 微信登录信息模型
@interface QGWechatLoginInfoModel : QGBaseModel
/// 普通用户个人资料填写的城市
@property (nonatomic, strong) NSString * city;
/// 国家,如中国为 CN
@property (nonatomic, strong) NSString * country;
/// 普通用户个人资料填写的省份
@property (nonatomic, strong) NSString * province;
/// 用户头像,最后一个数值代表正方形头像大小(有 0、46、64、96、132 数值可选,0 代表 640*640 正方形头像),用户没有头像时该项为空
@property (nonatomic, strong) NSString * headimgurl;
/// 语言
@property (nonatomic, strong) NSString * language;
/// 昵称
@property (nonatomic, strong) NSString * nickname;
/// 普通用户的标识,对当前开发者帐号唯一
@property (nonatomic, strong) NSString * openid;
/// 普通用户性别,1 为男性,2 为女性
@property (nonatomic, strong) NSString * sex;
/// 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的 unionid 是唯一的。
@property (nonatomic, strong) NSString * unionid;
@end
......@@ -432,10 +432,9 @@ static ZHWeChatTool *chatTool = nil;
NSString *getUserInfoStr =[NSString stringWithFormat:@"https://api.weixin.qq.com/sns/userinfo?access_token=%@&openid=%@",accessTokenResponseDic[@"access_token"],accessTokenResponseDic[@"openid"]];
NSURL * getUserInfoUrl = [NSURL URLWithString:getUserInfoStr];
NSString * userInfoResponseStr = [NSString stringWithContentsOfURL:getUserInfoUrl encoding:NSUTF8StringEncoding error:nil];
NSData * userInfoResponseData = [userInfoResponseStr dataUsingEncoding:NSUTF8StringEncoding];
//获取数据成功 解析access_tokenDic
NSDictionary * userInfoResponseDic;
if (userInfoResponseData) {
QGWechatLoginInfoModel * infoModel = [QGWechatLoginInfoModel yy_modelWithJSON:userInfoResponseStr];
//检测能否拿到openid
if (infoModel.openid) {
/*
{
"openid": "OPENID",
......@@ -449,12 +448,12 @@ static ZHWeChatTool *chatTool = nil;
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
}
*/
userInfoResponseDic = [NSJSONSerialization JSONObjectWithData:userInfoResponseData options:NSJSONReadingMutableContainers error:nil];
//丢入主线程,回调出去
dispatch_async(dispatch_get_main_queue(), ^{
if (self.authSuccessBlock) {
self.authSuccessBlock(userInfoResponseDic);
self.authSuccessBlock(infoModel);
}
});
......@@ -466,4 +465,10 @@ static ZHWeChatTool *chatTool = nil;
}
@end
@implementation QGWechatLoginInfoModel
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment