文档章节

微信公众平台深度开发JAVA版第一季 16.响应被动消息4

blueheart
 blueheart
发布于 2017/05/15 14:05
字数 2042
阅读 4
收藏 0

回复视频消息不成功,不知道为什么.是因为视频上传不成功吗?

package wx.out;

import java.util.Date;
import java.util.List;

import wx.in.In;

public class Out_News {
	private String ToUserName = null;//	是	接收方帐号(收到的OpenID)
	private String FromUserName =null;//	是	开发者微信号
	private String CreateTime = null;//	是	消息创建时间 (整型)
	private String MsgType = null;//	是	news
	private String ArticleCount = null;//	是	图文消息个数,限制为8条以内
	private String Articles = null;//	是	多条图文消息信息,默认第一个item为大图,注意,如果图文数超过8,则将会无响应
	private String Title = null;//	是	图文消息标题
	private String Description = null;//	是	图文消息描述
	private String PicUrl = null;//	是	图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
	private String Url = null;//	是	点击图文消息跳转链接
	public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}
	public String getArticleCount() {
		return ArticleCount;
	}
	public void setArticleCount(String articleCount) {
		ArticleCount = articleCount;
	}
	public String getArticles() {
		return Articles;
	}
	public void setArticles(String articles) {
		Articles = articles;
	}
	public String getTitle() {
		return Title;
	}
	public void setTitle(String title) {
		Title = title;
	}
	public String getDescription() {
		return Description;
	}
	public void setDescription(String description) {
		Description = description;
	}
	public String getPicUrl() {
		return PicUrl;
	}
	public void setPicUrl(String picUrl) {
		PicUrl = picUrl;
	}
	public String getUrl() {
		return Url;
	}
	public void setUrl(String url) {
		Url = url;
	}
	public Out_News() {
		super();
	}
	StringBuffer strb = new StringBuffer();
	StringBuffer strb_ = new StringBuffer();
	public Out_News(In in) {
	//public Out_Text(In in,String str) {
		super();
		// TODO Auto-generated constructor stub
		Date date = new Date();

		strb.append("             <ToUserName><![CDATA["+in.getFromUserName()+"]]></ToUserName>                   ");
		strb.append("         <FromUserName><![CDATA["+in.getToUserName()+"]]></FromUserName>                       ");
		strb.append("         <CreateTime>"+date.getTime()+"</CreateTime>                       ");
		strb.append("          <MsgType><![CDATA[news]]></MsgType>   ");
	    //this.setContent(str);
	}

	//public String getStr(String str){
	public String getStr(List<Out_News> out_News){

		strb_.append("           <xml>                     ");    
		strb_.append(strb);
		strb_.append("            		<ArticleCount>"+out_News.size()+"</ArticleCount>                   ");
		strb_.append("		<Articles>");
		for(int x=0;x<out_News.size();x++){
			strb_.append("	<item>");
			strb_.append("<Title><![CDATA["+out_News.get(x).getTitle()+"]]></Title> ");
			strb_.append("<Description><![CDATA["+out_News.get(x).getDescription()+"]]></Description>");
			strb_.append("<PicUrl><![CDATA["+out_News.get(x).getPicUrl()+"]]></PicUrl>");
			strb_.append("<Url><![CDATA["+out_News.get(x).getUrl()+"]]></Url>");
			strb_.append("</item>");
		}
		strb_.append("		</Articles>");
		strb_.append("            </xml>                    ");		
		return strb_.toString();		
	}	
}
package wx.out;

import java.util.Date;

import wx.in.In;

public class Out_Music {
	private String ToUserName = null;//	是	接收方帐号(收到的OpenID)
	private String FromUserName = null;//	是	开发者微信号
	private String CreateTime = null;//	是	消息创建时间 (整型)
	private String MsgType =null;//	是	music
	private String Title = null;//	否	音乐标题
	private String Description = null;//	否	音乐描述
	private String MusicURL = null;//	否	音乐链接
	private String HQMusicUrl = null;//	否	高质量音乐链接,WIFI环境优先使用该链接播放音乐
	private String ThumbMediaId = null;//	是	缩略图的媒体id,通过素材管理中的接口上传多媒体文件,得到的id
	StringBuffer strb = new StringBuffer();
	StringBuffer strb_ = new StringBuffer();
	
	public Out_Music(In in) {
		super();
		Date date = new Date();

		strb.append("             <ToUserName><![CDATA["+in.getFromUserName()+"]]></ToUserName>                   ");
		strb.append("         <FromUserName><![CDATA["+in.getToUserName()+"]]></FromUserName>                       ");
		strb.append("         <CreateTime>"+date.getTime()+"</CreateTime>                       ");
		strb.append("          <MsgType><![CDATA[music]]></MsgType>   ");
	}
	//public String getStr(String str){
	public String getStr(){

		strb_.append("           <xml>                     ");    
		strb_.append(strb);
		strb_.append("           <Music>                   ");
		strb_.append("         <Title><![CDATA["+this.getTitle()+"]]></Title>                  ");
		strb_.append("         <Description><![CDATA["+this.getDescription()+"]]></Description>                  ");
		strb_.append("         <MusicUrl><![CDATA["+this.getMusicURL()+"]]></MusicUrl>                  ");
		strb_.append("         <HQMusicUrl><![CDATA["+this.getHQMusicUrl()+"]]></HQMusicUrl>                  ");
		strb_.append("         <ThumbMediaId><![CDATA["+this.getThumbMediaId()+"]]></ThumbMediaId>                  ");
	
		strb_.append("         </Music>                 ");
		strb_.append("         </xml>                 ");
		return strb_.toString();

		
	}
	public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}
	public String getTitle() {
		return Title;
	}
	public void setTitle(String title) {
		Title = title;
	}
	public String getDescription() {
		return Description;
	}
	public void setDescription(String description) {
		Description = description;
	}
	public String getMusicURL() {
		return MusicURL;
	}
	public void setMusicURL(String musicURL) {
		MusicURL = musicURL;
	}
	public String getHQMusicUrl() {
		return HQMusicUrl;
	}
	public void setHQMusicUrl(String hQMusicUrl) {
		HQMusicUrl = hQMusicUrl;
	}
	public String getThumbMediaId() {
		return ThumbMediaId;
	}
	public void setThumbMediaId(String thumbMediaId) {
		ThumbMediaId = thumbMediaId;
	}

}
package wx.out;

import java.util.Date;

import wx.in.In;

public class Out_Video {
	private String ToUserName = null;//	是	接收方帐号(收到的OpenID)
	private String FromUserName =null;//	是	开发者微信号
	private String CreateTime = null;//	是	消息创建时间 (整型)
	private String MsgType =null;//	是	video
	private String MediaId	 = null;//是	通过素材管理中的接口上传多媒体文件,得到的id
	private String Title =null;//	否	视频消息的标题
	private String Description =null;//	否	视频消息的描述
	StringBuffer strb = new StringBuffer();
	StringBuffer strb_ = new StringBuffer();
	
	public Out_Video(In in) {
		super();
		Date date = new Date();
		strb.append("<ToUserName><![CDATA["+in.getFromUserName()+"]]></ToUserName>");
		strb.append("<FromUserName><![CDATA["+in.getToUserName()+"]]></FromUserName>");
		strb.append("<CreateTime>"+date.getTime()+"</CreateTime>");
		strb.append("<MsgType><![CDATA[video]]></MsgType>");
	}
	//public String getStr(String str){
	public String getStr(){

        strb_.append("<xml>");
		strb_.append(strb);
		strb_.append("<Video>");
		strb_.append("<MediaId><![CDATA["+this.getMediaId()+"]]></MediaId>");
		strb_.append("<Title><![CDATA["+this.getTitle()+"]]></Title>");
		strb_.append("<Description><![CDATA["+this.getDescription()+"]]></Description>");
		strb_.append("</Video>");
		strb_.append("</xml>");
		return strb_.toString();

		
	}
	public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}
	public String getMediaId() {
		return MediaId;
	}
	public void setMediaId(String mediaId) {
		MediaId = mediaId;
	}
	public String getTitle() {
		return Title;
	}
	public void setTitle(String title) {
		Title = title;
	}
	public String getDescription() {
		return Description;
	}
	public void setDescription(String description) {
		Description = description;
	}

}
<!--  
<xml>
	<ToUserName><![CDATA[gh_44e4d096da50]]></ToUserName>
	<FromUserName><![CDATA[o2d2nwwoWhw1P2VDWiQHj1brqSc4]]></FromUserName>
	<CreateTime>1495110418</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[beifengwang]]></Content>
	<MsgId>6421450349635041495</MsgId>
</xml>
<xml>
	<ToUserName><![CDATA[gh_44e4d096da50]]></ToUserName>
	<FromUserName><![CDATA[o2d2nwwoWhw1P2VDWiQHj1brqSc4]]></FromUserName>
	<CreateTime>1495011380</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[1]]></Content>
	<MsgId>6421024984663956534</MsgId>
</xml>
<xml>
	<ToUserName><![CDATA[gh_44e4d096da50]]></ToUserName>
	<FromUserName><![CDATA[o2d2nwwoWhw1P2VDWiQHj1brqSc4]]></FromUserName>
	<CreateTime>1495011574</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[2]]></Content>
	<MsgId>6421025817887612034</MsgId>
</xml>
<xml>
	<ToUserName><![CDATA[gh_44e4d096da50]]></ToUserName>
	<FromUserName><![CDATA[o2d2nwwoWhw1P2VDWiQHj1brqSc4]]></FromUserName>
	<CreateTime>1495014482</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[北风网]]></Content>
	<MsgId>6421038307652509766</MsgId>
</xml>
<xml>
	<ToUserName><![CDATA[gh_44e4d096da50]]></ToUserName>
	<FromUserName><![CDATA[o2d2nwwoWhw1P2VDWiQHj1brqSc4]]></FromUserName>
	<CreateTime>1495029086</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[ 00000000000000000]]></Content>
	<MsgId>6421101031354906377</MsgId>
</xml>

<xml>
	<ToUserName><![CDATA[o2d2nwwoWhw1P2VDWiQHj1brqSc4]]></ToUserName>
	<FromUserName><![CDATA[gh_44e4d096da50]]></FromUserName>
	<CreateTime>1495266614798</CreateTime>
	<MsgType><![CDATA[news]]></MsgType>
	<ArticleCount>4</ArticleCount>
	<Articles>
		<item>
			<Title><![CDATA[null]]></Title>
			<Description><![CDATA[null]]></Description>
			<PicUrl><![CDATA[null]]></PicUrl>
			<Url><![CDATA[null]]></Url>
		</item>
		<item>
			<Title><![CDATA[null]]></Title>
			<Description><![CDATA[null]]></Description>
			<PicUrl><![CDATA[null]]></PicUrl>
			<Url><![CDATA[null]]></Url>
		</item>
		<item>
			<Title><![CDATA[null]]></Title>
			<Description><![CDATA[null]]></Description>
			<PicUrl><![CDATA[null]]></PicUrl>
			<Url><![CDATA[null]]></Url>
		</item>
		<item>
			<Title><![CDATA[null]]></Title>
			<Description><![CDATA[null]]></Description>
			<PicUrl><![CDATA[null]]></PicUrl>
			<Url><![CDATA[null]]></Url>
		</item>
	</Articles>
</xml>
-->
<xml>
	<ToUserName><![CDATA[o2d2nwwoWhw1P2VDWiQHj1brqSc4]]></ToUserName>
	<FromUserName><![CDATA[gh_44e4d096da50]]></FromUserName>
	<CreateTime>1495266790355</CreateTime>
	<MsgType><![CDATA[news]]></MsgType>
	<ArticleCount>4</ArticleCount>
	<Articles>
		<item>
			<Title><![CDATA[title0]]></Title>
			<Description><![CDATA[description0]]></Description>
			<PicUrl><![CDATA[picUrl0]]></PicUrl>
			<Url><![CDATA[url0]]></Url>
		</item>
		<item>
			<Title><![CDATA[title1]]></Title>
			<Description><![CDATA[description1]]></Description>
			<PicUrl><![CDATA[picUrl1]]></PicUrl>
			<Url><![CDATA[url1]]></Url>
		</item>
		<item>
			<Title><![CDATA[title2]]></Title>
			<Description><![CDATA[description2]]></Description>
			<PicUrl><![CDATA[picUrl2]]></PicUrl>
			<Url><![CDATA[url2]]></Url>
		</item>
		<item>
			<Title><![CDATA[title3]]></Title>
			<Description><![CDATA[description3]]></Description>
			<PicUrl><![CDATA[picUrl3]]></PicUrl>
			<Url><![CDATA[url3]]></Url>
		</item>
	</Articles>
</xml>                          
package wx.out;

import java.util.Date;

import wx.in.In;

public class Out_Voice {
	private String ToUserName =null;//	是	接收方帐号(收到的OpenID)
	private String FromUserName	= null;//是	开发者微信号
	private String CreateTime = null;//	是	消息创建时间戳 (整型)
	private String MsgType = null;//	是	语音,voice
	private String MediaId = null;//	是	通过素材管理中的接口上传多媒体文件,得到的id
	StringBuffer strb = new StringBuffer();
	StringBuffer strb_ = new StringBuffer();
	
	public Out_Voice(In in) {
		super();
		Date date = new Date();

		strb.append("             <ToUserName><![CDATA["+in.getFromUserName()+"]]></ToUserName>                   ");
		strb.append("         <FromUserName><![CDATA["+in.getToUserName()+"]]></FromUserName>                       ");
		strb.append("         <CreateTime>"+date.getTime()+"</CreateTime>                       ");
		strb.append("          <MsgType><![CDATA[voice]]></MsgType>   ");
	}
	//public String getStr(String str){
	public String getStr(){

		strb_.append("           <xml>                     ");    
		strb_.append(strb);
		strb_.append("           <Voice>                   ");
		strb_.append("         <MediaId><![CDATA["+this.getMediaId()+"]]></MediaId>                  ");
	
		strb_.append("         </Voice>                 ");
		strb_.append("         </xml>                 ");
		return strb_.toString();

		
	}
	public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}
	public String getMediaId() {
		return MediaId;
	}
	public void setMediaId(String mediaId) {
		MediaId = mediaId;
	}

}
package wx.out;

import java.util.Date;

import wx.in.In;

public class Out_Image {
	private String ToUserName = null;//	是	接收方帐号(收到的OpenID)
	private String FromUserName = null;//	是	开发者微信号
	private String CreateTime =null;//	是	消息创建时间 (整型)
	private String MsgType  =null;//	是	image
	private String MediaId  =null;//	是	通过素材管理中的接口上传多媒体文件,得到的id。
	StringBuffer strb = new StringBuffer();
	StringBuffer strb_ = new StringBuffer();
	
	public Out_Image(In in) {
		super();
		Date date = new Date();

		strb.append("             <ToUserName><![CDATA["+in.getFromUserName()+"]]></ToUserName>                   ");
		strb.append("         <FromUserName><![CDATA["+in.getToUserName()+"]]></FromUserName>                       ");
		strb.append("         <CreateTime>"+date.getTime()+"</CreateTime>                       ");
		strb.append("          <MsgType><![CDATA[Image]]></MsgType>   ");
	}
	//public String getStr(String str){
	public String getStr(){

		strb_.append("           <xml>                     ");    
		strb_.append(strb);
		strb_.append("           <Image>                   ");
		strb_.append("         <MediaId><![CDATA["+this.getMediaId()+"]]></MediaId>                  ");
	
		strb_.append("         </Image>                 ");
		strb_.append("         </xml>                 ");
		return strb_.toString();

		
	}
	public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}
	public String getMediaId() {
		return MediaId;
	}
	public void setMediaId(String mediaId) {
		MediaId = mediaId;
	}
	
}
package wx.out;

import java.util.Date;

import wx.in.In;

public class Out_Text {
	private String ToUserName = null;//	是	接收方帐号(收到的OpenID)
	private String FromUserName = null;//	是	开发者微信号
	private String CreateTime = null;//	是	消息创建时间 (整型)
	private String MsgType =null;//	 是	text
	private String Content = null;//	是	回复的消息内容(换行:在content中能够换行,微信客户端就支持换行显示)
	StringBuffer strb = new StringBuffer();
	StringBuffer strb_ = new StringBuffer();
	public Out_Text(In in) {
	//public Out_Text(In in,String str) {
		super();
		// TODO Auto-generated constructor stub
		Date date = new Date();

		strb.append("             <ToUserName><![CDATA["+in.getFromUserName()+"]]></ToUserName>                   ");
		strb.append("         <FromUserName><![CDATA["+in.getToUserName()+"]]></FromUserName>                       ");
		strb.append("         <CreateTime>"+date.getTime()+"</CreateTime>                       ");
		strb.append("          <MsgType><![CDATA[text]]></MsgType>   ");
	    //this.setContent(str);
	}

	//public String getStr(String str){
	public String getStr(){

		strb_.append("           <xml>                     ");    
		strb_.append(strb);
		//strb_.append("            <Content><![CDATA["+str+"]]></Content>                    ");
		strb_.append("            <Content><![CDATA["+this.getContent()+"]]></Content>                    ");
		strb_.append("            </xml>                    ");
		return strb_.toString();

		
	}
	
	public String getToUserName() {
		return ToUserName;
	}
	public void setToUserName(String toUserName) {
		ToUserName = toUserName;
	}
	public String getFromUserName() {
		return FromUserName;
	}
	public void setFromUserName(String fromUserName) {
		FromUserName = fromUserName;
	}
	public String getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(String createTime) {
		CreateTime = createTime;
	}
	public String getMsgType() {
		return MsgType;
	}
	public void setMsgType(String msgType) {
		MsgType = msgType;
	}
	public String getContent() {
		return Content;
	}
	public void setContent(String content) {
		Content = content;
	}
	
	
	
}

 

© 著作权归作者所有

blueheart
粉丝 0
博文 35
码字总数 29716
作品 0
佛山
程序员
私信 提问
分享java微信开发视频

课程讲师:翟东平 课程分类:Java适合人群:高级课时数量:24(41节)课时更新程度:完毕服务类型:C类(普通服务类课程)用到技术:微信公众平台,微信,java涉及项目:超市促销活动,微信限时...

双层牛堡
2015/04/07
0
0
Java微信开发_00_资源汇总贴

1.微信公众平台技术文档(https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432) 2.微信企业号开发接口文档(http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%BB%E......

rayner
2017/08/07
0
0
微信公众帐号开发教程第4篇-消息及消息处理工具的封装

工欲善其事必先利其器!本篇内容主要讲解如何将微信公众平台定义的消息及消息相关的操作封装成工具类,方面后期的使用。这里需要明确的是消息其实是由用户发给你的公众帐号的,消息先被微信平...

bliver
2013/11/29
0
2
JeeWx 捷微 2.3 发布,JAVA微信管家平台

JeeWx,敏捷微信开发,简称“捷微”,捷微是一款免费开源的JAVA微信管家平台 一、简介 Jeewx是一个开源、高效、敏捷的微信开发平台,采用JAVA语言基于Jeecg快速开发框架实现,Jeewx开源版实现...

Jeecg
2016/03/24
10.6K
0
微信公众平台开发教程新手解惑40则

【编者按】由CSDN和《程序员》杂志联合主办的 2014年微信开发者大会 将于8月23日在北京举行,邀请了来自于一线的微信开发商技术负责人或资深工程师从企业应用开发高级篇、智能客服与LBS、微信...

DavidBao
2015/04/29
0
0

没有更多内容

加载失败,请刷新页面

加载更多

vmstat命令详解

https://www.cnblogs.com/ggjucheng/archive/2012/01/05/2312625.html

流光韶逝
20分钟前
0
0
如何理解算法时间复杂度的表示

先从O(1) 来说,理论上哈希表就是O(1)。因为哈希表是通过哈希函数来映射的,所以拿到一个关键 字,用哈希函数转换一下,就可以直接从表中取出对应的值。和现存数据有多少毫无关系,故而每次执...

yky20190625
36分钟前
2
0
分布式架构 实现分布式锁的常见方式

一、我们为什么需要分布式锁? 在单机时代,虽然不需要分布式锁,但也面临过类似的问题,只不过在单机的情况下,如果有多个线程要同时访问某个共享资源的时候,我们可以采用线程间加锁的机制...

太猪-YJ
今天
7
0
GitLab Docker 安装记录

安装环境 环境Centos7.4 64 1.拉取镜像文件 docker pull gitlab/gitlab-ce:latest 2.docker 安装 git.zddts.com 为访问域名或换成可以访问的IP docker run -d --hostname git.***.com -p ......

侠者圣
今天
0
0
EfficientNet: 再论 CNN 的网络规模

由于这里公式无法正常显示,所有内容以图片内容上传,如有需要,可提供 pdf 版。

爱吃草莓的皮卡丘
今天
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部