Skip to content

Commit e7a0d6a

Browse files
committed
#1271 企业微信标签创建接口支持传入id参数
1 parent d9da800 commit e7a0d6a

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,62 @@
1818
*/
1919
public interface WxCpTagService {
2020

21+
/**
22+
* 创建标签.
23+
* <pre>
24+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=ACCESS_TOKEN
25+
* 文档地址:https://work.weixin.qq.com/api/doc#90000/90135/90210
26+
* </pre>
27+
*
28+
* @param name 标签名称,长度限制为32个字以内(汉字或英文字母),标签名不可与其他标签重名。
29+
* @param id 标签id,非负整型,指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。
30+
* @return 标签id
31+
* @throws WxErrorException .
32+
*/
33+
String create(String name, Integer id) throws WxErrorException;
34+
2135
/**
2236
* 创建标签.
2337
*
2438
* @param tagName 标签名
39+
* @return 标签id
40+
* @throws WxErrorException .
41+
* @deprecated 建议使用 {@link #create(String, Integer)},其中后面的参数可以为空
2542
*/
43+
@Deprecated
2644
String create(String tagName) throws WxErrorException;
2745

2846
/**
2947
* 更新标签.
3048
*
3149
* @param tagId 标签id
3250
* @param tagName 标签名
51+
* @throws WxErrorException .
3352
*/
3453
void update(String tagId, String tagName) throws WxErrorException;
3554

3655
/**
3756
* 删除标签.
3857
*
3958
* @param tagId 标签id
59+
* @throws WxErrorException .
4060
*/
4161
void delete(String tagId) throws WxErrorException;
4262

4363
/**
4464
* 获得标签列表.
65+
*
66+
* @return 标签列表
67+
* @throws WxErrorException .
4568
*/
4669
List<WxCpTag> listAll() throws WxErrorException;
4770

4871
/**
4972
* 获取标签成员.
5073
*
5174
* @param tagId 标签ID
75+
* @return 成员列表
76+
* @throws WxErrorException .
5277
*/
5378
List<WxCpUser> listUsersByTagId(String tagId) throws WxErrorException;
5479

@@ -57,6 +82,8 @@ public interface WxCpTagService {
5782
* 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
5883
*
5984
* @param tagId 标签id
85+
* @return .
86+
* @throws WxErrorException .
6087
*/
6188
WxCpTagGetResult get(String tagId) throws WxErrorException;
6289

@@ -66,6 +93,8 @@ public interface WxCpTagService {
6693
* @param tagId 标签id
6794
* @param userIds 用户ID 列表
6895
* @param partyIds 企业部门ID列表
96+
* @return .
97+
* @throws WxErrorException .
6998
*/
7099
WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
71100

@@ -75,6 +104,8 @@ public interface WxCpTagService {
75104
* @param tagId 标签id
76105
* @param userIds 用户id列表
77106
* @param partyIds 企业部门ID列表
107+
* @return .
108+
* @throws WxErrorException .
78109
*/
79110
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
80111

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
import me.chanjar.weixin.cp.bean.WxCpTagAddOrRemoveUsersResult;
1111
import me.chanjar.weixin.cp.bean.WxCpTagGetResult;
1212
import me.chanjar.weixin.cp.bean.WxCpUser;
13-
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
1413
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1514

1615
import java.util.List;
1716

1817
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tag.*;
19-
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tag.TAG_CREATE;
20-
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tag.TAG_UPDATE;
2118

2219
/**
2320
* <pre>
@@ -31,12 +28,27 @@
3128
public class WxCpTagServiceImpl implements WxCpTagService {
3229
private final WxCpService mainService;
3330

31+
@Override
32+
public String create(String name, Integer id) throws WxErrorException {
33+
JsonObject o = new JsonObject();
34+
o.addProperty("tagname", name);
35+
36+
if (id != null) {
37+
o.addProperty("tagid", id);
38+
}
39+
return this.create(o);
40+
}
41+
3442
@Override
3543
public String create(String tagName) throws WxErrorException {
3644
JsonObject o = new JsonObject();
3745
o.addProperty("tagname", tagName);
46+
return this.create(o);
47+
}
48+
49+
private String create(JsonObject param) throws WxErrorException {
3850
String url = this.mainService.getWxCpConfigStorage().getApiUrl(TAG_CREATE);
39-
String responseContent = this.mainService.post(url, o.toString());
51+
String responseContent = this.mainService.post(url, param.toString());
4052
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
4153
return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
4254
}

0 commit comments

Comments
 (0)