修复评审意见:修复 agentId 分组 null 冲突 bug,修正 Javadoc HTML 结构,完善 README 配置限制说明和示例代码
Agent-Logs-Url: https://github.com/binarywang/WxJava/sessions/dcb81708-f62f-4f63-837b-0e62c1da2883 Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8ffe58517b
commit
aaa3e7e9fc
@@ -22,6 +22,13 @@
|
||||
|
||||
如需同时使用多种权限范围,可在 `wx.cp.corps` 下配置多个条目,每个条目使用对应权限的 Secret,通过不同的 `tenantId` 区分后使用。
|
||||
|
||||
> **配置限制说明**:
|
||||
> - 当前 starter 实现会校验:同一 `corp-id` 下,`agent-id` **必须唯一**
|
||||
> - 同一 `corp-id` 下,**只能有一个条目不填 `agent-id`**
|
||||
> - 否则会因为 token/ticket 缓存 key 冲突而在启动时直接抛异常
|
||||
>
|
||||
> 因此,像"通讯录同步 Secret""客户联系 Secret"这类通常不填写 `agent-id` 的配置,**不能**在同一个 `corp-id` 下同时配置多个 `agent-id` 均为空的条目;如确有多个条目,请确保其中最多只有一个未填写 `agent-id`。
|
||||
|
||||
## 快速开始
|
||||
|
||||
1. 引入依赖
|
||||
@@ -74,6 +81,7 @@ import com.binarywang.spring.starter.wxjava.cp.service.WxCpMultiServices;
|
||||
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.api.WxCpUserService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -93,7 +101,11 @@ public class DemoService {
|
||||
// 通讯录同步 Secret 具有部门/成员增删改查等权限
|
||||
WxCpService contactService = wxCpMultiServices.getWxCpService("contact");
|
||||
WxCpDepartmentService departmentService = contactService.getDepartmentService();
|
||||
departmentService.update(department);
|
||||
// 更新部门示例(WxCpDepart 包含 id、name、parentId 等字段)
|
||||
WxCpDepart depart = new WxCpDepart();
|
||||
depart.setId(100L);
|
||||
depart.setName("新部门名称");
|
||||
departmentService.update(depart);
|
||||
// todo ...
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -59,8 +60,8 @@ public abstract class AbstractWxCpConfiguration {
|
||||
String corpId = entry.getKey();
|
||||
// 校验每个企业下,agentId 是否唯一
|
||||
boolean multi = entry.getValue().stream()
|
||||
// 通讯录没有 agentId,如果不判断是否为空,这里会报 NPE 异常
|
||||
.collect(Collectors.groupingBy(c -> c.getAgentId() == null ? 0 : c.getAgentId(), Collectors.counting()))
|
||||
// 通讯录没有 agentId,使用字符串转换避免 null 与 agentId=0 冲突
|
||||
.collect(Collectors.groupingBy(c -> Objects.toString(c.getAgentId(), "null"), Collectors.counting()))
|
||||
.entrySet().stream().anyMatch(e -> e.getValue() > 1);
|
||||
if (multi) {
|
||||
throw new RuntimeException("请确保企业微信配置唯一性[" + corpId + "]");
|
||||
|
||||
Reference in New Issue
Block a user