diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java index 78f1d791..52bf9323 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java @@ -18,11 +18,29 @@ import java.util.List; */ public interface WxCpTagService { + /** + * 创建标签. + *
+ * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=ACCESS_TOKEN + * 文档地址:https://work.weixin.qq.com/api/doc#90000/90135/90210 + *+ * + * @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
@@ -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(); }