1
0
mirror of synced 2025-12-21 08:30:11 +08:00

#425 小程序客服消息新增图文链接消息支持

This commit is contained in:
Binary Wang
2018-01-27 17:58:39 +08:00
parent b44f9b315f
commit a687d00d4a
11 changed files with 185 additions and 107 deletions

View File

@@ -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);
}

View File

@@ -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\"}}");
}