mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 07:23:01 +08:00
添加对发送模板消息的单元测试
This commit is contained in:
parent
a5757774cb
commit
cb9380cc4f
@ -257,9 +257,8 @@ public class WxMpServiceImpl implements WxMpService {
|
|||||||
@Override
|
@Override
|
||||||
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
|
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
|
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
|
||||||
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
|
String responseContent = this.post(url, templateMessage.toJson());
|
||||||
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
|
final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
||||||
final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
|
|
||||||
if (jsonObject.get("errcode").getAsInt() == 0){
|
if (jsonObject.get("errcode").getAsInt() == 0){
|
||||||
return jsonObject.get("msgid").getAsString();
|
return jsonObject.get("msgid").getAsString();
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,6 @@ import java.io.Serializable;
|
|||||||
*/
|
*/
|
||||||
public class WxMpTemplateData implements Serializable {
|
public class WxMpTemplateData implements Serializable {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 6301835292940277870L;
|
private static final long serialVersionUID = 6301835292940277870L;
|
||||||
private String name;
|
private String name;
|
||||||
private String value;
|
private String value;
|
||||||
@ -48,6 +45,7 @@ public class WxMpTemplateData implements Serializable {
|
|||||||
public String getColor() {
|
public String getColor() {
|
||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(String color) {
|
public void setColor(String color) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
package me.chanjar.weixin.mp.bean;
|
package me.chanjar.weixin.mp.bean;
|
||||||
|
|
||||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 static final long serialVersionUID = 5063374783759519418L;
|
||||||
|
|
||||||
private String toUser;
|
private String toUser;
|
||||||
private String templateId;
|
private String templateId;
|
||||||
private String url;
|
private String url;
|
||||||
@ -65,4 +62,61 @@ public class WxMpTemplateMessage implements Serializable {
|
|||||||
public String toJson() {
|
public String toJson() {
|
||||||
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
|
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<WxMpTemplateData> 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<WxMpTemplateData> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,12 @@ package me.chanjar.weixin.mp.api;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
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.Binder;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.thoughtworks.xstream.XStream;
|
import com.thoughtworks.xstream.XStream;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||||
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||||
|
|
||||||
public class ApiTestModule implements Module {
|
public class ApiTestModule implements Module {
|
||||||
|
|
||||||
@ -19,8 +16,8 @@ public class ApiTestModule implements Module {
|
|||||||
public void configure(Binder binder) {
|
public void configure(Binder binder) {
|
||||||
try (InputStream is1 = ClassLoader
|
try (InputStream is1 = ClassLoader
|
||||||
.getSystemResourceAsStream("test-config.xml")) {
|
.getSystemResourceAsStream("test-config.xml")) {
|
||||||
WxXmlMpInMemoryConfigStorage config = fromXml(
|
WxXmlMpInMemoryConfigStorage config = this
|
||||||
WxXmlMpInMemoryConfigStorage.class, is1);
|
.fromXml(WxXmlMpInMemoryConfigStorage.class, is1);
|
||||||
WxMpServiceImpl wxService = new WxMpServiceImpl();
|
WxMpServiceImpl wxService = new WxMpServiceImpl();
|
||||||
wxService.setWxMpConfigStorage(config);
|
wxService.setWxMpConfigStorage(config);
|
||||||
|
|
||||||
@ -32,50 +29,11 @@ public class ApiTestModule implements Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T fromXml(Class<T> clazz, InputStream is) {
|
private <T> T fromXml(Class<T> clazz, InputStream is) {
|
||||||
XStream xstream = XStreamInitializer.getInstance();
|
XStream xstream = XStreamInitializer.getInstance();
|
||||||
xstream.alias("xml", clazz);
|
xstream.alias("xml", clazz);
|
||||||
xstream.processAnnotations(clazz);
|
xstream.processAnnotations(clazz);
|
||||||
return (T) xstream.fromXML(is);
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class WxMpMassMessageAPITest {
|
|||||||
@Test
|
@Test
|
||||||
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
|
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
|
||||||
// 发送群发消息
|
// 发送群发消息
|
||||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
|
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService
|
||||||
.getWxMpConfigStorage();
|
.getWxMpConfigStorage();
|
||||||
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
|
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
|
||||||
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
|
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
|
||||||
@ -53,7 +53,7 @@ public class WxMpMassMessageAPITest {
|
|||||||
public void testMediaMassOpenIdsMessageSend(String massMsgType,
|
public void testMediaMassOpenIdsMessageSend(String massMsgType,
|
||||||
String mediaId) throws WxErrorException {
|
String mediaId) throws WxErrorException {
|
||||||
// 发送群发消息
|
// 发送群发消息
|
||||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
|
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService
|
||||||
.getWxMpConfigStorage();
|
.getWxMpConfigStorage();
|
||||||
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
|
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
|
||||||
massMessage.setMsgType(massMsgType);
|
massMessage.setMsgType(massMsgType);
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||||
|
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Guice;
|
import org.testng.annotations.Guice;
|
||||||
@ -48,13 +49,13 @@ public class WxMpGroupServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testGroupQueryUserGroup() throws WxErrorException {
|
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());
|
long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenid());
|
||||||
Assert.assertTrue(groupid != -1l);
|
Assert.assertTrue(groupid != -1l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGroupMoveUser() throws WxErrorException {
|
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());
|
this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenid(), this.wxService.getGroupService().groupGet().get(3).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import com.google.inject.Inject;
|
|||||||
import me.chanjar.weixin.common.api.WxConsts;
|
import me.chanjar.weixin.common.api.WxConsts;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
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.WxMpCustomMessage;
|
||||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfInfo;
|
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfInfo;
|
||||||
@ -38,7 +38,7 @@ public class WxMpKefuServiceImplTest {
|
|||||||
protected WxMpServiceImpl wxService;
|
protected WxMpServiceImpl wxService;
|
||||||
|
|
||||||
public void testSendCustomMessage() throws WxErrorException {
|
public void testSendCustomMessage() throws WxErrorException {
|
||||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
|
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
|
||||||
.getWxMpConfigStorage();
|
.getWxMpConfigStorage();
|
||||||
WxMpCustomMessage message = new WxMpCustomMessage();
|
WxMpCustomMessage message = new WxMpCustomMessage();
|
||||||
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
|
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
|
||||||
@ -50,7 +50,7 @@ public class WxMpKefuServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testSendCustomMessageWithKfAccount() throws WxErrorException {
|
public void testSendCustomMessageWithKfAccount() throws WxErrorException {
|
||||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
|
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
|
||||||
.getWxMpConfigStorage();
|
.getWxMpConfigStorage();
|
||||||
WxMpCustomMessage message = new WxMpCustomMessage();
|
WxMpCustomMessage message = new WxMpCustomMessage();
|
||||||
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
|
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
|
||||||
|
@ -7,6 +7,7 @@ import com.google.inject.Inject;
|
|||||||
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
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.WxRedpackResult;
|
||||||
import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest;
|
import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest;
|
||||||
import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest;
|
import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest;
|
||||||
@ -71,7 +72,7 @@ public class WxMpPayServiceImplTest {
|
|||||||
request.setClientIp("aaa");
|
request.setClientIp("aaa");
|
||||||
request.setMchBillno("aaaa");
|
request.setMchBillno("aaaa");
|
||||||
request
|
request
|
||||||
.setReOpenid(((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
|
.setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
|
||||||
WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request);
|
WxRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request);
|
||||||
System.err.println(redpackResult);
|
System.err.println(redpackResult);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package me.chanjar.weixin.mp.api.impl;
|
package me.chanjar.weixin.mp.api.impl;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
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;
|
||||||
@ -7,8 +10,11 @@ import org.testng.annotations.Test;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import me.chanjar.weixin.common.api.WxConsts;
|
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;
|
||||||
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
|
@Test
|
||||||
@Guice(modules = ApiTestModule.class)
|
@Guice(modules = ApiTestModule.class)
|
||||||
@ -82,9 +88,18 @@ public class WxMpServiceImplTest {
|
|||||||
Assert.fail("Not yet implemented");
|
Assert.fail("Not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(invocationCount = 100, threadPoolSize = 30)
|
||||||
public void testTemplateSend() {
|
public void testTemplateSend() throws WxErrorException {
|
||||||
Assert.fail("Not yet implemented");
|
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
|
@Test
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.chanjar.weixin.mp.api.impl;
|
package me.chanjar.weixin.mp.api.impl;
|
||||||
|
|
||||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||||
|
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
|
||||||
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
|
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Guice;
|
import org.testng.annotations.Guice;
|
||||||
@ -21,7 +22,7 @@ public class WxMpUserBlacklistServiceImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBlacklist() throws Exception {
|
public void testGetBlacklist() throws Exception {
|
||||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
|
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
|
||||||
.getWxMpConfigStorage();
|
.getWxMpConfigStorage();
|
||||||
WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid());
|
WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid());
|
||||||
Assert.assertNotNull(wxMpUserBlacklistGetResult);
|
Assert.assertNotNull(wxMpUserBlacklistGetResult);
|
||||||
@ -33,7 +34,7 @@ public class WxMpUserBlacklistServiceImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPushToBlacklist() throws Exception {
|
public void testPushToBlacklist() throws Exception {
|
||||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
|
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
|
||||||
.getWxMpConfigStorage();
|
.getWxMpConfigStorage();
|
||||||
List<String> openidList = new ArrayList<>();
|
List<String> openidList = new ArrayList<>();
|
||||||
openidList.add(configStorage.getOpenid());
|
openidList.add(configStorage.getOpenid());
|
||||||
@ -42,7 +43,7 @@ public class WxMpUserBlacklistServiceImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPullFromBlacklist() throws Exception {
|
public void testPullFromBlacklist() throws Exception {
|
||||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
|
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
|
||||||
.getWxMpConfigStorage();
|
.getWxMpConfigStorage();
|
||||||
List<String> openidList = new ArrayList<>();
|
List<String> openidList = new ArrayList<>();
|
||||||
openidList.add(configStorage.getOpenid());
|
openidList.add(configStorage.getOpenid());
|
||||||
|
@ -8,6 +8,7 @@ import com.google.inject.Inject;
|
|||||||
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
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.WxMpUser;
|
||||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||||
|
|
||||||
@ -25,12 +26,12 @@ public class WxMpUserServiceImplTest {
|
|||||||
protected WxMpServiceImpl wxService;
|
protected WxMpServiceImpl wxService;
|
||||||
|
|
||||||
public void testUserUpdateRemark() throws WxErrorException {
|
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(), "测试备注名");
|
this.wxService.getUserService().userUpdateRemark(configProvider.getOpenid(), "测试备注名");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUserInfo() throws WxErrorException {
|
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);
|
WxMpUser user = this.wxService.getUserService().userInfo(configProvider.getOpenid(), null);
|
||||||
Assert.assertNotNull(user);
|
Assert.assertNotNull(user);
|
||||||
System.out.println(user);
|
System.out.println(user);
|
||||||
|
@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
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.WxTagListUser;
|
||||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
@ -63,7 +64,7 @@ public class WxMpUserTagServiceImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchUntagging() throws Exception {
|
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);
|
boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assert.assertTrue(res);
|
Assert.assertTrue(res);
|
||||||
@ -72,7 +73,7 @@ public class WxMpUserTagServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUserTagList() throws Exception {
|
public void testUserTagList() throws Exception {
|
||||||
List<Integer> res = this.wxService.getUserTagService().userTagList(
|
List<Integer> res = this.wxService.getUserTagService().userTagList(
|
||||||
((ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
|
((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assert.assertNotNull(res);
|
Assert.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<accessToken>可以不填写</accessToken>
|
<accessToken>可以不填写</accessToken>
|
||||||
<expiresTime>可以不填写</expiresTime>
|
<expiresTime>可以不填写</expiresTime>
|
||||||
<openid>某个加你公众号的用户的openId</openid>
|
<openid>某个加你公众号的用户的openId</openid>
|
||||||
|
<templateId>模版消息的模版ID</templateId>
|
||||||
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
|
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
|
||||||
<qrconnectRedirectUrl>网页应用授权登陆回调地址</qrconnectRedirectUrl>
|
<qrconnectRedirectUrl>网页应用授权登陆回调地址</qrconnectRedirectUrl>
|
||||||
<kfAccount>完整客服账号,格式为:账号前缀@公众号微信号</kfAccount>
|
<kfAccount>完整客服账号,格式为:账号前缀@公众号微信号</kfAccount>
|
||||||
|
Loading…
Reference in New Issue
Block a user