@@ -35,4 +35,14 @@ public interface WxMpUserTagService { | |||||
*/ | */ | ||||
List<WxUserTag> tagGet() throws WxErrorException; | 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; | |||||
} | } |
@@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; | |||||
import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
import me.chanjar.weixin.common.bean.result.WxError; | |||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.WxMpUserTagService; | import me.chanjar.weixin.mp.api.WxMpUserTagService; | ||||
@@ -32,12 +33,12 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
public WxUserTag tagCreate(String name) throws WxErrorException { | public WxUserTag tagCreate(String name) throws WxErrorException { | ||||
String url = API_URL_PREFIX + "/create"; | String url = API_URL_PREFIX + "/create"; | ||||
JsonObject json = new JsonObject(); | 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()); | 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); | responseContent); | ||||
return WxUserTag.fromJson(responseContent); | return WxUserTag.fromJson(responseContent); | ||||
} | } | ||||
@@ -51,4 +52,20 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { | |||||
responseContent); | responseContent); | ||||
return WxUserTag.listFromJson(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; | |||||
} | |||||
} | } |
@@ -1,15 +1,16 @@ | |||||
package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
import com.google.inject.Inject; | |||||
import me.chanjar.weixin.mp.api.ApiTestModule; | |||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag; | |||||
import java.util.List; | import java.util.List; | ||||
import org.testng.Assert; | import org.testng.Assert; | ||||
import org.testng.annotations.Guice; | import org.testng.annotations.Guice; | ||||
import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||
import com.google.inject.Inject; | |||||
import me.chanjar.weixin.mp.api.ApiTestModule; | |||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag; | |||||
/** | /** | ||||
* | * | ||||
* @author binarywang(https://github.com/binarywang) | * @author binarywang(https://github.com/binarywang) | ||||
@@ -21,11 +22,14 @@ public class WxMpUserTagServiceImplTest { | |||||
@Inject | @Inject | ||||
protected WxMpServiceImpl wxService; | protected WxMpServiceImpl wxService; | ||||
private Integer tagId; | |||||
@Test | @Test | ||||
public void testTagCreate() throws Exception { | public void testTagCreate() throws Exception { | ||||
String tagName = "测试标签"; | |||||
String tagName = "测试标签" + System.currentTimeMillis(); | |||||
WxUserTag res = this.wxService.getUserTagService().tagCreate(tagName); | WxUserTag res = this.wxService.getUserTagService().tagCreate(tagName); | ||||
System.out.println(res); | System.out.println(res); | ||||
this.tagId = res.getId(); | |||||
Assert.assertEquals(tagName, res.getName()); | Assert.assertEquals(tagName, res.getName()); | ||||
} | } | ||||
@@ -36,4 +40,12 @@ public class WxMpUserTagServiceImplTest { | |||||
Assert.assertNotNull(res); | Assert.assertNotNull(res); | ||||
} | } | ||||
@Test(dependsOnMethods = { "testTagCreate" }) | |||||
public void testTagUpdate() throws Exception { | |||||
String tagName = "修改标签" + System.currentTimeMillis(); | |||||
Boolean res = this.wxService.getUserTagService().tagUpdate(this.tagId, tagName); | |||||
System.out.println(res); | |||||
Assert.assertTrue(res); | |||||
} | |||||
} | } |