Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆕【企业微信】增加获取敏感词规则列表和获取敏感词规则详情接口API #3243

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import me.chanjar.weixin.cp.bean.external.contact.*;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRule;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleAddRequest;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleInfo;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleList;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -1134,6 +1136,31 @@ WxMediaUploadResult uploadAttachment(String mediaType, Integer attachmentType, F
*/
void delInterceptRule(String ruleId) throws WxErrorException;

/**
* 获取敏感词规则列表
*
* 企业和第三方应用可以通过此接口获取所有设置的敏感词规则列表。
* 请求方式:GET(HTTPS)
* 文档地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_intercept_rule_list">获取敏感词规则列表</a>
*
* @return WxCpInterceptRuleList 敏感词规则列表
* @throws WxErrorException 微信API异常
*/
WxCpInterceptRuleList getInterceptRuleList() throws WxErrorException;

/**
* 获取敏感词详情
*
* 企业和第三方应用可以通过此接口获取单个敏感词规则的详细信息。
* 请求方式:GET(HTTPS)
* 文档地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_intercept_rule">获取敏感词详情</a>
*
* @param ruleId 敏感词规则ID
* @return WxCpInterceptRuleInfo 敏感词规则详情
* @throws WxErrorException 微信API异常
*/
WxCpInterceptRuleInfo getInterceptRuleDetail(String ruleId) throws WxErrorException;

/**
* <pre>
* 创建商品图册
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import me.chanjar.weixin.cp.bean.external.contact.*;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRule;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleAddRequest;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleInfo;
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleList;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -740,6 +742,19 @@ public void delInterceptRule(String ruleId) throws WxErrorException {
GsonHelper.buildJsonObject("rule_id", ruleId));
}

@Override
public WxCpInterceptRuleList getInterceptRuleList() throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_INTERCEPT_RULE_LIST);
return WxCpInterceptRuleList.fromJson(this.mainService.get(url,null));
}

@Override
public WxCpInterceptRuleInfo getInterceptRuleDetail(String ruleId) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_INTERCEPT_RULE);
String json = this.mainService.post(url, GsonHelper.buildJsonObject("rule_id", ruleId));
return WxCpInterceptRuleInfo.fromJson(json);
}

@Override
public String addProductAlbum(WxCpProductAlbumInfo wxCpProductAlbumInfo) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_PRODUCT_ALBUM);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.chanjar.weixin.cp.bean.external.interceptrule;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.external.acquisition.WxCpCustomerAcquisitionInfo;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* @Date: 2024-03-07 17:02
* @Author: shenliuming
* @return:
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxCpInterceptRuleInfo extends WxCpBaseResp implements Serializable {

private static final long serialVersionUID = -425957862453041229L;

@SerializedName("rule")
private Rule rule;

@Data
@EqualsAndHashCode(callSuper = false)
public static class Rule implements Serializable {
@SerializedName("rule_id")
private String ruleId;

@SerializedName("rule_name")
private String ruleName;

@SerializedName("word_list")
private List<String> wordList;

@SerializedName("semantics_list")
private List<Integer> semanticsList;

@SerializedName("intercept_type")
private Integer interceptType;

@SerializedName("applicable_range")
private ApplicableRange applicableRange;

@SerializedName("create_time")
private long createTime;

}


public static WxCpInterceptRuleInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpInterceptRuleInfo.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package me.chanjar.weixin.cp.bean.external.interceptrule;

import com.google.gson.annotations.SerializedName;
import lombok.*;
import me.chanjar.weixin.common.bean.ToJson;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.external.acquisition.WxCpCustomerAcquisitionInfo;
import me.chanjar.weixin.cp.bean.external.acquisition.WxCpCustomerAcquisitionList;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* @Date: 2024-03-07 15:54
* @Author: shenliuming
* @return:
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxCpInterceptRuleList extends WxCpBaseResp implements Serializable {

private static final long serialVersionUID = -830298362453041229L;
/**
* link_id列表
*/
@SerializedName("rule_list")
private List<Rule> ruleList;

public static WxCpInterceptRuleList fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpInterceptRuleList.class);
}

@Data
@EqualsAndHashCode(callSuper = false)
public static class Rule implements Serializable {
private static final long serialVersionUID = 4750537220968228300L;

/**
* 规则id
*/
@SerializedName("rule_id")
private String ruleId;

/**
* 规则名称,长度上限20个字符
*/
@SerializedName("rule_name")
private String ruleName;

/**
* 创建时间
*/
@SerializedName("create_time")
private Long createTime;

public static WxCpInterceptRuleList.Rule fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpInterceptRuleList.Rule.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,14 @@ interface ExternalContact {
* The constant DEL_INTERCEPT_RULE.
*/
String DEL_INTERCEPT_RULE = "/cgi-bin/externalcontact/del_intercept_rule";
/**
* 获取敏感词规则列表
*/
String GET_INTERCEPT_RULE_LIST = "/cgi-bin/externalcontact/get_intercept_rule_list";
/**
* 获取敏感词规则详情
*/
String GET_INTERCEPT_RULE = "/cgi-bin/externalcontact/get_intercept_rule";
/**
* 获取当前仍然有效的获客链接
*/
Expand Down