add weixinapi

This commit is contained in:
lianxiang
2018-08-27 13:35:39 +08:00
parent a4242fa7b7
commit 6e090fd28d
21 changed files with 325 additions and 58 deletions
@@ -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
@@ -22,6 +22,7 @@
#import "LXCountTimer.h"
#import "GiGaHelper.h"
#import <MediaPlayer/MediaPlayer.h>
#import "GiGaMeViewController.h"
@interface GiGaMaskTaskViewController ()
{
@@ -56,7 +57,7 @@
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self startMaskTime];
}
- (void)viewDidLoad {
@@ -139,14 +140,15 @@
-(void)startMaskTime{
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
if (delegate.isMasking) {
return;
}
delegate.isMasking = YES;
[_musicPalyer play];
[self setBackGroundPlayingInfo];//锁屏音频信息
//总时间隔 s
NSTimeInterval timeInterVal = 58;
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
NSString *hour = timesArr[0];
@@ -161,8 +163,7 @@
}
#pragma mark 设置后台锁屏样式 无效??
#pragma mark 设置后台锁屏音频信息
-(void)setBackGroundPlayingInfo{
MPMediaItemArtwork *arwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"MaskTime.png"]];
@@ -181,6 +182,7 @@
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
@@ -216,15 +218,12 @@
#pragma mark 开始测试
-(void)testBtnAcion:(UIButton *)btn{
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
if (delegate.isMasking) {
return;
}
[self startMaskTime];
return ;
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
if (isUserLogin) {
//GIGA_ShowToast(@"userLogin!");
@@ -260,7 +259,6 @@
GiGaAdDetailViewController *detailVC=[[GiGaAdDetailViewController alloc] init];
[self.navigationController pushViewController:detailVC animated:YES];
}
#pragma mark 新手引导消失
@@ -298,11 +296,13 @@
userGuardVC.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
[self presentViewController:userGuardVC animated:NO completion:nil];
}
#pragma mark App引导页
-(void)showAPPappGaurdView{
GiGaAppGaurdVC *gaurdVC = [[GiGaAppGaurdVC alloc] init];
[self presentViewController:gaurdVC animated:YES completion:nil];
}
#pragma mark - setUpNav
-(void)setUpNav{
@@ -320,11 +320,11 @@
[rightBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}
#pragma mark 消息 action
#pragma mark 消息 action
-(void)leftBtnAction{
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
if (isUserLogin) {
@@ -342,6 +342,9 @@
#pragma mark 个人中心 action
-(void)rightBtnAction{
GiGaMeViewController *meVC= [[GiGaMeViewController alloc] init];
[self.navigationController pushViewController:meVC animated:YES];
}
#pragma mark -bottomView
@@ -44,7 +44,7 @@
-(void)setquestionArray{
NSArray *array = @[
@{@"questionid" : @"1", @"totalCount" : @"5", @"question" : @"如果昨天是明天的话就好了,这样今天就周五了。真实的今天可能是星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"星期三:理想今天是星期五,昨天是星期四,真实明天是理想的昨天是星期四,真实的今天是星期三。\n星期日:理想今天是星期五,明天是星期六,真实昨天是理想的明天是星期六,真实的今天是星期日。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:星期三", @"B:星期四", @"C:星期五"]},
@{@"questionid" : @"1", @"totalCount" : @"5", @"question" : @"如果昨天是明天的话就好了,这样今天就周五了。真实的今天可能是星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"星期三:理想今天是星期五,昨天是星期四,真实明天是理想的昨天是星期四,真实的今天是星期三。\n星期日:理想今天是星期五,明天是星期六,真实昨天是理想的明天是星期六,真实的今天是星期日。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:星期三星期三星期三星期三星期三星期三星期三", @"B:星期四", @"C:星期五星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三星期三"]},
@{@"questionid" : @"2", @"totalCount" : @"5", @"question" : @"这里是问题,这道题的答案是AC。这里是问题,这道题的答案是AC。这里是问题,这道题的答案是AC。", @"questiontype" : @"1", @"questiontype_text" : @"多选题", @"questionselectnumber" : @"5", @"questiondescribe" : @"这里是答案解析,这里可以很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的。", @"trueanswer" : @"AC", @"userAnswer" : @[], @"tkselect" : @[@"A:这个选项是正确的。这个选项是正确的。这个选项是正确的。", @"B:这个选项是错误的。这个选项是错误的。这个选项是错误的。", @"C:这个选项是正确的。这个选项是正确的。这个选项是正确的。", @"D:这个选项是错误的。这个选项是错误的。这个选项是错误的。", @"E:这个选项是错误的。这个选项是错误的。这个选项是错误的。"]},
@{@"questionid" : @"3", @"totalCount" : @"5", @"question" : @"以下哪个牌子不是化妆品?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"化妆品,化妆品化妆品化妆品化妆品化妆品化妆品化妆品。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:化妆品", @"B:化妆品", @"C:星期五"]},
@{@"questionid" : @"4", @"totalCount" : @"5", @"question" : @"如果昨天是明天的话就好了,这样今天就周五了。真实的今天可能是星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"真实昨天是理想的明天是星期六,真实的今天是星期日?", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:星三", @"B:星", @"C:期"]},
@@ -80,9 +80,8 @@
[self.view layoutIfNeeded];//必加
//刷新答案相关数据
[_questionView reloadViewWithFrame:CGRectMake(0, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
[_questionView reloadViewWithFrame:CGRectMake(30, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW - 30*2, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
}
#pragma mark 创建控件
@@ -25,7 +25,7 @@
{
if (!_view) {
UIView *view = [[UIView alloc] init];
//view.backgroundColor = [UIColor blueColor];
view.backgroundColor = [UIColor blueColor];
[self addSubview:view];
_view = view;
}
@@ -77,13 +77,15 @@
NSString *labelText = _answerArr[i];
labelText = [labelText stringByReplacingOccurrencesOfString:@"\r" withString:@""];
labelText = [labelText stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//内容高度
CGFloat labelH = [GiGaHelper sizeWithText:labelText font:font maxSize:CGSizeMake(KMainW - 50, MAXFLOAT)].height;
//CGFloat labelH = [GiGaHelper sizeWithText:labelText font:font maxSize:CGSizeMake(frame.size.width - btnH - 5, MAXFLOAT)].height;
CGFloat labelH = [GiGaHelper getSpaceLabelHeight:labelText withFont:font maxSize:CGSizeMake(frame.size.width - btnH - 5, MAXFLOAT)];
//选项标签
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(btnH + 5, labelY + 4, KMainW - 50, labelH)];
label.text = labelText;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(btnH + 5, labelY + 4,frame.size.width - btnH - 5, labelH)];
[GiGaHelper setLabelSpace:label withValue:labelText withFont:font] ;
label.font = font;
label.numberOfLines = 0;
label.textColor = GIGAUIColorFromRGBA(0x616161);
@@ -112,18 +114,17 @@
}
}
self.view.frame = CGRectMake(10, 0, KMainW - 20, labelY - padding);
self.view.frame = CGRectMake(0,0,frame.size.width, labelY - padding);
frame.size.height = labelY - padding;
self.frame = frame;
[self setNeedsUpdateConstraints];
[self mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.superview.mas_top).offset(frame.origin.y + 10);
make.left.mas_equalTo(self.superview.mas_left).offset(30);
make.height.mas_equalTo(frame.size.height);
make.width.mas_equalTo(frame.size.width - 30*2);
}];
// [self setNeedsUpdateConstraints];
// [self mas_updateConstraints:^(MASConstraintMaker *make) {
// make.top.mas_equalTo(self.superview.mas_top).offset(frame.origin.y + 10);
// make.left.mas_equalTo(self.superview.mas_left).offset(30);
// make.height.mas_equalTo(frame.size.height);
// make.width.mas_equalTo(frame.size.width - 30*2);
// }];
}
- (void)btnOnClick:(UIButton *)btn
@@ -7,6 +7,7 @@
//
#import "GiGaMeViewController.h"
#import "GiGaUserViewController.h"
@interface GiGaMeViewController ()
@@ -16,6 +17,7 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"我的";
// Do any additional setup after loading the view.
}
@@ -24,14 +26,12 @@
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
GiGaUserViewController *userVC= [[GiGaUserViewController alloc] init];
[self.navigationController pushViewController:userVC animated:YES];
// 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
@@ -15,8 +15,11 @@
@implementation GiGaUserViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"个人中心";
}
- (void)didReceiveMemoryWarning {
@@ -24,6 +27,7 @@
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation