CNLiveBindingManageRequest.m
10.6 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//
// CNLiveBindingManageRequest.m
// CNLiveNetAdd
//
// Created by CNLive-zxw on 2019/9/10.
// Copyright © 2019 cnlive. All rights reserved.
//
#import "CNLiveBindingManageRequest.h"
#import "CNLiveBindingManageModel.h"
#import "CNThreeLoginModel.h"
#import "CNLiveShareImageManager.h"
@implementation CNLiveBindingManageRequest
+ (void)requestModel:(CNLiveBindingManageModel *)model block:(CNLiveBindingResponseBlock)block{
if([model.isBinding isEqualToString:@"1"]){
//解除绑定操作
[CNLiveBindingManageRequest requestUnBindingModel:model block:^(BOOL isSuccess, CNBindingManageModel * _Nullable model, BOOL isBinding) {
block?block(isSuccess, model, isBinding):@"";
}];
}
else{
//绑定操作
[CNLiveBindingManageRequest requestBindingModel:model block:^(BOOL isSuccess, CNBindingManageModel * _Nullable model, BOOL isBinding) {
block?block(isSuccess, model, isBinding):@"";
}];
}
}
//绑定操作
+ (void)requestBindingModel:(CNLiveBindingManageModel *)model block:(CNBindingResponseBlock)block{
__weak typeof(self) weakSelf = self;
// 获取第三方id
[CNLiveShareImageManager send:model.type authRespBlock:^(CNLiveSendAuthResp type, CNLiveThirdPartyModel *userInfo, NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return;
if(error){
if(error.code == 10000){
//用户取消
}else{
[QMUITips showWithText:@"绑定失败" inView:AppKeyWindow hideAfterDelay:1.5];
}
return ;
}
if(userInfo.thirdPartyId&&![userInfo.thirdPartyId isEqualToString:@""]){
// 发起绑定请求
model.thirdPartyId = userInfo.thirdPartyId;
[strongSelf sendBindingModel:model block:block];
}else{
[QMUITips showWithText:@"绑定失败" inView:AppKeyWindow hideAfterDelay:1.5];
}
}];
}
+ (void)sendBindingModel:(CNBindingManageModel *)model block:(CNBindingResponseBlock)block{
NSDictionary *params = @{
@"uid":CNUserShareModel.uid?CNUserShareModel.uid:@"",
@"thirdPartyPlat":model.thirdPartyPlat?model.thirdPartyPlat:@"",
@"thirdPartyId":model.thirdPartyId?model.thirdPartyId:@"",
@"token":CNUserShareModel.token?CNUserShareModel.token:@"",
@"clientPlat":@"i"};
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:NO];
__weak typeof(self) weakSelf = self;
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNLoginBind3rdUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return;
if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
//绑定,并更新本地数据
CNBindingManageModel *bindingModel = [strongSelf updateBindingModel:model isBinding:@"1"];
block?block(YES, bindingModel, YES):@"";
}
else if([responseObject isKindOfClass:[NSDictionary class]]) {
[QMUITips showWithText:responseObject[@"errorMessage"] inView:AppKeyWindow hideAfterDelay:1.5];
block?block(NO, nil, NO):@"";
}
else{
[QMUITips showWithText:@"绑定失败" inView:AppKeyWindow hideAfterDelay:1.5];
block?block(NO, nil, NO):@"";
}
}];
}
//解除绑定操作
+ (void)requestUnBindingModel:(CNBindingManageModel *)model block:(CNBindingResponseBlock)block{
NSDictionary *params = @{
@"uid":CNUserShareModel.uid?CNUserShareModel.uid:@"",
@"thirdPartyPlat":model.thirdPartyPlat?model.thirdPartyPlat:@"",
@"thirdPartyId":model.thirdPartyId?model.thirdPartyId:@"",
@"token":CNUserShareModel.token?CNUserShareModel.token:@"",
@"clientPlat":@"i"};
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:NO];
__weak typeof(self) weakSelf = self;
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNLoginUnBind3rdUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return;
if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
//解除绑定,并更新本地数据
CNBindingManageModel *unbindingModel = [strongSelf updateBindingModel:model isBinding:@"0"];
block?block(YES, unbindingModel, NO):@"";
}
else if ([responseObject isKindOfClass:[NSDictionary class]]) {
[QMUITips showWithText:responseObject[@"errorMessage"] inView:AppKeyWindow hideAfterDelay:1.5];
block?block(NO, nil, NO):@"";
}
else{
[QMUITips showWithText:@"解除绑定失败" inView:AppKeyWindow hideAfterDelay:1.5];
block?block(NO, nil, NO):@"";
}
}];
}
//改变绑定数据
+ (CNBindingManageModel *)updateBindingModel:(CNBindingManageModel *)model isBinding:(NSString *)isBinding{
if([isBinding isEqualToString:@"0"]){
//解除绑定
model.isBinding = @"0";
//微博
if([model.thirdPartyPlat isEqualToString:@"1"]){
CNUserShareModel.sinaUid = @"";
}
//qq
else if([model.thirdPartyPlat isEqualToString:@"2"]){
CNUserShareModel.qqUid = @"";
}
//微信
else if([model.thirdPartyPlat isEqualToString:@"3"]){
CNUserShareModel.wxUid = @"";
}
//苹果
else if([model.thirdPartyPlat isEqualToString:@"5"]){
CNUserShareModel.appleUid = @"";
}
[QMUITips showWithText:@"解除绑定成功" inView:AppKeyWindow hideAfterDelay:1.5];
return model;
}
else if ([isBinding isEqualToString:@"1"]){
//添加绑定
model.isBinding = @"1";
//微博
if([model.thirdPartyPlat isEqualToString:@"1"]){
CNUserShareModel.sinaUid = model.thirdPartyId;
}
//qq
else if([model.thirdPartyPlat isEqualToString:@"2"]){
CNUserShareModel.qqUid = model.thirdPartyId;
}
//微信
else if([model.thirdPartyPlat isEqualToString:@"3"]){
CNUserShareModel.wxUid = model.thirdPartyId;
}
//苹果
else if([model.thirdPartyPlat isEqualToString:@"5"]){
CNUserShareModel.appleUid = model.thirdPartyId;
}
[QMUITips showWithText:@"绑定成功" inView:AppKeyWindow hideAfterDelay:1.5];
return model;
}
return nil;
}
//请求绑定数据
+ (void)requestModels:(CNBindingArrayBlock)block{
NSMutableArray *bindingData = [[NSMutableArray alloc] init];
NSMutableArray *unBindingData = [[NSMutableArray alloc] init];
CNBindingManageModel *tmodel = [[CNBindingManageModel alloc]init];
tmodel.title = @"手机号";
tmodel.image = @"login_telephone";
NSString *mobile = [CNUserShareModel.mobile stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
tmodel.desc = mobile;
tmodel.isBinding = @"1";
tmodel.thirdPartyPlat = @"10";
tmodel.thirdPartyId = CNUserShareModel.uid;
[bindingData addObject:tmodel];
CNBindingManageModel *wmodel = [[CNBindingManageModel alloc]init];
wmodel.title = @"微信";
wmodel.image = @"login_wechat";
wmodel.thirdPartyPlat = @"3";
if(CNUserShareModel.wxUid&&![CNUserShareModel.wxUid isEqualToString:@""]){
wmodel.desc = @"已绑定微信";
wmodel.thirdPartyId = CNUserShareModel.wxUid;
wmodel.isBinding = @"1";
}else{
wmodel.desc = @"未绑定微信";
wmodel.isBinding = @"0";
}
[unBindingData addObject:wmodel];
CNBindingManageModel *qmodel = [[CNBindingManageModel alloc]init];
qmodel.title = @"QQ";
qmodel.image = @"login_qq";
qmodel.thirdPartyPlat = @"2";
if(CNUserShareModel.qqUid&&![CNUserShareModel.qqUid isEqualToString:@""]){
qmodel.desc = @"已绑定QQ";
qmodel.thirdPartyId = CNUserShareModel.qqUid;
qmodel.isBinding = @"1";
}else{
qmodel.desc = @"未绑定QQ";
qmodel.isBinding = @"0";
}
[unBindingData addObject:qmodel];
CNBindingManageModel *smodel = [[CNBindingManageModel alloc]init];
smodel.title = @"微博";
smodel.image = @"login_weibo";
smodel.thirdPartyPlat = @"1";
if(CNUserShareModel.sinaUid&&![CNUserShareModel.sinaUid isEqualToString:@""]){
smodel.desc = @"已绑定微博";
smodel.thirdPartyId = CNUserShareModel.sinaUid;
smodel.isBinding = @"1";
}else{
smodel.desc = @"未绑定微博";
smodel.isBinding = @"0";
}
[unBindingData addObject:smodel];
CNBindingManageModel *amodel = [[CNBindingManageModel alloc]init];
amodel.title = @"苹果账号";
amodel.image = @"login_apple_icon";
amodel.thirdPartyPlat = @"5";
if(CNUserShareModel.appleUid&&![CNUserShareModel.appleUid isEqualToString:@""]){
amodel.desc = @"已绑定苹果账号";
amodel.thirdPartyId = CNUserShareModel.appleUid;
amodel.isBinding = @"1";
}else{
amodel.desc = @"未绑定苹果账号";
amodel.isBinding = @"0";
}
[unBindingData addObject:amodel];
block?block(bindingData,unBindingData):@"";
}
//三方登录
+ (void)thirdPartyLoginWithType:(CNLiveSendAuthResp)type model:(CNThreeLoginModel *)model block:(CNLoginResponseBlock)block{
NSDictionary *params = @{@"thirdPartyPlat":model.thirdPartyPlat?model.thirdPartyPlat:@"",
@"thirdPartyId":model.thirdPartyId?model.thirdPartyId:@"",
@"frmId":model.frmId?model.frmId:@"",
@"clientPlat":@"i"};
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:NO];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNLoginIn3rdForWJJUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
block?block(requestTask, responseObject, error):@"";
}];
}
@end