mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 22:11:40 +08:00
添加批量为用户打标签的接口
This commit is contained in:
parent
592ac81163
commit
9780d651d6
@ -66,4 +66,14 @@ public interface WxMpUserTagService {
|
|||||||
*/
|
*/
|
||||||
WxTagListUser tagListUser(Integer tagId, String nextOpenid) throws WxErrorException;
|
WxTagListUser tagListUser(Integer tagId, String nextOpenid) 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/members/batchtagging?access_token=ACCESS_TOKEN
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
boolean batchTagging(Integer tagId, String[] openids) throws WxErrorException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.chanjar.weixin.mp.api.impl;
|
package me.chanjar.weixin.mp.api.impl;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import me.chanjar.weixin.common.bean.result.WxError;
|
import me.chanjar.weixin.common.bean.result.WxError;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
@ -106,4 +107,27 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
|
|||||||
responseContent);
|
responseContent);
|
||||||
return WxTagListUser.fromJson(responseContent);
|
return WxTagListUser.fromJson(responseContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean batchTagging(Integer tagId, String[] openids) throws WxErrorException {
|
||||||
|
String url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging";
|
||||||
|
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
json.addProperty("tagid", tagId);
|
||||||
|
JsonArray openidArrayJson = new JsonArray();
|
||||||
|
for (String openid : openids) {
|
||||||
|
openidArrayJson.add(openid);
|
||||||
|
}
|
||||||
|
json.add("openid_list", openidArrayJson);
|
||||||
|
|
||||||
|
String responseContent = this.wxMpService.post(url, json.toString());
|
||||||
|
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(),
|
||||||
|
responseContent);
|
||||||
|
WxError wxError = WxError.fromJson(responseContent);
|
||||||
|
if (wxError.getErrorCode() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new WxErrorException(wxError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,4 +60,12 @@ public class WxMpUserTagServiceImplTest {
|
|||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assert.assertNotNull(res);
|
Assert.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBatchTagging() throws Exception {
|
||||||
|
String[] openids = new String[]{((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()};
|
||||||
|
boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids);
|
||||||
|
System.out.println(res);
|
||||||
|
Assert.assertTrue(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user