CNLiveUserInfo.m
11.4 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//
// CNLiveUserInfo.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/13.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "CNLiveUserInfo.h"
#import "CNLiveNetworkManager.h"
#import "CNLiveUserSystemTools.h"
#import "NSDictionary+Safety.h"
//更新手机号
static NSString *updateMobileURL = @"https://api.cnlive.com/open/api2/user/updateMobileById";
//查询用户信息
static NSString *queryUserInfoURL = @"https://api.cnlive.com/open/api2/user/readUserById";
//修改用户单项信息
static NSString *updateUserByIdURL = @"https://api.cnlive.com/open/api2/user/updateUserById";
//更新用户附加信息
static NSString *updateOtherInfoURL = @"https://api.cnlive.com/open/api2/user/updateUserExtInfo";
//修改密码
static NSString *updatePwdURL = @"https://api.cnlive.com/open/api2/user/updatePwdByMobile";
//绑定第三方账号
static NSString *BindingThirdURL = @"https://api.cnlive.com/open/api2/user/bind3rd";
@implementation CNLiveUserInfo
/**
* 更新手机号
*/
- (void)updateMobileWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid mobile:(NSString *)mobile verificationCode:(NSString *)verificationCode token:(NSString *)token success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"uid":[CNLiveUserSystemTools verify:uid],
@"mobile":[CNLiveUserSystemTools verify:mobile],
@"verificationCode":[CNLiveUserSystemTools verify:verificationCode],
@"clientPlat":@"i",
@"token":[CNLiveUserSystemTools verify:token],
@"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:updateMobileURL parameter:parameter success:success failure:failure];
}
/**
* 绑定第三方账号
*/
- (void)bindingThirdPartyWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid thirdPartyPlatType:(NSString *)plat thirdPartyId:(NSString *)thirdPartyId token:(NSString *)token success:(void (^)(id))success failure:(void (^)(NSDictionary *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"uid":[CNLiveUserSystemTools verify:uid],
@"thirdPartyPlat":[CNLiveUserSystemTools verify:plat],
@"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId],
@"token":[CNLiveUserSystemTools verify:token],
@"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:BindingThirdURL parameter:parameter success:success failure:failure];
}
/**
* 查询用户信息
*/
- (void)queryUserInfoWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid srcUid:(NSString *)srcUid token:(NSString *)token success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"uid":[CNLiveUserSystemTools verify:uid],
@"srcUid":[CNLiveUserSystemTools verify:srcUid],
@"clientPlat":@"i",
@"token":[CNLiveUserSystemTools verify:token],
@"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:queryUserInfoURL parameter:parameter success:success failure:failure];
}
/**
* 修改用户单项信息
*/
- (void)modifyUserInfoWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(UserInfoType)type uid:(NSString *)uid modifyInfo:(NSString *)info token:(NSString *)token success:(void (^)(id result))success failure :(void (^)(NSDictionary *error))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"uid":[CNLiveUserSystemTools verify:uid],
@"type":[self updateType:type],
@"value":[CNLiveUserSystemTools verify:info],
@"clientPlat":@"i",
@"token":[CNLiveUserSystemTools verify:token],
@"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:updateUserByIdURL parameter:parameter success:success failure:failure];
}
/**
* 更新用户附加信息
*/
- (void)updateOtherInfoWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid extInfo:(NSString *)extInfo token:(NSString *)token success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"token":[CNLiveUserSystemTools verify:token],
@"uid":[CNLiveUserSystemTools verify:uid],
@"extInfo":[CNLiveUserSystemTools verify:extInfo],
@"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:updateOtherInfoURL parameter:parameter success:success failure:failure];
}
/**
* 修改密码
*/
- (void)changePasswordWithAppId:(NSString *)appId appKey:(NSString *)appKey mobile:(NSString *)mobile verificationCode:(NSString *)verificationCode newPassword:(NSString *)newPassword success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"mobile":[CNLiveUserSystemTools verify:mobile],
@"verificationCode":[CNLiveUserSystemTools verify:verificationCode],
@"newPwd":[CNLiveUserSystemTools verify:newPassword],
@"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:updatePwdURL 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
{
[[CNLiveNetworkManager 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];
}];
}
#pragma mark - type
- (NSString *)updateType:(UserInfoType)updateType
{
NSString *type;
switch (updateType) {
case UserInfoTypeNickName:
type = @"nickName";
break;
case UserInfoTypeGender:
type = @"gender";
break;
case UserInfoTypeEmail:
type = @"email";
break;
case UserInfoTypeLocation:
type = @"location";
break;
default:
break;
}
return type;
}
@end