forked from sonofsky2010/TQT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TQTLoginRequest.m
95 lines (86 loc) · 2.96 KB
/
TQTLoginRequest.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// TQTLoginRequest.m
// TQT
//
// Created by lishunnian on 11-7-6.
// Copyright 2011年 __MyCompanyName__. All rights reserved.
//
#import "TQTLoginRequest.h"
#import "QOauthKey.h"
#import "TQTApiUrl.h"
#import "QOauth.h"
#import "QWeiboRequest.h"
#import "NSURL+QAdditions.h"
#import "SBJsonParser.h"
#import "TQTWeiBo.h"
#import "TQTAppDelegate.h"
@implementation TQTLoginRequest
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
+ (NSURL *)authorizeRequestUrl
{
TQTAppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
if (appDelegate.oauthKey) {
appDelegate.oauthKey = [[[QOauthKey alloc] init] autorelease];
}
QOauthKey *oauthKey = appDelegate.oauthKey;
oauthKey.consumerKey = kAppKey;
oauthKey.consumerSecret = kAppSecret;
oauthKey.callbackUrl = @"TQT://www.qq.com/";
QWeiboRequest *request = [[[QWeiboRequest alloc] init] autorelease];
NSString *responString = [request syncRequestWithUrl:kRequestTokenUrl httpMethod:@"GET" oauthKey:oauthKey parameters:nil files:nil];
NSDictionary *responDict = [NSURL parseURLQueryString:responString];
oauthKey.tokenKey = [responDict objectForKey:@"oauth_token"];
oauthKey.tokenSecret = [responDict objectForKey:@"oauth_token_secret"];
NSLog(@"tokenKey:%@", oauthKey.tokenKey);
NSLog(@"tokenSecret:%@", oauthKey.tokenSecret);
NSURL *authorizeRequestUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kAuthorizeUrl, oauthKey.tokenKey]];
return authorizeRequestUrl;
}
+ (BOOL)setAccessOauthkeyWithVerify:(NSString *)aVerify
{
TQTAppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
QOauthKey *oauthKey = appDelegate.oauthKey;
oauthKey.verify = aVerify;
NSLog(@"%@", oauthKey.verify);
QWeiboRequest *request = [[QWeiboRequest alloc] init];
QOauthKey *key = [[QOauthKey alloc] init];
key.consumerKey = oauthKey.consumerKey;
key.consumerSecret = oauthKey.consumerSecret;
key.tokenKey = oauthKey.tokenKey;
key.tokenSecret = oauthKey.tokenSecret;
key.verify = oauthKey.verify;
NSString *response = [request syncRequestWithUrl:@"https://open.t.qq.com/cgi-bin/access_token"
httpMethod:@"GET"
oauthKey:key
parameters:nil
files:nil];
[key release];
[request release];
NSDictionary *dict = [NSURL parseURLQueryString:response];
NSLog(@"%@", dict);
if (![dict objectForKey:@"oauth_token"] || ![dict objectForKey:@"oauth_token_secret"]) {
return NO;
}
oauthKey.tokenKey = [dict objectForKey:@"oauth_token"];
oauthKey.tokenSecret = [dict objectForKey:@"oauth_token_secret"];
return YES;
}
- (void)storeOauthKey:(QOauthKey *)aKey
{
}
- (QOauthKey *)lastStoreKey
{
return nil;
}
@end