-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathOnlineStatus.java
More file actions
67 lines (61 loc) · 2.29 KB
/
Copy pathOnlineStatus.java
File metadata and controls
67 lines (61 loc) · 2.29 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
package io.rong.methods.user.onlinestatus;
import io.rong.RongCloud;
import io.rong.models.CheckMethod;
import io.rong.models.response.CheckOnlineResult;
import io.rong.models.user.UserModel;
import io.rong.util.CommonUtil;
import io.rong.util.GsonUtil;
import io.rong.util.HttpUtil;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
/**
*
* User Online Status
*
* @version
* */
public class OnlineStatus {
private static final String UTF8 = "UTF-8";
private static final String PATH = "user/online-status";
private String appKey;
private String appSecret;
private RongCloud rongCloud;
public RongCloud getRongCloud() {
return rongCloud;
}
public void setRongCloud(RongCloud rongCloud) {
this.rongCloud = rongCloud;
}
public OnlineStatus(String appKey, String appSecret,RongCloud rongCloud) {
this.appKey = appKey;
this.appSecret = appSecret;
this.rongCloud = rongCloud;
}
/**
* Check User Online Status
* Avoid frequent or looped calls to this API. Instead, choose an appropriate frequency and timing for calls, as this API has rate limits in place.
*
* url /user/checkOnline
*
* @param user: User ID (required)
*
* @return CheckOnlineResult
**/
public CheckOnlineResult check(UserModel user) throws Exception {
// Parameter validation
String message = CommonUtil.checkFiled(user, PATH, CheckMethod.CHECK);
if (null != message) {
return (CheckOnlineResult) GsonUtil.fromJson(message, CheckOnlineResult.class);
}
StringBuilder sb = new StringBuilder();
sb.append("&userId=").append(URLEncoder.encode(user.id.toString(), UTF8));
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1, body.length());
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret,
"/user/checkOnline.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
return (CheckOnlineResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.CHECK,HttpUtil.returnResult(conn, rongCloud.getConfig())), CheckOnlineResult.class);
}
}