-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathUserExample.java
More file actions
108 lines (90 loc) · 2.9 KB
/
UserExample.java
File metadata and controls
108 lines (90 loc) · 2.9 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
package io.rong.example.user;
import io.rong.CenterEnum;
import io.rong.RongCloud;
import io.rong.methods.user.User;
import io.rong.models.*;
import io.rong.models.response.*;
import io.rong.models.user.ExpireModel;
import io.rong.models.user.UserModel;
/**
* Demo class
*
* @author RongCloud
*/
public class UserExample {
/**
* Replace with your App Key
*/
private static final String appKey = "appKey";
/**
* Replace with your App Secret
*/
private static final String appSecret = "appSecret";
public static void main(String[] args) throws Exception {
RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret, CenterEnum.BJ);
User User = rongCloud.user;
/**
* Register a user and generate a unique identity Token for the user in RongCloud.
*/
UserModel user = new UserModel()
.setId("userxxd2")
.setName("username")
.setPortrait("http://www.rongcloud.cn/images/logo.png");
TokenResult result = User.register(user);
System.out.println("getToken: " + result.toString());
/**
*
*
* Method to refresh user information.
*/
Result refreshResult = User.update(user);
System.out.println("refresh: " + refreshResult.toString());
/**
*
*
* Method to query user information.
*/
UserResult userResult = User.get(user);
System.out.println("getUserInfo: " + userResult.toString());
/**
* Deactivate a user.
*/
ResponseResult abandon = User.deactivate(user);
System.out.println("user abandon: " + abandon.toString());
/**
* Query deactivated users.
*/
UserDeactivateResult abandonList = User.deactivateList(1, 20);
System.out.println("user abandon list: " + abandonList.toString());
/**
* Activate a user.
*/
ResponseResult active = User.activate(user);
System.out.println("user activate set: " + active.toString());
/**
* Reactivate user IDs.
*/
UserModel user1 = new UserModel().setIds(new String[]{"CHIQ1", "CHIQ2"});
ResponseResult reactivate = User.reactivate(user1);
System.out.println("user reactivate set: " + reactivate.toString());
/**
*
*
*
* Query the groups a user belongs to
*/
UserGroupQueryResult userGroupResult = User.getGroups(user);
System.out.println("getGroups: " + userGroupResult.toString());
ExpireModel expireModel = new ExpireModel()
.setUserId(new String[]{"CHIQ1", "CHIQ2"})
.setTime(1623123911000L);
/**
*
*
*
* Token expiration
*/
refreshResult = User.expire(expireModel);
System.out.println("expire: " + refreshResult.toString());
}
}