增加用户标签修改接口

This commit is contained in:
Binary Wang
2016-09-11 17:49:22 +08:00
parent 5d95f37235
commit 214661b6c6
3 changed files with 48 additions and 9 deletions

View File

@@ -35,4 +35,14 @@ public interface WxMpUserTagService {
*/
List<WxUserTag> tagGet() throws WxErrorException;
/**
* <pre>
* 编辑标签
* 详情请见:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">用户标签管理</a>
* 接口url格式 https://api.weixin.qq.com/cgi-bin/tags/update?access_token=ACCESS_TOKEN
* </pre>
*
*/
Boolean tagUpdate(Integer id, String name) throws WxErrorException;
}

View File

@@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
import com.google.gson.JsonObject;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserTagService;
@@ -32,12 +33,12 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
public WxUserTag tagCreate(String name) throws WxErrorException {
String url = API_URL_PREFIX + "/create";
JsonObject json = new JsonObject();
JsonObject groupJson = new JsonObject();
groupJson.addProperty("name", name);
json.add("tag", groupJson);
JsonObject tagJson = new JsonObject();
tagJson.addProperty("name", name);
json.add("tag", tagJson);
String responseContent = this.wxMpService.post(url, json.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, name,
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(),
responseContent);
return WxUserTag.fromJson(responseContent);
}
@@ -51,4 +52,20 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
responseContent);
return WxUserTag.listFromJson(responseContent);
}
@Override
public Boolean tagUpdate(Integer id, String name) throws WxErrorException {
String url = API_URL_PREFIX + "/update";
JsonObject json = new JsonObject();
JsonObject tagJson = new JsonObject();
tagJson.addProperty("id", id);
tagJson.addProperty("name", name);
json.add("tag", tagJson);
String responseContent = this.wxMpService.post(url, json.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(), responseContent);
WxError wxError = WxError.fromJson(responseContent);
return wxError.getErrorCode() == 0;
}
}