回复数据格式如下:
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[video]]></MsgType>
<Video>
<MediaId><![CDATA[media_id]]></MediaId>
<Title><![CDATA[title]]></Title>
<Description><![CDATA[description]]></Description>
</Video>
</xml>
节点Video依然要注意首字母大写。这里相比图片和语音多了两个字段,词义也很明确,Title就是标题,Description就是写一些描述说明。MediaId依然是按照微信公众号开发(四)——点击菜单回复图片和语音的方式,提交到微信服务端。
创建“视频菜单”。参照《创建菜单》
{
"type":"click",
"name":"视频",
"key":"mh003"
}
步骤都是和之前一样,先修改WXMessgeBean文件:
package com.myweb.demo.bean;
import javax.xml.bind.annotation.*;
@XmlRootElement(name="xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class WXMessgeBean {
......
private VideoMessage Video;
......
public VideoMessage getVideo() {
return Video;
}
public void setVideo(VideoMessage video) {
Video = video;
}
//增加视频数据Bean
public static class VideoMessage{
private String mediaId;
private String title;
private String description;
public String getMediaId() {
return mediaId;
}
@XmlElement(name = "MediaId")
public void setMediaId(String mediaId) {
this.mediaId = mediaId;
}
public String getTitle() {
return title;
}
@XmlElement(name = "Title")
public void setTitle(String title) {
this.title = title;
}
@XmlElement(name = "Description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
}
我们来看回复代码,只看视频数据组装这块。
else if (wxMessgeBean.getEventKey().equals("mh003")){
bean.setMsgType("video");
bean.setVideo(new WXMessgeBean.VideoMessage());
bean.getVideo().setTitle("篝火晚会");
bean.getVideo().setDescription("塞罕坝林场夜晚篝火晚会");
bean.getVideo().setMediaId("CbwFYY0j7khQxHnaBToXHhOPapSG-tuPZ6asO4O_4fHbnnZIbPth2gs_bR4S3U92");
}
效果如图: