-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathBanAllMember.java
More file actions
178 lines (163 loc) · 7.49 KB
/
Copy pathBanAllMember.java
File metadata and controls
178 lines (163 loc) · 7.49 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
package io.rong.methods.chatroom.ban;
import com.alibaba.fastjson.JSONException;
import com.google.gson.JsonParseException;
import io.rong.RongCloud;
import io.rong.models.CheckMethod;
import io.rong.models.chatroom.ChatroomModel;
import io.rong.models.response.ChatroomBanListResult;
import io.rong.models.response.ResponseResult;
import io.rong.models.response.StatusResult;
import io.rong.util.CommonUtil;
import io.rong.util.GsonUtil;
import io.rong.util.HttpUtil;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
/**
* Chatroom Mute All Service
*/
public class BanAllMember {
private static final String UTF8 = "UTF-8";
private static final String PATH = "chatroom/ban";
private String appKey;
private String appSecret;
private RongCloud rongCloud;
public RongCloud getRongCloud() {
return rongCloud;
}
public void setRongCloud(RongCloud rongCloud) {
this.rongCloud = rongCloud;
}
public BanAllMember(String appKey, String appSecret) {
this.appKey = appKey;
this.appSecret = appSecret;
}
/**
* Add Chatroom Mute All Method
*
* @param chatroom : Id (required)
* @return ResponseResult
**/
public ResponseResult add(ChatroomModel chatroom) throws Exception {
String message = CommonUtil.checkFiled(chatroom, PATH, CheckMethod.ADD);
if (null != message) {
return (ResponseResult) GsonUtil.fromJson(message, ResponseResult.class);
}
StringBuilder sb = new StringBuilder();
sb.append("chatroomId=").append(URLEncoder.encode(chatroom.getId(), UTF8));
if(null != chatroom.getExtra() && chatroom.getExtra().length() != 0){
sb.append("&extra=").append(URLEncoder.encode(chatroom.getExtra(), UTF8));
}
if(null != chatroom.getNeedNotify()){
sb.append("&needNotify=").append(chatroom.getNeedNotify());
}
String body = sb.toString();
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret,
"/chatroom/ban/add.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
ResponseResult result = null;
String response = "";
try {
response = HttpUtil.returnResult(conn, rongCloud.getConfig());
result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.ADD, response), ResponseResult.class);
} catch (JSONException | JsonParseException | IllegalStateException e) {
rongCloud.getConfig().errorCounter.incrementAndGet();
result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage());
}
result.setReqBody(body);
return result;
}
/**
* Remove chatroom mute all method
*
* @param chatroom : Id. (Required)
* @return ResponseResult
**/
public ResponseResult remove(ChatroomModel chatroom) throws Exception {
String message = CommonUtil.checkFiled(chatroom, PATH, CheckMethod.ADD);
if (null != message) {
return (ResponseResult) GsonUtil.fromJson(message, ResponseResult.class);
}
StringBuilder sb = new StringBuilder();
sb.append("chatroomId=").append(URLEncoder.encode(chatroom.getId(), UTF8));
if(null != chatroom.getExtra() && chatroom.getExtra().length() != 0){
sb.append("&extra=").append(URLEncoder.encode(chatroom.getExtra(), UTF8));
}
if(null != chatroom.getNeedNotify()){
sb.append("&needNotify=").append(chatroom.getNeedNotify());
}
String body = sb.toString();
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret,
"/chatroom/ban/rollback.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
ResponseResult result = null;
String response = "";
try {
response = HttpUtil.returnResult(conn, rongCloud.getConfig());
result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.ADD, response), ResponseResult.class);
} catch (JSONException | JsonParseException | IllegalStateException e) {
rongCloud.getConfig().errorCounter.incrementAndGet();
result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage());
}
result.setReqBody(body);
return result;
}
/**
* Check the mute all chatrooms method
*
* @param chatroom : Id. (Required)
* @return ResponseResult
**/
public StatusResult check(ChatroomModel chatroom) throws Exception {
String message = CommonUtil.checkFiled(chatroom, PATH, CheckMethod.CHECK);
if (null != message) {
return (StatusResult) GsonUtil.fromJson(message, StatusResult.class);
}
String body = "chatroomId="+URLEncoder.encode(chatroom.getId(), UTF8);
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret,
"/chatroom/ban/check.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
StatusResult result;
String response = "";
try {
response = HttpUtil.returnResult(conn, rongCloud.getConfig());
result = (StatusResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.ADD, response), StatusResult.class);
} catch (JSONException | JsonParseException | IllegalStateException e) {
rongCloud.getConfig().errorCounter.incrementAndGet();
result = new StatusResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage());
}
result.setReqBody(body);
return result;
}
/**
* Query the list of users muted in chatrooms
*
* @return ListGagChatroomUserResult
**/
public ChatroomBanListResult getList(Integer size, Integer page) throws Exception {
StringBuilder sb = new StringBuilder();
if (size != null) {
sb.append("size=").append(URLEncoder.encode(size.toString(), UTF8));
}
if (page != null) {
sb.append("&page=").append(URLEncoder.encode(page.toString(), UTF8));
}
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1);
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret,
"/chatroom/ban/query.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
ChatroomBanListResult result;
String response = "";
try {
response = HttpUtil.returnResult(conn, rongCloud.getConfig());
result = (ChatroomBanListResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.GETLIST, response), ChatroomBanListResult.class);
} catch (JSONException | JsonParseException | IllegalStateException e) {
rongCloud.getConfig().errorCounter.incrementAndGet();
result = new ChatroomBanListResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage(), null);
}
result.setReqBody(body);
return result;
}
}