package com.jfinal.weixin.sdk.msg;
import org.junit.Assert;
import org.junit.Test;
import com.jfinal.weixin.sdk.msg.in.InImageMsg;
import com.jfinal.weixin.sdk.msg.in.InLinkMsg;
import com.jfinal.weixin.sdk.msg.in.InLocationMsg;
import com.jfinal.weixin.sdk.msg.in.InMsg;
import com.jfinal.weixin.sdk.msg.in.InNotDefinedMsg;
import com.jfinal.weixin.sdk.msg.in.InShortVideoMsg;
import com.jfinal.weixin.sdk.msg.in.InTextMsg;
import com.jfinal.weixin.sdk.msg.in.InVideoMsg;
import com.jfinal.weixin.sdk.msg.in.InVoiceMsg;
import com.jfinal.weixin.sdk.msg.in.card.InMerChantOrderEvent;
import com.jfinal.weixin.sdk.msg.in.card.InUpdateMemberCardEvent;
import com.jfinal.weixin.sdk.msg.in.card.InUserCardEvent;
import com.jfinal.weixin.sdk.msg.in.card.InUserPayFromCardEvent;
import com.jfinal.weixin.sdk.msg.in.event.InMenuEvent;
import com.jfinal.weixin.sdk.msg.in.event.InNotDefinedEvent;
import com.jfinal.weixin.sdk.msg.in.event.InShakearoundUserShakeEvent;
import com.jfinal.weixin.sdk.msg.in.event.ScanCodeInfo;
import com.jfinal.weixin.sdk.msg.in.speech_recognition.InSpeechRecognitionResults;
public class XMLMsgTest {
/**
* 菜单事件
*/
@Test
public void test001() {
String xml = ""
+ ""
+ ""
+ "1446526359"
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InMenuEvent);
InMenuEvent inMenuEvent = (InMenuEvent) inMsg;
ScanCodeInfo scanCodeInfo = inMenuEvent.getScanCodeInfo();
String scanType = scanCodeInfo.getScanType();
String scanResult = scanCodeInfo.getScanResult();
Assert.assertEquals(scanType, "qrcode");
Assert.assertEquals(scanResult, "http://www.jfinal.com");
}
/**
* 普通文本
*/
@Test
public void test002() {
String xml = ""
+ ""
+ ""
+ "1450496618"
+ ""
+ ""
+ "6229835537670016495"
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InTextMsg);
}
/**
* 地理位置
*/
@Test
public void test003() {
String xml = ""
+ ""
+ ""
+ "1450496950"
+ ""
+ "39.845194"
+ "116.314440"
+ "15"
+ ""
+ "6229836963599158839"
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InLocationMsg);
}
/**
* 小视屏
*/
@Test
public void test004() {
String xml = ""
+ ""
+ ""
+ "1450497127"
+ ""
+ ""
+ ""
+ "6229837723808370244"
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InShortVideoMsg);
}
/**
* 连接
*/
@Test
public void test005() {
String xml = ""
+ ""
+ ""
+ "1450497332"
+ ""
+ ""
+ ""
+ ""
+ "6229838604276665948"
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InLinkMsg);
}
/**
* 照片
*/
@Test
public void test006() {
String xml = ""
+ ""
+ ""
+ "1450497590"
+ ""
+ ""
+ "6229839712378228337"
+ ""
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InImageMsg);
}
/**
* 视频
*/
@Test
public void test007() {
String xml = ""
+ ""
+ ""
+ "1450497793"
+ ""
+ ""
+ ""
+ "6229840584256589452"
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InVideoMsg);
}
/**
* 语音
*/
@Test
public void test008() {
String xml = ""
+ ""
+ ""
+ "1450497977"
+ ""
+ ""
+ ""
+ "6229841374129160192"
+ ""
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InVoiceMsg);
Assert.assertTrue(inMsg instanceof InSpeechRecognitionResults);
}
/**
* 周边摇一摇
*/
@Test
public void test009() {
String xml = ""
+ ""
+ ""
+ "1433332012"
+ ""
+ ""
+ ""
+ ""
+ "1002"
+ "1223"
+ "0.057"
+ ""
+ ""
+ ""
+ ""
+ "1002"
+ "1223"
+ "166.816"
+ ""
+ ""
+ ""
+ "1002"
+ "1223"
+ "15.013"
+ ""
+ ""
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InShakearoundUserShakeEvent);
}
/**
* 微信会员卡二维码扫描领取接口
*/
@Test
public void test010() {
String xml = "" +
"" +
"" +
"1462420243" +
"" +
"" +
"" +
"" +
"";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InUserCardEvent);
}
/**
* 微信会员卡二维码扫描领取接口
*/
@Test
public void test011() {
String xml = " \n" +
"\n" +
"1462420171\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InUserCardEvent);
}
/**
* 微信会员卡二维码扫描领取接口
*/
@Test
public void test012() {
String xml = "\n" +
"\n" +
"\n" +
"1462420730\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"1000\n" +
"0\n" +
"";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InUpdateMemberCardEvent);
}
/**
* 微信会员卡二维码扫描领取接口
*/
@Test
public void test013() {
String xml = "\n" +
"\n" +
"\n" +
"1462420332\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"403808221\n" +
"100\n" +
"100\n" +
"";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InUserPayFromCardEvent);
}
// 微信小店订单支付成功接口消息
@Test
public void test014() {
String xml = "\n" +
"\n" +
"\n" +
"1463387703\n" +
"\n" +
"\n" +
"\n" +
"2\n" +
"\n" +
"\n" +
"\n";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InMerChantOrderEvent);
}
// 不存在的事件类型测试
@Test
public void test015() {
String xml = "\n" +
"\n" +
"\n" +
"1463387703\n" +
"\n" +
"\n" +
"\n" +
"2\n" +
"\n" +
"\n" +
"\n";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InNotDefinedEvent);
}
// 不存在的消息类型测试
@Test
public void test016() {
String xml = ""
+ ""
+ ""
+ "1450496618"
+ ""
+ ""
+ "6229835537670016495"
+ "";
InMsg inMsg = InMsgParser.parse(xml);
Assert.assertTrue(inMsg instanceof InNotDefinedMsg);
}
}