-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZYCheckAuth.m
74 lines (56 loc) · 1.78 KB
/
ZYCheckAuth.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ZYCheckAuth.m
// ABiteOfKunMing
//
// Created by zCloud on 14-8-4.
// Copyright (c) 2014年 Yun.Zou. All rights reserved.
//
#import "ZYCheckAuth.h"
#define APPKEY @"801515859"
#define APPSECRECT @"34ec44459431ebe4020974cb655f87b3"
#define REDIRECTURI @"http://www.baidu.com"
@interface ZYCheckAuth () <WeiboRequestDelegate,WeiboAuthDelegate>
@property (strong, nonatomic) WeiboApi *wbapi;
@end
@implementation ZYCheckAuth
- (WeiboApi *)wbapi
{
if (!_wbapi) {
_wbapi = [[WeiboApi alloc]initWithAppKey:APPKEY
andSecret:APPSECRECT
andRedirectUri:REDIRECTURI
andAuthModeFlag:TCWBModelDefault
andCachePolicy:TCWBCachePolicyCacheFirst];
}
return _wbapi;
}
#pragma mark - Public methods
-(void)checkAuthValid
{
[self.wbapi checkAuthValid:TCWBAuthCheckServer andDelegete:self];
}
-(void)logout
{
[self.wbapi cancelAuth];
}
#pragma mark - WeiboAuthDelegate
/**
* @brief 授权成功后的回调
* @param INPUT error 标准出错信息
* @return 无返回
*/
-(void)didCheckAuthValid:(BOOL)bResult suggest:(NSString *)strSuggestion
{
NSString *str = [[NSString alloc] initWithFormat:@"ret=%d, suggestion = %@", bResult, strSuggestion];
NSLog(@"%@",str);
//注意回到主线程,有些回调并不在主线程中,所以这里必须回到主线程
dispatch_async(dispatch_get_main_queue(), ^{
_isAccessTokenValid = bResult;
_accessToken = [self.wbapi getToken].accessToken;
_openId = [self.wbapi getToken].openid;
_appKey = [self.wbapi getToken].appKey;
_appSecrect = [self.wbapi getToken].appSecret;
[self.delegate isAuthValid];
});
}
@end