瀏覽代碼

🐛 #1327 修复小程序获取订阅消息公共模板标题和获取关键词库两个接口问题

dev1
ArBing 5 年之前
committed by Binary Wang
父節點
當前提交
8c514a7850
共有 3 個文件被更改,包括 14 次插入9 次删除
  1. +1
    -1
      weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java
  2. +10
    -5
      weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImpl.java
  3. +3
    -3
      weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImplTest.java

+ 1
- 1
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java 查看文件

@@ -57,7 +57,7 @@ public interface WxMaSubscribeService {
* @return . * @return .
* @throws WxErrorException . * @throws WxErrorException .
*/ */
WxMaTemplateLibraryListResult getPubTemplateTitleList(Integer[] ids, int start, int limit) throws WxErrorException;
WxMaTemplateLibraryListResult getPubTemplateTitleList(String[] ids, int start, int limit) throws WxErrorException;


/** /**
* <pre> * <pre>


+ 10
- 5
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImpl.java 查看文件

@@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@@ -11,6 +12,7 @@ import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;


import java.io.Serializable;
import java.util.List; import java.util.List;


/** /**
@@ -22,15 +24,18 @@ public class WxMaSubscribeServiceImpl implements WxMaSubscribeService {
private WxMaService wxMaService; private WxMaService wxMaService;


@Override @Override
public WxMaTemplateLibraryListResult getPubTemplateTitleList(Integer[] ids, int start, int limit) throws WxErrorException {
return WxMaTemplateLibraryListResult.fromJson(this.wxMaService.post(GET_PUB_TEMPLATE_TITLE_LIST_URL,
ImmutableMap.of("ids", StringUtils.join(ids, ","),
"start", start, "limit", limit)));
public WxMaTemplateLibraryListResult getPubTemplateTitleList(String[] ids, int start, int limit) throws WxErrorException {
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("ids", StringUtils.join(ids, ","),
"start", start, "limit", limit);
String responseText = this.wxMaService.get(GET_PUB_TEMPLATE_TITLE_LIST_URL,
Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxMaTemplateLibraryListResult.fromJson(responseText);
} }


@Override @Override
public List<PubTemplateKeyword> getPubTemplateKeyWordsById(String id) throws WxErrorException { public List<PubTemplateKeyword> getPubTemplateKeyWordsById(String id) throws WxErrorException {
String responseText = this.wxMaService.post(GET_PUB_TEMPLATE_KEY_WORDS_BY_ID_URL, ImmutableMap.of("tid", id));
String responseText = this.wxMaService.get(GET_PUB_TEMPLATE_KEY_WORDS_BY_ID_URL,
Joiner.on("&").withKeyValueSeparator("=").join(ImmutableMap.of("tid", id)));
return WxMaGsonBuilder.create().fromJson(new JsonParser().parse(responseText).getAsJsonObject() return WxMaGsonBuilder.create().fromJson(new JsonParser().parse(responseText).getAsJsonObject()
.getAsJsonArray("data"), new TypeToken<List<PubTemplateKeyword>>() { .getAsJsonArray("data"), new TypeToken<List<PubTemplateKeyword>>() {
}.getType()); }.getType());


+ 3
- 3
weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImplTest.java 查看文件

@@ -27,18 +27,18 @@ public class WxMaSubscribeServiceImplTest {


@Test @Test
public void testGetPubTemplateTitleList() throws WxErrorException { public void testGetPubTemplateTitleList() throws WxErrorException {
this.wxService.getSubscribeService().getPubTemplateTitleList(new Integer[]{578}, 1, 1);
this.wxService.getSubscribeService().getPubTemplateTitleList(new String[]{"2", "616"}, 0, 1);
} }


@Test @Test
public void testGetPubTemplateKeyWordsById() throws WxErrorException { public void testGetPubTemplateKeyWordsById() throws WxErrorException {
final List<WxMaSubscribeService.PubTemplateKeyword> result = this.wxService.getSubscribeService().getPubTemplateKeyWordsById("578");
final List<WxMaSubscribeService.PubTemplateKeyword> result = this.wxService.getSubscribeService().getPubTemplateKeyWordsById("99");
System.out.println(result); System.out.println(result);
} }


@Test @Test
public void testAddTemplate() throws WxErrorException { public void testAddTemplate() throws WxErrorException {
final String templateId = this.wxService.getSubscribeService().addTemplate("1", Lists.newArrayList(1), "hhaa");
final String templateId = this.wxService.getSubscribeService().addTemplate("401", Lists.newArrayList(1, 2), "测试数据");
System.out.println(templateId); System.out.println(templateId);
} }




Loading…
取消
儲存