From cb9380cc4f3344cba8da2e4b5f7989750baf9f91 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Wed, 28 Sep 2016 11:12:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=B6=88=E6=81=AF=E7=9A=84=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/impl/WxMpServiceImpl.java | 5 +- .../weixin/mp/bean/WxMpTemplateData.java | 4 +- .../weixin/mp/bean/WxMpTemplateMessage.java | 66 +++++++++++++++++-- .../chanjar/weixin/mp/api/ApiTestModule.java | 50 ++------------ .../weixin/mp/api/WxMpMassMessageAPITest.java | 4 +- .../mp/api/WxXmlMpInMemoryConfigStorage.java | 57 ++++++++++++++++ .../mp/api/impl/WxMpGroupServiceImplTest.java | 5 +- .../mp/api/impl/WxMpKefuServiceImplTest.java | 6 +- .../mp/api/impl/WxMpPayServiceImplTest.java | 3 +- .../mp/api/impl/WxMpServiceImplTest.java | 23 +++++-- .../WxMpUserBlacklistServiceImplTest.java | 7 +- .../mp/api/impl/WxMpUserServiceImplTest.java | 5 +- .../api/impl/WxMpUserTagServiceImplTest.java | 5 +- .../src/test/resources/test-config.sample.xml | 1 + 14 files changed, 164 insertions(+), 77 deletions(-) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index 9710697f..ba3fcdfc 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -257,9 +257,8 @@ public class WxMpServiceImpl implements WxMpService { @Override public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/message/template/send"; - String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson()); - JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); - final JsonObject jsonObject = tmpJsonElement.getAsJsonObject(); + String responseContent = this.post(url, templateMessage.toJson()); + final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); if (jsonObject.get("errcode").getAsInt() == 0){ return jsonObject.get("msgid").getAsString(); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java index ff83baa9..d46ae24b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateData.java @@ -7,9 +7,6 @@ import java.io.Serializable; */ public class WxMpTemplateData implements Serializable { - /** - * - */ private static final long serialVersionUID = 6301835292940277870L; private String name; private String value; @@ -48,6 +45,7 @@ public class WxMpTemplateData implements Serializable { public String getColor() { return this.color; } + public void setColor(String color) { this.color = color; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java index eec25eda..408abb50 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpTemplateMessage.java @@ -1,17 +1,14 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class WxMpTemplateMessage implements Serializable { +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - /** - * - */ +public class WxMpTemplateMessage implements Serializable { private static final long serialVersionUID = 5063374783759519418L; + private String toUser; private String templateId; private String url; @@ -65,4 +62,61 @@ public class WxMpTemplateMessage implements Serializable { public String toJson() { return WxMpGsonBuilder.INSTANCE.create().toJson(this); } + + public static WxMpTemplateMessageBuilder builder() { + return new WxMpTemplateMessageBuilder(); + } + + public static class WxMpTemplateMessageBuilder { + private String toUser; + private String templateId; + private String url; + private String topColor; + private List data = new ArrayList<>(); + + public WxMpTemplateMessageBuilder toUser(String toUser) { + this.toUser = toUser; + return this; + } + + public WxMpTemplateMessageBuilder templateId(String templateId) { + this.templateId = templateId; + return this; + } + + public WxMpTemplateMessageBuilder url(String url) { + this.url = url; + return this; + } + + public WxMpTemplateMessageBuilder topColor(String topColor) { + this.topColor = topColor; + return this; + } + + public WxMpTemplateMessageBuilder data(List data) { + this.data = data; + return this; + } + + public WxMpTemplateMessageBuilder from(WxMpTemplateMessage origin) { + this.toUser(origin.toUser); + this.templateId(origin.templateId); + this.url(origin.url); + this.topColor(origin.topColor); + this.data(origin.data); + return this; + } + + public WxMpTemplateMessage build() { + WxMpTemplateMessage m = new WxMpTemplateMessage(); + m.toUser = this.toUser; + m.templateId = this.templateId; + m.url = this.url; + m.topColor = this.topColor; + m.data = this.data; + return m; + } + } + } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java index f4b79ae2..4ec12cbd 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java @@ -3,15 +3,12 @@ package me.chanjar.weixin.mp.api; import java.io.IOException; import java.io.InputStream; -import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; -import org.apache.commons.lang3.builder.ToStringBuilder; - import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.xml.XStreamInitializer; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; public class ApiTestModule implements Module { @@ -19,8 +16,8 @@ public class ApiTestModule implements Module { public void configure(Binder binder) { try (InputStream is1 = ClassLoader .getSystemResourceAsStream("test-config.xml")) { - WxXmlMpInMemoryConfigStorage config = fromXml( - WxXmlMpInMemoryConfigStorage.class, is1); + WxXmlMpInMemoryConfigStorage config = this + .fromXml(WxXmlMpInMemoryConfigStorage.class, is1); WxMpServiceImpl wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); @@ -32,50 +29,11 @@ public class ApiTestModule implements Module { } @SuppressWarnings("unchecked") - public static T fromXml(Class clazz, InputStream is) { + private T fromXml(Class clazz, InputStream is) { XStream xstream = XStreamInitializer.getInstance(); xstream.alias("xml", clazz); xstream.processAnnotations(clazz); return (T) xstream.fromXML(is); } - @XStreamAlias("xml") - public static class WxXmlMpInMemoryConfigStorage - extends WxMpInMemoryConfigStorage { - - private String openid; - private String kfAccount; - private String qrconnectRedirectUrl; - - public String getOpenid() { - return this.openid; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - - public String getKfAccount() { - return this.kfAccount; - } - - public void setKfAccount(String kfAccount) { - this.kfAccount = kfAccount; - } - - public String getQrconnectRedirectUrl() { - return this.qrconnectRedirectUrl; - } - - public void setQrconnectRedirectUrl(String qrconnectRedirectUrl) { - this.qrconnectRedirectUrl = qrconnectRedirectUrl; - } - - } - } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java index ee99b6e1..3f2c28b8 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java @@ -36,7 +36,7 @@ public class WxMpMassMessageAPITest { @Test public void testTextMassOpenIdsMessageSend() throws WxErrorException { // 发送群发消息 - ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); @@ -53,7 +53,7 @@ public class WxMpMassMessageAPITest { public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException { // 发送群发消息 - ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(massMsgType); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java new file mode 100644 index 00000000..6b28f196 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxXmlMpInMemoryConfigStorage.java @@ -0,0 +1,57 @@ +/** + * Copyright(c) 2011-2016 by UCredit Inc. + * All Rights Reserved + */ +package me.chanjar.weixin.mp.api; + +import org.apache.commons.lang3.builder.ToStringBuilder; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +@XStreamAlias("xml") +public class WxXmlMpInMemoryConfigStorage + extends WxMpInMemoryConfigStorage { + + private String openid; + private String kfAccount; + private String qrconnectRedirectUrl; + private String templateId; + + public String getOpenid() { + return this.openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public String getKfAccount() { + return this.kfAccount; + } + + public void setKfAccount(String kfAccount) { + this.kfAccount = kfAccount; + } + + public String getQrconnectRedirectUrl() { + return this.qrconnectRedirectUrl; + } + + public void setQrconnectRedirectUrl(String qrconnectRedirectUrl) { + this.qrconnectRedirectUrl = qrconnectRedirectUrl; + } + + public String getTemplateId() { + return this.templateId; + } + + public void setTemplateId(String templateId) { + this.templateId = templateId; + } + +} \ No newline at end of file diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java index 5d114cc4..2216e553 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java @@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.WxMpGroup; import org.testng.Assert; import org.testng.annotations.Guice; @@ -48,13 +49,13 @@ public class WxMpGroupServiceImplTest { } public void testGroupQueryUserGroup() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenid()); Assert.assertTrue(groupid != -1l); } public void testGroupMoveUser() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenid(), this.wxService.getGroupService().groupGet().get(3).getId()); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index 66ff3c30..32a0118f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -14,7 +14,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.WxMpCustomMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfInfo; @@ -38,7 +38,7 @@ public class WxMpKefuServiceImplTest { protected WxMpServiceImpl wxService; public void testSendCustomMessage() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpCustomMessage message = new WxMpCustomMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); @@ -50,7 +50,7 @@ public class WxMpKefuServiceImplTest { } public void testSendCustomMessageWithKfAccount() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpCustomMessage message = new WxMpCustomMessage(); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java index f246032d..1982f948 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java @@ -7,6 +7,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.pay.WxRedpackResult; import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest; import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest; @@ -71,7 +72,7 @@ public class WxMpPayServiceImplTest { request.setClientIp("aaa"); request.setMchBillno("aaaa"); request - .setReOpenid(((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + .setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request); System.err.println(redpackResult); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java index 33242ba4..c108d575 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java @@ -1,5 +1,8 @@ package me.chanjar.weixin.mp.api.impl; +import java.text.SimpleDateFormat; +import java.util.Date; + import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -7,8 +10,11 @@ import org.testng.annotations.Test; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.bean.WxMpTemplateData; +import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; @Test @Guice(modules = ApiTestModule.class) @@ -82,9 +88,18 @@ public class WxMpServiceImplTest { Assert.fail("Not yet implemented"); } - @Test - public void testTemplateSend() { - Assert.fail("Not yet implemented"); + @Test(invocationCount = 100, threadPoolSize = 30) + public void testTemplateSend() throws WxErrorException { + SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss.SSS"); + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + .getWxMpConfigStorage(); + WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() + .toUser(configStorage.getOpenid()) + .templateId(configStorage.getTemplateId()).build(); + templateMessage.addWxMpTemplateData( + new WxMpTemplateData("first", dateFormat.format(new Date()))); + this.wxService.templateSend(templateMessage); } @Test diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java index 6d31ea97..aebf6926 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.mp.api.impl; import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import org.testng.Assert; import org.testng.annotations.Guice; @@ -21,7 +22,7 @@ public class WxMpUserBlacklistServiceImplTest { @Test public void testGetBlacklist() throws Exception { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid()); Assert.assertNotNull(wxMpUserBlacklistGetResult); @@ -33,7 +34,7 @@ public class WxMpUserBlacklistServiceImplTest { @Test public void testPushToBlacklist() throws Exception { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); List openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); @@ -42,7 +43,7 @@ public class WxMpUserBlacklistServiceImplTest { @Test public void testPullFromBlacklist() throws Exception { - ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService .getWxMpConfigStorage(); List openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java index 95671b40..4167a852 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java @@ -8,6 +8,7 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; @@ -25,12 +26,12 @@ public class WxMpUserServiceImplTest { protected WxMpServiceImpl wxService; public void testUserUpdateRemark() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); this.wxService.getUserService().userUpdateRemark(configProvider.getOpenid(), "测试备注名"); } public void testUserInfo() throws WxErrorException { - ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); + WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpUser user = this.wxService.getUserService().userInfo(configProvider.getOpenid(), null); Assert.assertNotNull(user); System.out.println(user); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index 5ccae195..74a6cfc4 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; import org.testng.Assert; @@ -63,7 +64,7 @@ public class WxMpUserTagServiceImplTest { @Test public void testBatchUntagging() throws Exception { - String[] openids = new String[]{((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; + String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids); System.out.println(res); Assert.assertTrue(res); @@ -72,7 +73,7 @@ public class WxMpUserTagServiceImplTest { @Test public void testUserTagList() throws Exception { List res = this.wxService.getUserTagService().userTagList( - ((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); + ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); System.out.println(res); Assert.assertNotNull(res); } diff --git a/weixin-java-mp/src/test/resources/test-config.sample.xml b/weixin-java-mp/src/test/resources/test-config.sample.xml index 0df87b09..ad46a19e 100644 --- a/weixin-java-mp/src/test/resources/test-config.sample.xml +++ b/weixin-java-mp/src/test/resources/test-config.sample.xml @@ -6,6 +6,7 @@ 可以不填写 可以不填写 某个加你公众号的用户的openId + 模版消息的模版ID 网页授权获取用户信息回调地址 网页应用授权登陆回调地址 完整客服账号,格式为:账号前缀@公众号微信号