CNLiveLogin.m
5.98 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// CNLiveLogin.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/13.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "CNLiveLogin.h"
#import "CNLiveNetworkManager.h"
#import "CNLiveUserSystemTools.h"
#import "NSDictionary+Safety.h"
//快捷登录
static NSString *shortcutLoginURL = @"http://api.cnlive.com/open/api2/user/loginInQuickly";
//登录
static NSString *loginURL = @"http://api.cnlive.com/open/api2/user/loginIn";
//第三方登录
static NSString *thirdLoginURL = @"http://api.cnlive.com/open/api2/user/loginIn3rd";
@implementation CNLiveLogin
- (void)thirdPartyLoginWithAppId:(NSString *)appId appKey:(NSString *)appKey thirdPartyPlatType:(NSString *)plat thirdPartyId:(NSString *)thirdPartyId nickName:(NSString *)nickName gender:(NSString *)gender location:(NSString *)location faceUrl:(NSString *)faceUrl frmId:(NSString *)frmId success:(void (^)(id result))success failure:(void (^)(NSError *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"thirdPartyPlat":[CNLiveUserSystemTools verify:plat],
@"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId],
@"nickName":[CNLiveUserSystemTools verify:nickName],
@"gender":[CNLiveUserSystemTools verify:gender],
@"location":[CNLiveUserSystemTools verify:location],
@"faceUrl":[CNLiveUserSystemTools verify:faceUrl],
@"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]],
@"frmId":[CNLiveUserSystemTools verify:frmId],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier,
@"timestamp": timeString};
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params];
NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]];
NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString];
[parameter setObject:signString forKey:@"sign"];
[self requestWithURL:thirdLoginURL parameter:parameter success:success failure:failure];
}
/**
* 快捷登录
*/
- (void)shortcutLoginWithAppId:(NSString *)appId appKey:(NSString *)appKey userName:(NSString *)userName verificationCode:(NSString *)verificationCode frmId:(NSString *)frmId success:(void (^)(id result))success failure :(void (^)(NSError *error))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"userName":[CNLiveUserSystemTools verify:userName],
@"verificationCode":[CNLiveUserSystemTools verify:verificationCode],
@"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]],
@"frmId":[CNLiveUserSystemTools verify:frmId],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier,
@"timestamp": timeString};
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params];
NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]];
NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString];
[parameter setObject:signString forKey:@"sign"];
[self requestWithURL:shortcutLoginURL parameter:parameter success:success failure:failure];
}
/**
* 登录
*/
- (void)loginWithAppId:(NSString *)appId appKey:(NSString *)appKey userName:(NSString *)userName password:(NSString *)password frmId:(NSString *)frmId success:(void (^)(id result))success failure:(void (^)(NSError *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"userName":[CNLiveUserSystemTools verify:userName],
@"pwd":[CNLiveUserSystemTools verify:password],
@"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]],
@"frmId":[CNLiveUserSystemTools verify:frmId],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier,
@"timestamp": timeString};
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params];
NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]];
NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString];
[parameter setObject:signString forKey:@"sign"];
[self requestWithURL:loginURL parameter:parameter success:success failure:failure];
}
#pragma mark - request
- (void)requestWithURL:(NSString *)URL parameter:(NSDictionary *)param success:(void(^)(id result))success failure :(void (^)(NSError * error))failure
{
[[CNLiveNetworkManager manager] requestPostURL:URL parameters:param success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) {
responseObject = [responseObject validatedDictionary];
success(responseObject);
} failure:^(NSURLResponse * _Nullable response, NSError * _Nullable error) {
failure(error);
}];
}
@end