-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathSensitiveExample.java
More file actions
109 lines (89 loc) · 3.65 KB
/
SensitiveExample.java
File metadata and controls
109 lines (89 loc) · 3.65 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
package io.rong.example.sensitive;
import io.rong.CenterEnum;
import io.rong.RongCloud;
import io.rong.methods.sensitive.SensitiveWord;
import io.rong.models.response.BatchAddSensitiveWordResult;
import io.rong.models.response.ListWordfilterResult;
import io.rong.models.response.ResponseResult;
import io.rong.models.sensitiveword.AddSensitiveWordsModel;
import io.rong.models.sensitiveword.SensitiveWordModel;
import java.util.ArrayList;
import java.util.List;
public class SensitiveExample {
/**
* Replace with your App Key here
* */
private static final String appKey = "appKey";
/**
* Replace with your App Secret here
* */
private static final String appSecret = "appSecret";
public static void main(String[] args) throws Exception {
RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret, CenterEnum.BJ);
// Custom API URL
// RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api);
SensitiveWord sensitiveWord = rongCloud.sensitiveword;
/**
*
*
* Add or replace sensitive words
*
* */
SensitiveWordModel sentiveWord = new SensitiveWordModel()
.setType(0)
.setKeyword("Pornography, Gambling, Drugs")
.setReplace("***");
ResponseResult addesult = sensitiveWord.add(sentiveWord);
System.out.println("sentiveWord add: " + addesult.toString());
/**
*
*
* Add or replace sensitive words
*/
sentiveWord = new SensitiveWordModel()
.setType(1)
.setKeyword("ABC");
ResponseResult addersult = sensitiveWord.add(sentiveWord);
System.out.println("sentiveWord add replace : " + addersult.toString());
/**
*
*
* Method to query the list of sensitive words
*
* */
ListWordfilterResult result = sensitiveWord.getList(1);
System.out.println("getList: " + result.toString());
/**
*
*
* Method to remove a sensitive word (Removes a specific sensitive word from the list.)
*
* */
ResponseResult removeesult = sensitiveWord.remove("money");
System.out.println("SensitivewordDelete: " + removeesult.toString());
/**
*
*
* Method to batch remove sensitive words (Removes multiple sensitive words from the list in bulk.)
*
* */
String[] words = {"Pornography, Gambling, Drugs"};
ResponseResult batchDeleteResult = sensitiveWord.batchDelete(words);
System.out.println("SensitivewordbatchDelete: " + batchDeleteResult.toString());
/**
*
* Method to batch add sensitive words
*/
AddSensitiveWordsModel.SensitiveWord word1 = new AddSensitiveWordsModel.SensitiveWord().setWord("abc").setReplaceWord("***");
AddSensitiveWordsModel.SensitiveWord word2 = new AddSensitiveWordsModel.SensitiveWord().setWord("ab").setReplaceWord("**");
AddSensitiveWordsModel.SensitiveWord word3 = new AddSensitiveWordsModel.SensitiveWord().setWord("a");
List<AddSensitiveWordsModel.SensitiveWord> wordList = new ArrayList<>();
wordList.add(word1);
wordList.add(word2);
wordList.add(word3);
AddSensitiveWordsModel addSensitiveWordsModel = new AddSensitiveWordsModel()
.setWords(wordList);
BatchAddSensitiveWordResult batchAddSensitiveWordResult = sensitiveWord.batchAdd(addSensitiveWordsModel);
System.out.println("SensitiveWordBatchAdd: " + batchAddSensitiveWordResult.toString());
}
}