add weixinapi
This commit is contained in:
@@ -11,6 +11,10 @@
|
||||
#import "PassWordResetVC.h"
|
||||
#import "GiGaRegistViewController.h"
|
||||
#import "GiGaUserDefault.h"
|
||||
#import "WXApi.h"
|
||||
#import "GiGaNetManager.h"
|
||||
#import "WeiIXinApiManager.h"
|
||||
|
||||
@interface GiGaUserLoginVC ()
|
||||
@property (weak, nonatomic) IBOutlet UIImageView *userImagView;
|
||||
@property (weak, nonatomic) IBOutlet UITextField *acountTextField;
|
||||
@@ -33,9 +37,19 @@
|
||||
[self textFieldUI];
|
||||
[self.registBtn addTarget:self action:@selector(registBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.loginBtn addTarget:self action:@selector(loginBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.weiXinLoginBtn addTarget:self
|
||||
action:@selector(weiXinLoginAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
NC_ADD_TARGET_NAME_OBJECT(self, @selector(WeiXinLongIn:), kWeiXinAuthrization_Success, nil)
|
||||
|
||||
if (![WXApi isWXAppInstalled]) {
|
||||
self.weiXinLoginBtn.hidden = YES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-(void)dealloc{
|
||||
|
||||
NC_REMOVE_NAME(self, kWeiXinAuthrization_Success,nil);
|
||||
}
|
||||
|
||||
-(void)setUpX{
|
||||
@@ -49,8 +63,7 @@
|
||||
}
|
||||
|
||||
-(void)textFieldUI{
|
||||
|
||||
|
||||
|
||||
//self.acountTextField.attributedPlaceholder = @"";
|
||||
UIView *acountView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
|
||||
acountView.backgroundColor = [UIColor redColor];
|
||||
@@ -60,7 +73,8 @@
|
||||
self.acountTextField.leftView = acountView;
|
||||
self.acountTextField.leftViewMode = UITextFieldViewModeAlways;
|
||||
|
||||
[self.passwordTextField setValue:[UIColor colorWithRed:153/255.0f green:153/255.0f blue:153/255.0f alpha:1] forKey:@"_placeholderLabel.textColor"];
|
||||
// NSAttributedString *passholderText = [[NSAttributedString alloc] initWithString:@"密码" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor redColor]}];
|
||||
// self.passwordTextField.attributedPlaceholder = passholderText;
|
||||
UIView *passView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
|
||||
passView.backgroundColor = [UIColor redColor];
|
||||
UIImageView *passViewIcon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 16, 18)];
|
||||
@@ -68,7 +82,6 @@
|
||||
[passView addSubview:passViewIcon];
|
||||
self.passwordTextField.leftView = passView;
|
||||
self.passwordTextField.leftViewMode = UITextFieldViewModeAlways;
|
||||
|
||||
self.loginBtn.layer.masksToBounds = YES;
|
||||
self.loginBtn.layer.cornerRadius = self.loginBtn.frame.size.height / 2;
|
||||
|
||||
@@ -116,4 +129,58 @@
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - 微信登录
|
||||
// 授权
|
||||
-(void)weiXinLoginAction{
|
||||
|
||||
if ([WXApi isWXAppInstalled]) {
|
||||
SendAuthReq * req = [[SendAuthReq alloc] init] ;
|
||||
req.scope = @"snsapi_userinfo";
|
||||
req.state = @"wx_oauth2_authorization_state";
|
||||
[WXApi sendReq:req];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//授权成功获取access_token
|
||||
-(void)WeiXinLongIn:(NSNotification *)notification{
|
||||
|
||||
NSDictionary *param = @{
|
||||
@"appid":WXin_APPID,
|
||||
@"secret":WXin_APPSecret,
|
||||
@"code":notification.object[@"code"],
|
||||
@"grant_type":@"authorization_code"
|
||||
};
|
||||
[WeiIXinApiManager weixinAccessTokeRequstUrl:@"https://api.weixin.qq.com/sns/oauth2/access_token" parameters:param success:^(id response) {
|
||||
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:nil];
|
||||
GILog(@"access_token back -->%@",dict);
|
||||
[GiGaUserDefault saveWeiXinaccesstokenInfoWithDic:dict];
|
||||
[self requstWeiXinUserinfo];
|
||||
|
||||
} failure:^(NSError *err) {
|
||||
GILog(@"access_token err-->%@",err.localizedDescription);
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
//获取微信用户信息
|
||||
-(void)requstWeiXinUserinfo{
|
||||
|
||||
NSDictionary *tokenDic = [GiGaUserDefault getWeiXinAccessToenDic];
|
||||
NSDictionary *param = @{
|
||||
@"openid":tokenDic[@"openid"],
|
||||
@"access_token":tokenDic[@"access_token"],
|
||||
};
|
||||
|
||||
[WeiIXinApiManager getWeiXinUserInfoUrl:@"https://api.weixin.qq.com/sns/userinfo" parameters:param success:^(id response) {
|
||||
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:nil];
|
||||
GILog(@"weixinUser info back -->%@",dict);
|
||||
|
||||
} failure:^(NSError *err) {
|
||||
|
||||
GILog(@"weixin_userinfoApi err-->%@",err.localizedDescription);
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user