#425 小程序客服消息新增图文链接消息支持
This commit is contained in:
@@ -7,16 +7,14 @@ import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||
import cn.binarywang.wx.miniapp.test.TestConfig;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 测试客服相关接口
|
||||
* 测试消息相关接口
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@@ -25,26 +23,14 @@ import java.util.Date;
|
||||
public class WxMaMsgServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMaService wxService;
|
||||
|
||||
public void testSendKefuMpNewsMessage() throws WxErrorException {
|
||||
TestConfig configStorage = (TestConfig) this.wxService
|
||||
.getWxMaConfig();
|
||||
WxMaKefuMessage message = new WxMaKefuMessage();
|
||||
message.setMsgType(WxConsts.KefuMsgType.MPNEWS);
|
||||
message.setToUser(configStorage.getOpenid());
|
||||
|
||||
this.wxService.getMsgService().sendKefuMsg(message);
|
||||
}
|
||||
private WxMaService wxService;
|
||||
|
||||
public void testSendKefuMessage() throws WxErrorException {
|
||||
TestConfig config = (TestConfig) this.wxService
|
||||
.getWxMaConfig();
|
||||
WxMaKefuMessage message = new WxMaKefuMessage();
|
||||
message.setMsgType(WxConsts.KefuMsgType.TEXT);
|
||||
message.setToUser(config.getOpenid());
|
||||
message.setContent(
|
||||
"欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||
TestConfig config = (TestConfig) this.wxService.getWxMaConfig();
|
||||
WxMaKefuMessage message = WxMaKefuMessage.newTextBuilder()
|
||||
.toUser(config.getOpenid())
|
||||
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
|
||||
.build();
|
||||
|
||||
this.wxService.getMsgService().sendKefuMsg(message);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.binarywang.wx.miniapp.bean;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
@@ -10,30 +10,35 @@ import org.testng.annotations.Test;
|
||||
@Test
|
||||
public class WxMaKefuMessageTest {
|
||||
|
||||
public void testTextReply() {
|
||||
WxMaKefuMessage reply = new WxMaKefuMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.KefuMsgType.TEXT);
|
||||
reply.setContent("sfsfdsdf");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
||||
public void testTextBuilder() {
|
||||
WxMaKefuMessage reply = WxMaKefuMessage.newTextBuilder()
|
||||
.toUser("OPENID")
|
||||
.content("sfsfdsdf")
|
||||
.build();
|
||||
assertThat(reply.toJson())
|
||||
.isEqualTo("{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
||||
}
|
||||
|
||||
public void testTextBuild() {
|
||||
WxMaKefuMessage reply = WxMaKefuMessage.newTextBuilder().toUser("OPENID").content("sfsfdsdf").build();
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
||||
public void testImageBuilder() {
|
||||
WxMaKefuMessage reply = WxMaKefuMessage.newImageBuilder()
|
||||
.toUser("OPENID")
|
||||
. mediaId("MEDIA_ID")
|
||||
.build();
|
||||
assertThat(reply.toJson())
|
||||
.isEqualTo( "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
|
||||
public void testImageReply() {
|
||||
WxMaKefuMessage reply = new WxMaKefuMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.KefuMsgType.IMAGE);
|
||||
reply.setMediaId("MEDIA_ID");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
|
||||
public void testImageBuild() {
|
||||
WxMaKefuMessage reply = WxMaKefuMessage.newImageBuilder().toUser("OPENID").mediaId("MEDIA_ID").build();
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
public void testLinkBuilder() {
|
||||
WxMaKefuMessage reply = WxMaKefuMessage.newLinkBuilder()
|
||||
.toUser("OPENID")
|
||||
.url("url")
|
||||
.description("description")
|
||||
.title("title")
|
||||
.thumbUrl("thumbUrl")
|
||||
.build();
|
||||
assertThat(reply.toJson())
|
||||
.isEqualTo( "{\"touser\":\"OPENID\",\"msgtype\":\"image\"," +
|
||||
"\"link\":{\"title\":\"title\",\"description\":\"description\",\"url\":\"url\",\"thumb_url\":\"thumbUrl\"}}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user