diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml index fea10021..42e111c0 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml @@ -250,7 +250,7 @@ 40063 - 红包参数为空 + 参数为空 40064 @@ -897,6 +897,10 @@ 82004 微信版本号过低 + + 85002 + 包含敏感词 + 7000000 diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/UserApi.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/UserApi.java index b8ec7cfd..fdf74bb2 100644 --- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/UserApi.java +++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/UserApi.java @@ -296,7 +296,7 @@ public class UserApi extends QyApi { * 成员列表 * @see 批量删除成员说明批量删除成员说明 * @return 处理结果 * @throws WeixinException */ diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/message/NotifyMessage.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/message/NotifyMessage.java index 2acd4347..b1ca4bec 100644 --- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/message/NotifyMessage.java +++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/message/NotifyMessage.java @@ -46,8 +46,8 @@ public class NotifyMessage implements Serializable { @JSONField(serialize = false) private IdParameter target; - public NotifyMessage(NotifyTuple tuple, int agentid) { - this(agentid, tuple, new IdParameter(), false); + public NotifyMessage(int agentid, NotifyTuple tuple) { + this(agentid, tuple, IdParameter.get(), false); } public NotifyMessage(int agentid, NotifyTuple tuple, IdParameter target, diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/IdParameter.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/IdParameter.java index e4dc62af..95c4c00f 100644 --- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/IdParameter.java +++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/IdParameter.java @@ -1,7 +1,10 @@ package com.foxinmy.weixin4j.qy.model; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import com.foxinmy.weixin4j.util.StringUtil; @@ -20,47 +23,103 @@ public class IdParameter implements Serializable { private static final long serialVersionUID = -2689758682205591133L; private static final char SEPARATOR = '|'; - - private Map parameterMap; - public IdParameter() { - this.parameterMap = new HashMap(); + private List userIds; + private List partyIds; + private List tagIds; + + private IdParameter() { + this.userIds = new ArrayList(); + this.partyIds = new ArrayList(); + this.tagIds = new ArrayList(); + } + + public static IdParameter get() { + return new IdParameter(); } /** - * 成员ID列表,最多支持1000个 + * 增加成员ID列表,最多支持1000个 * * @param userIds * @return */ - public IdParameter putUseIds(String... userIds) { - parameterMap.put("touser", StringUtil.join(userIds, SEPARATOR)); + public IdParameter putUserIds(String... userIds) { + this.userIds.addAll(Arrays.asList(userIds)); return this; } /** - * 部门ID列表,最多支持100个 + * 设置成员ID列表,最多支持1000个 + * + * @param userIds + * @return + */ + public IdParameter setUserIds(List userIds) { + this.userIds = userIds; + return this; + } + + /** + * 新增部门ID列表,最多支持100个 * * @param partyIds * @return */ - public IdParameter putUseIds(int... partyIds) { - parameterMap.put("toparty", StringUtil.join(partyIds, SEPARATOR)); + public IdParameter putPartyIds(Integer... partyIds) { + this.partyIds.addAll(Arrays.asList(partyIds)); return this; } /** - * 标签ID列表 + * 设置部门ID列表,最多支持100个 + * + * @param partyIds + * @return + */ + public IdParameter setPartyIds(List partyIds) { + this.partyIds = partyIds; + return this; + } + + /** + * 新增标签ID列表 * * @param tagIds * @return */ - public IdParameter putTagIds(int... tagIds) { - parameterMap.put("totag", StringUtil.join(tagIds, SEPARATOR)); + public IdParameter putTagIds(Integer... tagIds) { + this.tagIds.addAll(Arrays.asList(tagIds)); return this; } + /** + * 设置标签ID列表 + * + * @param tagIds + * @return + */ + public IdParameter setTagIds(List tagIds) { + this.tagIds = tagIds; + return this; + } + + /** + * 目标参数 + * + * @return + */ public Map getParameter() { + Map parameterMap = new HashMap(); + if (userIds != null && !userIds.isEmpty()) { + parameterMap.put("touser", StringUtil.join(userIds, SEPARATOR)); + } + if (partyIds != null && !partyIds.isEmpty()) { + parameterMap.put("toparty", StringUtil.join(partyIds, SEPARATOR)); + } + if (tagIds != null && !tagIds.isEmpty()) { + parameterMap.put("totag", StringUtil.join(tagIds, SEPARATOR)); + } return parameterMap; } } diff --git a/weixin4j-qy/src/test/java/com/foxinmy/weixin4j/qy/test/NotifyMsgTest.java b/weixin4j-qy/src/test/java/com/foxinmy/weixin4j/qy/test/NotifyMsgTest.java index 041428c2..f69a94ec 100644 --- a/weixin4j-qy/src/test/java/com/foxinmy/weixin4j/qy/test/NotifyMsgTest.java +++ b/weixin4j-qy/src/test/java/com/foxinmy/weixin4j/qy/test/NotifyMsgTest.java @@ -37,39 +37,39 @@ public class NotifyMsgTest extends TokenTest { @Test public void text() throws WeixinException { - NotifyMessage notify = new NotifyMessage(new Text("content"), 0); + NotifyMessage notify = new NotifyMessage(0, new Text("content")); System.out.println(notifyApi.sendNotify(notify)); } @Test public void image() throws WeixinException { - NotifyMessage notify = new NotifyMessage(new Image("123"), 0); + NotifyMessage notify = new NotifyMessage(0, new Image("123")); System.out.println(notifyApi.sendNotify(notify)); } @Test public void voice() throws WeixinException { - NotifyMessage notify = new NotifyMessage(new Voice("123"), 0); + NotifyMessage notify = new NotifyMessage(0, new Voice("123")); System.out.println(notifyApi.sendNotify(notify)); } @Test public void video() throws WeixinException { - NotifyMessage notify = new NotifyMessage(new Video("123"), 0); + NotifyMessage notify = new NotifyMessage(0, new Video("123")); System.out.println(notifyApi.sendNotify(notify)); } @Test public void file() throws WeixinException { File file = new File("file"); - NotifyMessage notify = new NotifyMessage(file, 0); + NotifyMessage notify = new NotifyMessage(0, file); System.out.println(notifyApi.sendNotify(notify)); } @Test public void news() throws WeixinException { News news = new News(); - NotifyMessage notify = new NotifyMessage(news, 0); + NotifyMessage notify = new NotifyMessage(0, news); news.addArticle("title1", "desc1", "picUrl1", "url1"); news.addArticle("title2", "desc2", "picUrl2", "url2"); System.out.println(notifyApi.sendNotify(notify)); @@ -78,7 +78,7 @@ public class NotifyMsgTest extends TokenTest { @Test public void mpnews() throws WeixinException { MpNews news = new MpNews(); - NotifyMessage notify = new NotifyMessage(news, 0); + NotifyMessage notify = new NotifyMessage(0, news); news.addArticle("thumbMediaId1", "title1", "content1"); news.addArticle("thumbMediaId2", "title1", "content2"); System.out.println(notifyApi.sendNotify(notify)); @@ -87,7 +87,7 @@ public class NotifyMsgTest extends TokenTest { @Test public void send1() throws WeixinException { Text text = new Text("this is a text"); - JSONObject result = notifyApi.sendNotify(new NotifyMessage(text, 1)); + JSONObject result = notifyApi.sendNotify(new NotifyMessage(1, text)); Assert.assertEquals(0, result.getIntValue("errcode")); } }