ソースを参照

添加批量为用户打标签的接口

master
BinaryWang 8年前
コミット
9780d651d6
3個のファイルの変更42行の追加0行の削除
  1. +10
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java
  2. +24
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java
  3. +8
    -0
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java

+ 10
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java ファイルの表示

@@ -66,4 +66,14 @@ public interface WxMpUserTagService {
*/
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;

}

+ 24
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java ファイルの表示

@@ -1,5 +1,6 @@
package me.chanjar.weixin.mp.api.impl;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -106,4 +107,27 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
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);
}
}

+ 8
- 0
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java ファイルの表示

@@ -60,4 +60,12 @@ public class WxMpUserTagServiceImplTest {
System.out.println(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);
}
}

読み込み中…
キャンセル
保存