🎨 #2477 【小程序】增加订阅消息通知事件的相关属性支持
This commit is contained in:
@@ -4,6 +4,7 @@ import me.chanjar.weixin.common.api.WxConsts;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
@@ -47,4 +48,182 @@ public class WxMaMessageTest {
|
||||
assertEquals(wxMessage.getSessionFrom(), "sessionFrom");
|
||||
}
|
||||
|
||||
public void testSubscribeMsgPopupEvent() {
|
||||
// xml 格式
|
||||
String xml = "<xml>" +
|
||||
"<ToUserName><![CDATA[gh_123456789abc]]></ToUserName>\n" +
|
||||
"<FromUserName><![CDATA[otFpruAK8D-E6EfStSYonYSBZ8_4]]></FromUserName>\n" +
|
||||
"<CreateTime>1610969440</CreateTime>\n" +
|
||||
"<MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
"<Event><![CDATA[subscribe_msg_popup_event]]></Event>\n" +
|
||||
"<SubscribeMsgPopupEvent>\n" +
|
||||
" <List>\n" +
|
||||
" <TemplateId><![CDATA[VRR0UEO9VJOLs0MHlU0OilqX6MVFDwH3_3gz3Oc0NIc]]></TemplateId>\n" +
|
||||
" <SubscribeStatusString><![CDATA[accept]]></SubscribeStatusString>\n" +
|
||||
" <PopupScene>0</PopupScene>\n" +
|
||||
" </List>\n" +
|
||||
"</SubscribeMsgPopupEvent>" +
|
||||
"</xml>";
|
||||
|
||||
WxMaMessage wxMessage = WxMaMessage.fromXml(xml);
|
||||
checkSubscribeMsgPopupEvent(wxMessage);
|
||||
|
||||
// 订阅单个模板 json格式 (对象)
|
||||
String json = "{\n" +
|
||||
" \"ToUserName\": \"gh_123456789abc\",\n" +
|
||||
" \"FromUserName\": \"otFpruAK8D-E6EfStSYonYSBZ8_4\",\n" +
|
||||
" \"CreateTime\": \"1610969440\",\n" +
|
||||
" \"MsgType\": \"event\",\n" +
|
||||
" \"Event\": \"subscribe_msg_popup_event\",\n" +
|
||||
" \"List\": {\n" +
|
||||
" \"TemplateId\": \"VRR0UEO9VJOLs0MHlU0OilqX6MVFDwH3_3gz3Oc0NIc\",\n" +
|
||||
" \"SubscribeStatusString\": \"accept\",\n" +
|
||||
" \"PopupScene\": \"0\"\n" +
|
||||
" }\n" +
|
||||
" }";
|
||||
wxMessage = WxMaMessage.fromJson(json);
|
||||
checkSubscribeMsgPopupEvent(wxMessage);
|
||||
// 订阅多条模板的 json格式(数组)
|
||||
json = "{\n" +
|
||||
" \"ToUserName\": \"gh_123456789abc\",\n" +
|
||||
" \"FromUserName\": \"otFpruAK8D-E6EfStSYonYSBZ8_4\",\n" +
|
||||
" \"CreateTime\": \"1610969440\",\n" +
|
||||
" \"MsgType\": \"event\",\n" +
|
||||
" \"Event\": \"subscribe_msg_popup_event\",\n" +
|
||||
" \"List\": [{\n" +
|
||||
" \"TemplateId\": \"VRR0UEO9VJOLs0MHlU0OilqX6MVFDwH3_3gz3Oc0NIc\",\n" +
|
||||
" \"SubscribeStatusString\": \"accept\",\n" +
|
||||
" \"PopupScene\": \"0\"\n" +
|
||||
" }]\n" +
|
||||
" }";
|
||||
wxMessage = WxMaMessage.fromJson(json);
|
||||
checkSubscribeMsgPopupEvent(wxMessage);
|
||||
}
|
||||
|
||||
private void checkSubscribeMsgPopupEvent(WxMaMessage wxMessage) {
|
||||
assertEquals(wxMessage.getToUser(), "gh_123456789abc");
|
||||
assertEquals(wxMessage.getFromUser(), "otFpruAK8D-E6EfStSYonYSBZ8_4");
|
||||
assertEquals(wxMessage.getCreateTime(),new Integer(1610969440));
|
||||
assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.EVENT);
|
||||
assertEquals(wxMessage.getEvent(), "subscribe_msg_popup_event");
|
||||
assertEquals(wxMessage.getSubscribeMsgPopupEvent().getList().size(), 1);
|
||||
WxMaSubscribeMsgEvent.PopupEvent event = wxMessage.getSubscribeMsgPopupEvent().getList().get(0);
|
||||
assertEquals(event.getTemplateId(), "VRR0UEO9VJOLs0MHlU0OilqX6MVFDwH3_3gz3Oc0NIc");
|
||||
assertEquals(event.getSubscribeStatusString(),"accept");
|
||||
assertEquals(event.getPopupScene(), "0");
|
||||
}
|
||||
|
||||
public void testSubscribeMsgChangeEvent() {
|
||||
// xml 格式
|
||||
String xml = "<xml>\n" +
|
||||
" <ToUserName><![CDATA[gh_123456789abc]]></ToUserName>\n" +
|
||||
" <FromUserName><![CDATA[o7esq5OI1Uej6Xixw1lA2H7XDVbc]]></FromUserName>\n" +
|
||||
" <CreateTime>1610968440</CreateTime>\n" +
|
||||
" <MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
" <Event><![CDATA[subscribe_msg_change_event]]></Event>\n" +
|
||||
" <SubscribeMsgChangeEvent>\n" +
|
||||
" <List>" +
|
||||
" <TemplateId><![CDATA[BEwX0BOT3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8]]></TemplateId>\n" +
|
||||
" <SubscribeStatusString><![CDATA[reject]]></SubscribeStatusString>\n" +
|
||||
" </List>\n" +
|
||||
" </SubscribeMsgChangeEvent>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxMaMessage wxMessage = WxMaMessage.fromXml(xml);
|
||||
checkSubscribeMsgChangeEvent(wxMessage);
|
||||
|
||||
// json格式 (对象)
|
||||
String json = "{\n" +
|
||||
" \"ToUserName\": \"gh_123456789abc\",\n" +
|
||||
" \"FromUserName\": \"o7esq5OI1Uej6Xixw1lA2H7XDVbc\",\n" +
|
||||
" \"CreateTime\": \"1610968440\",\n" +
|
||||
" \"MsgType\": \"event\",\n" +
|
||||
" \"Event\": \"subscribe_msg_change_event\",\n" +
|
||||
" \"List\": {\n" +
|
||||
" \"TemplateId\":\"BEwX0BOT3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8\",\n" +
|
||||
" \"SubscribeStatusString\": \"reject\"\n" +
|
||||
" }\n" +
|
||||
"}\n";
|
||||
wxMessage = WxMaMessage.fromJson(json);
|
||||
checkSubscribeMsgChangeEvent(wxMessage);
|
||||
// json格式(数组)
|
||||
json = "{\n" +
|
||||
" \"ToUserName\": \"gh_123456789abc\",\n" +
|
||||
" \"FromUserName\": \"o7esq5OI1Uej6Xixw1lA2H7XDVbc\",\n" +
|
||||
" \"CreateTime\": \"1610968440\",\n" +
|
||||
" \"MsgType\": \"event\",\n" +
|
||||
" \"Event\": \"subscribe_msg_change_event\",\n" +
|
||||
" \"List\": [ {\n" +
|
||||
" \"TemplateId\":\"BEwX0BOT3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8\",\n" +
|
||||
" \"SubscribeStatusString\": \"reject\"\n" +
|
||||
" }]" +
|
||||
"}";
|
||||
wxMessage = WxMaMessage.fromJson(json);
|
||||
checkSubscribeMsgChangeEvent(wxMessage);
|
||||
}
|
||||
|
||||
private void checkSubscribeMsgChangeEvent(WxMaMessage wxMessage) {
|
||||
assertEquals(wxMessage.getToUser(), "gh_123456789abc");
|
||||
assertEquals(wxMessage.getFromUser(), "o7esq5OI1Uej6Xixw1lA2H7XDVbc");
|
||||
assertEquals(wxMessage.getCreateTime(),new Integer(1610968440));
|
||||
assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.EVENT);
|
||||
assertEquals(wxMessage.getEvent(), "subscribe_msg_change_event");
|
||||
assertEquals(wxMessage.getSubscribeMsgChangeEvent().getList().size(), 1);
|
||||
WxMaSubscribeMsgEvent.ChangeEvent event = wxMessage.getSubscribeMsgChangeEvent().getList().get(0);
|
||||
assertEquals(event.getTemplateId(), "BEwX0BOT3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8");
|
||||
assertEquals(event.getSubscribeStatusString(),"reject");
|
||||
}
|
||||
|
||||
public void testSubscribeMsgSentEvent() {
|
||||
// xml 格式
|
||||
String xml = "<xml>\n" +
|
||||
" <ToUserName><![CDATA[gh_123456789abc]]></ToUserName>\n" +
|
||||
" <FromUserName><![CDATA[o7esq5PHRGBQYmeNyfG064wEFVpQ]]></FromUserName>\n" +
|
||||
" <CreateTime>1620963428</CreateTime>\n" +
|
||||
" <MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
" <Event><![CDATA[subscribe_msg_sent_event]]></Event>\n" +
|
||||
" <SubscribeMsgSentEvent>\n" +
|
||||
" <List>" +
|
||||
" <TemplateId><![CDATA[BEwX0BO-T3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8]]></TemplateId>\n" +
|
||||
" <MsgID>1864323726461255680</MsgID>\n" +
|
||||
" <ErrorCode>0</ErrorCode>\n" +
|
||||
" <ErrorStatus><![CDATA[success]]></ErrorStatus>\n" +
|
||||
" </List>\n" +
|
||||
" </SubscribeMsgSentEvent>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxMaMessage wxMessage = WxMaMessage.fromXml(xml);
|
||||
checkSubscribeMsgSentEvent(wxMessage);
|
||||
|
||||
// json格式 (对象)
|
||||
String json = "{\n" +
|
||||
" \"ToUserName\": \"gh_123456789abc\",\n" +
|
||||
" \"FromUserName\": \"o7esq5PHRGBQYmeNyfG064wEFVpQ\",\n" +
|
||||
" \"CreateTime\": \"1620963428\",\n" +
|
||||
" \"MsgType\": \"event\",\n" +
|
||||
" \"Event\": \"subscribe_msg_sent_event\",\n" +
|
||||
" \"List\": {\n" +
|
||||
" \"TemplateId\": \"BEwX0BO-T3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8\",\n" +
|
||||
" \"MsgID\": \"1864323726461255680\",\n" +
|
||||
" \"ErrorCode\": \"0\",\n" +
|
||||
" \"ErrorStatus\": \"success\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
wxMessage = WxMaMessage.fromJson(json);
|
||||
checkSubscribeMsgSentEvent(wxMessage);
|
||||
}
|
||||
private void checkSubscribeMsgSentEvent(WxMaMessage wxMessage) {
|
||||
assertEquals(wxMessage.getToUser(), "gh_123456789abc");
|
||||
assertEquals(wxMessage.getFromUser(), "o7esq5PHRGBQYmeNyfG064wEFVpQ");
|
||||
assertEquals(wxMessage.getCreateTime(),new Integer(1620963428));
|
||||
assertEquals(wxMessage.getMsgType(), WxConsts.XmlMsgType.EVENT);
|
||||
assertEquals(wxMessage.getEvent(), "subscribe_msg_sent_event");
|
||||
assertNotNull(wxMessage.getSubscribeMsgSentEvent());
|
||||
WxMaSubscribeMsgEvent.SentEvent event = wxMessage.getSubscribeMsgSentEvent().getList();
|
||||
assertEquals(event.getTemplateId(), "BEwX0BO-T3MqK3Uc5oTU3CGBqzjpndk2jzUf7VfExd8");
|
||||
assertEquals(event.getMsgId(),"1864323726461255680");
|
||||
assertEquals(event.getErrorCode(),"0");
|
||||
assertEquals(event.getErrorStatus(),"success");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user