#1271 企业微信标签创建接口支持传入id参数

This commit is contained in:
Binary Wang 2019-11-11 15:06:56 +08:00
parent d9da800af1
commit e7a0d6a597
2 changed files with 47 additions and 4 deletions

View File

@ -18,11 +18,29 @@ import java.util.List;
*/
public interface WxCpTagService {
/**
* 创建标签.
* <pre>
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=ACCESS_TOKEN
* 文档地址https://work.weixin.qq.com/api/doc#90000/90135/90210
* </pre>
*
* @param name 标签名称长度限制为32个字以内汉字或英文字母标签名不可与其他标签重名
* @param id 标签id非负整型指定此参数时新增的标签会生成对应的标签id不指定时则以目前最大的id自增
* @return 标签id
* @throws WxErrorException .
*/
String create(String name, Integer id) throws WxErrorException;
/**
* 创建标签.
*
* @param tagName 标签名
* @return 标签id
* @throws WxErrorException .
* @deprecated 建议使用 {@link #create(String, Integer)}其中后面的参数可以为空
*/
@Deprecated
String create(String tagName) throws WxErrorException;
/**
@ -30,6 +48,7 @@ public interface WxCpTagService {
*
* @param tagId 标签id
* @param tagName 标签名
* @throws WxErrorException .
*/
void update(String tagId, String tagName) throws WxErrorException;
@ -37,11 +56,15 @@ public interface WxCpTagService {
* 删除标签.
*
* @param tagId 标签id
* @throws WxErrorException .
*/
void delete(String tagId) throws WxErrorException;
/**
* 获得标签列表.
*
* @return 标签列表
* @throws WxErrorException .
*/
List<WxCpTag> listAll() throws WxErrorException;
@ -49,6 +72,8 @@ public interface WxCpTagService {
* 获取标签成员.
*
* @param tagId 标签ID
* @return 成员列表
* @throws WxErrorException .
*/
List<WxCpUser> listUsersByTagId(String tagId) throws WxErrorException;
@ -57,6 +82,8 @@ public interface WxCpTagService {
* 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
*
* @param tagId 标签id
* @return .
* @throws WxErrorException .
*/
WxCpTagGetResult get(String tagId) throws WxErrorException;
@ -66,6 +93,8 @@ public interface WxCpTagService {
* @param tagId 标签id
* @param userIds 用户ID 列表
* @param partyIds 企业部门ID列表
* @return .
* @throws WxErrorException .
*/
WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
@ -75,6 +104,8 @@ public interface WxCpTagService {
* @param tagId 标签id
* @param userIds 用户id列表
* @param partyIds 企业部门ID列表
* @return .
* @throws WxErrorException .
*/
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;

View File

@ -10,14 +10,11 @@ import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.List;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tag.*;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tag.TAG_CREATE;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tag.TAG_UPDATE;
/**
* <pre>
@ -31,12 +28,27 @@ import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tag.TAG_UPDATE;
public class WxCpTagServiceImpl implements WxCpTagService {
private final WxCpService mainService;
@Override
public String create(String name, Integer id) throws WxErrorException {
JsonObject o = new JsonObject();
o.addProperty("tagname", name);
if (id != null) {
o.addProperty("tagid", id);
}
return this.create(o);
}
@Override
public String create(String tagName) throws WxErrorException {
JsonObject o = new JsonObject();
o.addProperty("tagname", tagName);
return this.create(o);
}
private String create(JsonObject param) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(TAG_CREATE);
String responseContent = this.mainService.post(url, o.toString());
String responseContent = this.mainService.post(url, param.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
}