Skip to content

Commit 0256461

Browse files
authored
🆕 #2592 【企业微信】增加外部联系人聊天敏感词的的新增、修改、删除的接口方法
1 parent ccd452c commit 0256461

File tree

6 files changed

+171
-20
lines changed

6 files changed

+171
-20
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,5 +960,33 @@ WxMediaUploadResult uploadAttachment(String mediaType, String fileType, Integer
960960
WxMediaUploadResult uploadAttachment(String mediaType, Integer attachmentType, File file)
961961
throws WxErrorException;
962962

963+
/**
964+
* <pre>
965+
* 新建敏感词规则
966+
* 企业和第三方应用可以通过此接口新建敏感词规则
967+
* 请求方式:POST(HTTPS)
968+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_intercept_rule?access_token=ACCESS_TOKEN
969+
* <pre>
970+
*/
971+
WxCpInterceptRuleResultResp addInterceptRule(WxCpInterceptRuleResp ruleResp) throws WxErrorException;
972+
/**
973+
* <pre>
974+
* 修改敏感词规则
975+
* 企业和第三方应用可以通过此接口修改敏感词规则
976+
* 请求方式:POST(HTTPS)
977+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_intercept_rule?access_token=ACCESS_TOKEN
978+
* <pre>
979+
*/
980+
WxCpInterceptRuleResultResp updateInterceptRule(WxCpInterceptRuleResp ruleResp) throws WxErrorException;
981+
/**
982+
* <pre>
983+
* 删除敏感词规则
984+
* 企业和第三方应用可以通过此接口修改敏感词规则
985+
* 请求方式:POST(HTTPS)
986+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_intercept_rule?access_token=ACCESS_TOKEN
987+
* <pre>
988+
* @param rule_id 规则id
989+
*/
990+
WxCpBaseResp delInterceptRule(String rule_id) throws WxErrorException;
963991

964992
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.JsonObject;
5+
56
import java.io.File;
67
import java.io.IOException;
78
import java.io.InputStream;
89
import java.util.UUID;
10+
911
import lombok.NonNull;
1012
import lombok.RequiredArgsConstructor;
1113
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
@@ -111,7 +113,7 @@ public WxCpExternalContactInfo getExternalContact(String userId) throws WxErrorE
111113
@Override
112114
public WxCpExternalContactInfo getContactDetail(String userId, String cursor) throws WxErrorException {
113115
String params = userId;
114-
if(StringUtils.isNotEmpty(cursor)){
116+
if (StringUtils.isNotEmpty(cursor)) {
115117
params = params + "&cursor=" + cursor;
116118
}
117119
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_DETAIL + params);
@@ -130,11 +132,11 @@ public String convertToOpenid(@NotNull String externalUserId) throws WxErrorExce
130132
}
131133

132134
@Override
133-
public String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException {
135+
public String unionidToExternalUserid(@NotNull String unionid, String openid) throws WxErrorException {
134136
JsonObject json = new JsonObject();
135137
json.addProperty("unionid", unionid);
136-
if(StringUtils.isNotEmpty(openid)){
137-
json.addProperty("openid",openid);
138+
if (StringUtils.isNotEmpty(openid)) {
139+
json.addProperty("openid", openid);
138140
}
139141
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UNIONID_TO_EXTERNAL_USERID);
140142
String responseContent = this.mainService.post(url, json.toString());
@@ -157,8 +159,8 @@ public WxCpExternalUserIdList unionidToExternalUserid3rd(@NotNull String unionid
157159
JsonObject json = new JsonObject();
158160
json.addProperty("unionid", unionid);
159161
json.addProperty("openid", openid);
160-
if(StringUtils.isNotEmpty(corpid)){
161-
json.addProperty("corpid",corpid);
162+
if (StringUtils.isNotEmpty(corpid)) {
163+
json.addProperty("corpid", corpid);
162164
}
163165
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UNIONID_TO_EXTERNAL_USERID_3RD);
164166
String responseContent = this.mainService.post(url, json.toString());
@@ -188,7 +190,7 @@ public WxCpBaseResp finishExternalUserIdMigration(@NotNull String corpid) throws
188190
@Override
189191
public String opengidToChatid(@NotNull String opengid) throws WxErrorException {
190192
JsonObject json = new JsonObject();
191-
json.addProperty("opengid",opengid);
193+
json.addProperty("opengid", opengid);
192194
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(OPENID_TO_CHATID);
193195
String responseContent = this.mainService.post(url, json.toString());
194196
JsonObject tmpJson = GsonParser.parse(responseContent);
@@ -247,7 +249,7 @@ public List<String> listFollowers() throws WxErrorException {
247249
@Override
248250
public WxCpUserExternalUnassignList listUnassignedList(Integer pageIndex, String cursor, Integer pageSize) throws WxErrorException {
249251
JsonObject json = new JsonObject();
250-
if(pageIndex != null){
252+
if (pageIndex != null) {
251253
json.addProperty("page_id", pageIndex);
252254
}
253255
json.addProperty("cursor", StringUtils.isEmpty(cursor) ? "" : cursor);
@@ -518,20 +520,20 @@ public WxCpGetMomentTaskResult getMomentTaskResult(String jobId) throws WxErrorE
518520

519521
@Override
520522
public WxCpGetMomentList getMomentList(Long startTime, Long endTime, String creator, Integer filterType,
521-
String cursor, Integer limit) throws WxErrorException {
523+
String cursor, Integer limit) throws WxErrorException {
522524
JsonObject json = new JsonObject();
523525
json.addProperty("start_time", startTime);
524526
json.addProperty("end_time", endTime);
525527
if (!StringUtils.isEmpty(creator)) {
526528
json.addProperty("creator", creator);
527529
}
528-
if (filterType!=null) {
530+
if (filterType != null) {
529531
json.addProperty("filter_type", filterType);
530532
}
531533
if (!StringUtils.isEmpty(cursor)) {
532534
json.addProperty("cursor", cursor);
533535
}
534-
if (limit!=null) {
536+
if (limit != null) {
535537
json.addProperty("limit", limit);
536538
}
537539
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_LIST);
@@ -547,7 +549,7 @@ public WxCpGetMomentTask getMomentTask(String momentId, String cursor, Integer l
547549
if (!StringUtils.isEmpty(cursor)) {
548550
json.addProperty("cursor", cursor);
549551
}
550-
if (limit!=null) {
552+
if (limit != null) {
551553
json.addProperty("limit", limit);
552554
}
553555
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_TASK);
@@ -557,14 +559,14 @@ public WxCpGetMomentTask getMomentTask(String momentId, String cursor, Integer l
557559

558560
@Override
559561
public WxCpGetMomentCustomerList getMomentCustomerList(String momentId, String userId,
560-
String cursor, Integer limit) throws WxErrorException {
562+
String cursor, Integer limit) throws WxErrorException {
561563
JsonObject json = new JsonObject();
562564
json.addProperty("moment_id", momentId);
563565
json.addProperty("userid", userId);
564566
if (!StringUtils.isEmpty(cursor)) {
565567
json.addProperty("cursor", cursor);
566568
}
567-
if (limit!=null) {
569+
if (limit != null) {
568570
json.addProperty("limit", limit);
569571
}
570572
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_CUSTOMER_LIST);
@@ -574,14 +576,14 @@ public WxCpGetMomentCustomerList getMomentCustomerList(String momentId, String u
574576

575577
@Override
576578
public WxCpGetMomentSendResult getMomentSendResult(String momentId, String userId,
577-
String cursor, Integer limit) throws WxErrorException {
579+
String cursor, Integer limit) throws WxErrorException {
578580
JsonObject json = new JsonObject();
579581
json.addProperty("moment_id", momentId);
580582
json.addProperty("userid", userId);
581583
if (!StringUtils.isEmpty(cursor)) {
582584
json.addProperty("cursor", cursor);
583585
}
584-
if (limit!=null) {
586+
if (limit != null) {
585587
json.addProperty("limit", limit);
586588
}
587589
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_SEND_RESULT);
@@ -790,8 +792,8 @@ public WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String a
790792
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册列表
791793
* </pre>
792794
*
793-
* @param limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
794-
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
795+
* @param limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
796+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
795797
* @return wx cp base resp
796798
* @throws WxErrorException the wx error exception
797799
*/
@@ -811,7 +813,7 @@ public WxCpProductAlbumListResult getProductAlbumList(Integer limit, String curs
811813
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
812814
* </pre>
813815
*
814-
* @param productId 商品id
816+
* @param productId 商品id
815817
* @return wx cp base resp
816818
* @throws WxErrorException the wx error exception
817819
*/
@@ -826,7 +828,7 @@ public WxCpProductAlbumResult getProductAlbum(String productId) throws WxErrorEx
826828

827829
@Override
828830
public WxMediaUploadResult uploadAttachment(String mediaType, String fileType, Integer attachmentType,
829-
InputStream inputStream) throws WxErrorException, IOException {
831+
InputStream inputStream) throws WxErrorException, IOException {
830832
return uploadAttachment(mediaType, attachmentType, FileUtils.createTmpFile(inputStream,
831833
UUID.randomUUID().toString(), fileType));
832834
}
@@ -839,4 +841,26 @@ public WxMediaUploadResult uploadAttachment(String mediaType, Integer attachment
839841
return this.mainService.execute(MediaUploadRequestExecutor.create(
840842
this.mainService.getRequestHttp()), url, file);
841843
}
844+
845+
@Override
846+
public WxCpInterceptRuleResultResp addInterceptRule(WxCpInterceptRuleResp ruleResp) throws WxErrorException {
847+
return WxCpInterceptRuleResultResp
848+
.fromJson(this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(ADD_INTERCEPT_RULE), ruleResp.toJson()));
849+
}
850+
851+
@Override
852+
public WxCpInterceptRuleResultResp updateInterceptRule(WxCpInterceptRuleResp ruleResp) throws WxErrorException {
853+
return WxCpInterceptRuleResultResp
854+
.fromJson(this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_INTERCEPT_RULE), ruleResp.toJson()));
855+
}
856+
857+
@Override
858+
public WxCpBaseResp delInterceptRule(String rule_id) throws WxErrorException {
859+
JsonObject jsonObject = new JsonObject();
860+
jsonObject.addProperty("rule_id",rule_id);
861+
return WxCpBaseResp
862+
.fromJson(this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(DEL_INTERCEPT_RULE), jsonObject));
863+
}
864+
865+
842866
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.util.Date;
11+
import java.util.List;
12+
13+
/**
14+
* 新增敏感词规则请求参数封装实体类
15+
*
16+
* @author didi
17+
* @date 2022-04-17
18+
*/
19+
@Data
20+
@Builder
21+
@NoArgsConstructor
22+
@AllArgsConstructor
23+
public class WxCpInterceptRuleResp {
24+
25+
@SerializedName("rule_name")
26+
private String ruleName;
27+
@SerializedName("rule_id")
28+
private String ruleId;
29+
@SerializedName("word_list")
30+
private List<String> wordList;
31+
@SerializedName("semantics_list")
32+
private List<Integer> semanticsList;
33+
@SerializedName("intercept_type")
34+
private int interceptType;
35+
@SerializedName("applicable_range")
36+
private ApplicableRange applicableRange;
37+
38+
@Data
39+
public static class ApplicableRange {
40+
@SerializedName("user_list")
41+
private List<String> userList;
42+
@SerializedName("department_list")
43+
private List<Integer> departmentList;
44+
public static ApplicableRange fromJson(String json) {
45+
return WxCpGsonBuilder.create().fromJson(json, ApplicableRange.class);
46+
}
47+
48+
public String toJson() {
49+
return WxCpGsonBuilder.create().toJson(this);
50+
}
51+
}
52+
53+
public static WxCpInterceptRuleResp fromJson(String json) {
54+
return WxCpGsonBuilder.create().fromJson(json, WxCpInterceptRuleResp.class);
55+
}
56+
57+
public String toJson() {
58+
return WxCpGsonBuilder.create().toJson(this);
59+
}
60+
61+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
11+
/**
12+
* 新建敏感词规则负返回结果
13+
* @author didi
14+
*/
15+
@Data
16+
@EqualsAndHashCode(callSuper = true)
17+
public class WxCpInterceptRuleResultResp extends WxCpBaseResp implements Serializable {
18+
19+
@SerializedName("rule_id")
20+
private String ruleId;
21+
22+
public static WxCpInterceptRuleResultResp fromJson(String json) {
23+
return WxCpGsonBuilder.create().fromJson(json, WxCpInterceptRuleResultResp.class);
24+
}
25+
26+
public String toJson() {
27+
return WxCpGsonBuilder.create().toJson(this);
28+
}
29+
30+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/applydata/ContentValue.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class ContentValue implements Serializable {
4242

4343
private Vacation vacation;
4444

45+
@SerializedName("date_range")
46+
private Attendance.DataRange dateRange;
47+
4548
@Data
4649
public static class Date implements Serializable {
4750
private static final long serialVersionUID = -6181554080062231138L;

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ interface ExternalContact {
281281

282282
String UPLOAD_ATTACHMENT = "/cgi-bin/media/upload_attachment";
283283

284+
285+
String ADD_INTERCEPT_RULE = "/cgi-bin/externalcontact/add_intercept_rule";
286+
String UPDATE_INTERCEPT_RULE = "/cgi-bin/externalcontact/update_intercept_rule";
287+
String DEL_INTERCEPT_RULE = "/cgi-bin/externalcontact/del_intercept_rule";
288+
284289
}
285290

286291
interface Kf {

0 commit comments

Comments
 (0)