CNLiveCheckVerificationCode.m
7.78 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// CNLiveCheckVerificationCode.m
// CNLiveUserSystemDemo
//
// Created by 张旭 on 2017/5/26.
// Copyright © 2017年 zhulin. All rights reserved.
//
#import "CNLiveCheckVerificationCode.h"
#import "CNLiveUserSystemTools.h"
#import "CNLiveUserNetworkManager.h"
#import "NSDictionary+Safety.h"
//注册前校验手机验证码
static NSString *registerCheckVerificationCodeTestURL = @"http://test.open.cnlive.com/openapi/api2/user/checkVerifyCodeForUnRegistered";
static NSString *registerCheckVerificationCodeFormalURL = @"https://api.cnlive.com/open/api2/user/checkVerifyCodeForUnRegistered";
//快捷登录前前校验手机验证码
static NSString *shortcutLoginCheckVerificationCodeTestURL = @"http://test.open.cnlive.com/openapi/api2/user/checkVerifyCode";
static NSString *shortcutLoginCheckVerificationCodeFormalURL = @"https://api.cnlive.com/open/api2/user/checkVerifyCode";
@implementation CNLiveCheckVerificationCode
- (void)registerCheckVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(CheckVerificationCodeType)type mobile:(NSString *)mobile verificationCode:(NSString *)verificationCode success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure
{
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"mobile":[CNLiveUserSystemTools verify:mobile],
@"verificationCode":[CNLiveUserSystemTools verify:verificationCode],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier
};
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:[self getURL:type] parameter:parameter success:success failure:failure];
}
- (void)registerCheckVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(CheckVerificationCodeType)type mobile:(NSString *)mobile countryCode:(NSString *)countryCode verificationCode:(NSString *)verificationCode success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure
{
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"mobile":[CNLiveUserSystemTools verify:mobile],
@"countryCode":countryCode,
@"verificationCode":[CNLiveUserSystemTools verify:verificationCode],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier
};
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:[self getURL:type] parameter:parameter success:success failure:failure];
}
- (void)shortcutLoginCheckVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(CheckVerificationCodeType)type mobile:(NSString *)mobile verificationCode:(NSString *)verificationCode success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure
{
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"mobile":[CNLiveUserSystemTools verify:mobile],
@"verificationCode":[CNLiveUserSystemTools verify:verificationCode],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier
};
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:[self getURL:type] parameter:parameter success:success failure:failure];
}
- (void)shortcutLoginCheckVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(CheckVerificationCodeType)type mobile:(NSString *)mobile countryCode:(NSString *)countryCode verificationCode:(NSString *)verificationCode success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure
{
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"mobile":[CNLiveUserSystemTools verify:mobile],
@"countryCode":countryCode,
@"verificationCode":[CNLiveUserSystemTools verify:verificationCode],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier
};
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:[self getURL:type] parameter:parameter success:success failure:failure];
}
#pragma mark - request
- (void)requestWithURL:(NSString *)URL parameter:(NSDictionary *)param success:(void(^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure
{
[[CNLiveUserNetworkManager manager] requestPostURL:URL parameters:param success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) {
responseObject = [responseObject validatedDictionary];
if ([[responseObject allKeys] containsObject:@"errorCode"] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
if (success) {
success(responseObject);
}
} else {
if (failure) {
failure(responseObject);
}
[CNLiveUserSystemTools errorStat:responseObject[@"errorMessage"]];
}
} failure:^(NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *errorDic = @{@"errorCode": [NSString stringWithFormat:@"%ld", error.code], @"errorMessage": error.localizedDescription};
if (failure) {
failure(errorDic);
}
[CNLiveUserSystemTools errorStat:error.localizedDescription];
}];
}
- (NSString *)getURL:(CheckVerificationCodeType)type
{
NSString *url;
switch (type) {
case CheckVerificationCodeTypeShortcutLogin:
if ([CNLiveUserSystemTools isTestEnvironment]) {
url = shortcutLoginCheckVerificationCodeTestURL;
}else{
url = shortcutLoginCheckVerificationCodeFormalURL;
}
break;
case CheckVerificationCodeTypeRegister:
if ([CNLiveUserSystemTools isTestEnvironment]) {
url = registerCheckVerificationCodeTestURL;
} else {
url = registerCheckVerificationCodeFormalURL;
}
break;
default:
break;
}
return url;
}
@end