调整IdParameter类
This commit is contained in:
parent
f5e9046294
commit
98a86108ae
@ -250,7 +250,7 @@
|
|||||||
</error>
|
</error>
|
||||||
<error>
|
<error>
|
||||||
<code>40063</code>
|
<code>40063</code>
|
||||||
<text>红包参数为空</text>
|
<text>参数为空</text>
|
||||||
</error>
|
</error>
|
||||||
<error>
|
<error>
|
||||||
<code>40064</code>
|
<code>40064</code>
|
||||||
@ -897,6 +897,10 @@
|
|||||||
<code>82004</code>
|
<code>82004</code>
|
||||||
<text>微信版本号过低</text>
|
<text>微信版本号过低</text>
|
||||||
</error>
|
</error>
|
||||||
|
<error>
|
||||||
|
<code>85002</code>
|
||||||
|
<text>包含敏感词</text>
|
||||||
|
</error>
|
||||||
<!-- 语义理解API错误 -->
|
<!-- 语义理解API错误 -->
|
||||||
<error>
|
<error>
|
||||||
<code>7000000</code>
|
<code>7000000</code>
|
||||||
|
|||||||
@ -296,7 +296,7 @@ public class UserApi extends QyApi {
|
|||||||
* 成员列表
|
* 成员列表
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98"
|
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98"
|
||||||
* >批量删除成员说明</a
|
* >批量删除成员说明</a>
|
||||||
* @return 处理结果
|
* @return 处理结果
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -46,8 +46,8 @@ public class NotifyMessage implements Serializable {
|
|||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
private IdParameter target;
|
private IdParameter target;
|
||||||
|
|
||||||
public NotifyMessage(NotifyTuple tuple, int agentid) {
|
public NotifyMessage(int agentid, NotifyTuple tuple) {
|
||||||
this(agentid, tuple, new IdParameter(), false);
|
this(agentid, tuple, IdParameter.get(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotifyMessage(int agentid, NotifyTuple tuple, IdParameter target,
|
public NotifyMessage(int agentid, NotifyTuple tuple, IdParameter target,
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package com.foxinmy.weixin4j.qy.model;
|
package com.foxinmy.weixin4j.qy.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
import com.foxinmy.weixin4j.util.StringUtil;
|
||||||
@ -21,46 +24,102 @@ public class IdParameter implements Serializable {
|
|||||||
|
|
||||||
private static final char SEPARATOR = '|';
|
private static final char SEPARATOR = '|';
|
||||||
|
|
||||||
private Map<String, String> parameterMap;
|
private List<String> userIds;
|
||||||
|
private List<Integer> partyIds;
|
||||||
|
private List<Integer> tagIds;
|
||||||
|
|
||||||
public IdParameter() {
|
private IdParameter() {
|
||||||
this.parameterMap = new HashMap<String, String>();
|
this.userIds = new ArrayList<String>();
|
||||||
|
this.partyIds = new ArrayList<Integer>();
|
||||||
|
this.tagIds = new ArrayList<Integer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IdParameter get() {
|
||||||
|
return new IdParameter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 成员ID列表,最多支持1000个
|
* 增加成员ID列表,最多支持1000个
|
||||||
*
|
*
|
||||||
* @param userIds
|
* @param userIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IdParameter putUseIds(String... userIds) {
|
public IdParameter putUserIds(String... userIds) {
|
||||||
parameterMap.put("touser", StringUtil.join(userIds, SEPARATOR));
|
this.userIds.addAll(Arrays.asList(userIds));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门ID列表,最多支持100个
|
* 设置成员ID列表,最多支持1000个
|
||||||
|
*
|
||||||
|
* @param userIds
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public IdParameter setUserIds(List<String> userIds) {
|
||||||
|
this.userIds = userIds;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增部门ID列表,最多支持100个
|
||||||
*
|
*
|
||||||
* @param partyIds
|
* @param partyIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IdParameter putUseIds(int... partyIds) {
|
public IdParameter putPartyIds(Integer... partyIds) {
|
||||||
parameterMap.put("toparty", StringUtil.join(partyIds, SEPARATOR));
|
this.partyIds.addAll(Arrays.asList(partyIds));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标签ID列表
|
* 设置部门ID列表,最多支持100个
|
||||||
|
*
|
||||||
|
* @param partyIds
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public IdParameter setPartyIds(List<Integer> partyIds) {
|
||||||
|
this.partyIds = partyIds;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增标签ID列表
|
||||||
*
|
*
|
||||||
* @param tagIds
|
* @param tagIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IdParameter putTagIds(int... tagIds) {
|
public IdParameter putTagIds(Integer... tagIds) {
|
||||||
parameterMap.put("totag", StringUtil.join(tagIds, SEPARATOR));
|
this.tagIds.addAll(Arrays.asList(tagIds));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置标签ID列表
|
||||||
|
*
|
||||||
|
* @param tagIds
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public IdParameter setTagIds(List<Integer> tagIds) {
|
||||||
|
this.tagIds = tagIds;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目标参数
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Map<String, String> getParameter() {
|
public Map<String, String> getParameter() {
|
||||||
|
Map<String, String> parameterMap = new HashMap<String, String>();
|
||||||
|
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;
|
return parameterMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,39 +37,39 @@ public class NotifyMsgTest extends TokenTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void text() throws WeixinException {
|
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));
|
System.out.println(notifyApi.sendNotify(notify));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void image() throws WeixinException {
|
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));
|
System.out.println(notifyApi.sendNotify(notify));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voice() throws WeixinException {
|
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));
|
System.out.println(notifyApi.sendNotify(notify));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void video() throws WeixinException {
|
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));
|
System.out.println(notifyApi.sendNotify(notify));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void file() throws WeixinException {
|
public void file() throws WeixinException {
|
||||||
File file = new File("file");
|
File file = new File("file");
|
||||||
NotifyMessage notify = new NotifyMessage(file, 0);
|
NotifyMessage notify = new NotifyMessage(0, file);
|
||||||
System.out.println(notifyApi.sendNotify(notify));
|
System.out.println(notifyApi.sendNotify(notify));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void news() throws WeixinException {
|
public void news() throws WeixinException {
|
||||||
News news = new News();
|
News news = new News();
|
||||||
NotifyMessage notify = new NotifyMessage(news, 0);
|
NotifyMessage notify = new NotifyMessage(0, news);
|
||||||
news.addArticle("title1", "desc1", "picUrl1", "url1");
|
news.addArticle("title1", "desc1", "picUrl1", "url1");
|
||||||
news.addArticle("title2", "desc2", "picUrl2", "url2");
|
news.addArticle("title2", "desc2", "picUrl2", "url2");
|
||||||
System.out.println(notifyApi.sendNotify(notify));
|
System.out.println(notifyApi.sendNotify(notify));
|
||||||
@ -78,7 +78,7 @@ public class NotifyMsgTest extends TokenTest {
|
|||||||
@Test
|
@Test
|
||||||
public void mpnews() throws WeixinException {
|
public void mpnews() throws WeixinException {
|
||||||
MpNews news = new MpNews();
|
MpNews news = new MpNews();
|
||||||
NotifyMessage notify = new NotifyMessage(news, 0);
|
NotifyMessage notify = new NotifyMessage(0, news);
|
||||||
news.addArticle("thumbMediaId1", "title1", "content1");
|
news.addArticle("thumbMediaId1", "title1", "content1");
|
||||||
news.addArticle("thumbMediaId2", "title1", "content2");
|
news.addArticle("thumbMediaId2", "title1", "content2");
|
||||||
System.out.println(notifyApi.sendNotify(notify));
|
System.out.println(notifyApi.sendNotify(notify));
|
||||||
@ -87,7 +87,7 @@ public class NotifyMsgTest extends TokenTest {
|
|||||||
@Test
|
@Test
|
||||||
public void send1() throws WeixinException {
|
public void send1() throws WeixinException {
|
||||||
Text text = new Text("this is a text");
|
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"));
|
Assert.assertEquals(0, result.getIntValue("errcode"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user