调整IdParameter类

This commit is contained in:
jinyu 2015-07-21 17:56:49 +08:00
parent f5e9046294
commit 98a86108ae
5 changed files with 88 additions and 25 deletions

View File

@ -250,7 +250,7 @@
</error>
<error>
<code>40063</code>
<text>红包参数为空</text>
<text>参数为空</text>
</error>
<error>
<code>40064</code>
@ -897,6 +897,10 @@
<code>82004</code>
<text>微信版本号过低</text>
</error>
<error>
<code>85002</code>
<text>包含敏感词</text>
</error>
<!-- 语义理解API错误 -->
<error>
<code>7000000</code>

View File

@ -296,7 +296,7 @@ public class UserApi extends QyApi {
* 成员列表
* @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"
* >批量删除成员说明</a
* >批量删除成员说明</a>
* @return 处理结果
* @throws WeixinException
*/

View File

@ -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,

View File

@ -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<String, String> parameterMap;
public IdParameter() {
this.parameterMap = new HashMap<String, String>();
private List<String> userIds;
private List<Integer> partyIds;
private List<Integer> tagIds;
private IdParameter() {
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
* @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<String> 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<Integer> 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<Integer> tagIds) {
this.tagIds = tagIds;
return this;
}
/**
* 目标参数
*
* @return
*/
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;
}
}

View File

@ -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"));
}
}