您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 营销创新 > java开发微信公众平台04
java开发微信公众平台04响应消息的基类同样,把消息回复中定义的所有消息都有的字段提取出来,封装成一个基类,这些公有的字段包括:ToUserName(接收方帐号,用户的OPEN_ID)、FromUserName(开发者的微信号)、CreateTime(消息的创建时间)、MsgType(消息类型)、FuncFlag(消息的星标标识),封装后基类.liufeng.course.message.resp.BaseMessage的代码如下:package.liufeng.course.message.resp;/***消息基类(公众帐号-普通用户)**@authorliufengy1t6d微信推广*@date2013-05-19*/publilassBaseMessage{//接收方帐号(收到的OpenID)privateStringToUserName;//开发者微信号privateStringFromUserName;//消息创建时间(整型)privatelongCreateTime;//消息类型(text/music/news)privateStringMsgType;//位0x0001被标志时,星标刚收到的消息privateintFuncFlag;publicStringgetToUserName(){y1t6d微信推广}publicvoidsetToUserName(StringtoUserName){ToUserName=toUserName;}publicStringgetFromUserName(){returnFromUserName;}publicvoidsetFromUserName(StringfromUserName){FromUserName=fromUserName;}publiclonggetCreateTime(){returnCreateTime;y1t6d微信推广}publicvoidsetCreateTime(longcreateTime){CreateTime=createTime;}publicStringgetMsgType(){returnMsgType;}publicvoidsetMsgType(StringmsgType){MsgType=msgType;}publicintgetFuncFlag(){returnFuncFlag;}publicvoidsetFuncFlag(intfuncFlag){y1t6d微信推广=funcFlag;}}package.liufeng.course.message.resp;/***文本消息**@authorliufeng*@date2013-05-19*/publilassTextMessageextendsBaseMessage{//回复的消息内容privateStringContent;publicStringgetContent(){y1t6d微信推广}publicvoidsetContent(Stringcontent){Content=content;}}package.liufeng.course.message.resp;/***音乐消息**@authorliufeng*@date2013-05-19*/publilassMusicMessageextendsBaseMessage{y1t6d微信推广音乐privateMusicMusic;publicMusicgetMusic(){returnMusic;}publicvoidsetMusic(Musicmusic){Music=music;}}package.liufeng.course.message.resp;/***音乐model**@authorliufengy1t6d微信推广*@date2013-05-19*/publilassMusic{//音乐名称privateStringTitle;//音乐描述privateStringDescription;//音乐链接privateStringMusicUrl;//高质量音乐链接,WIFI环境优先使用该链接播放音乐privateStringHQMusicUrl;publicStringgetTitle(){returnTitle;y1t6d微信推广}publicvoidsetTitle(Stringtitle){Title=title;}publicStringgetDescription(){returnDescription;}publicvoidsetDescription(Stringdescription){Description=description;}publicStringgetMusicUrl(){returnMusicUrl;}y1t6d微信推广(StringmusicUrl){MusicUrl=musicUrl;}publicStringgetHQMusicUrl(){returnHQMusicUrl;}publicvoidsetHQMusicUrl(StringmusicUrl){HQMusicUrl=musicUrl;}}package.liufeng.course.message.resp;importjava.util.List;/***文本消息y1t6d微信推广**@authorliufeng*@date2013-05-19*/publilassNewsMessageextendsBaseMessage{//图文消息个数,限制为10条以内privateintArticleCount;//多条图文消息信息,默认第一个item为大图privateList<ArticleArticles;publicintgetArticleCount(){returnArticleCount;}publicvoidsetArticleCount(intarticleCount){y1t6d微信推广=articleCount;}publicList<ArticlegetArticles(){returnArticles;}publicvoidsetArticles(List<Articlearticles){Articles=articles;}}图文消息中Article类的定义package.liufeng.course.message.resp;/***图文modely1t6d微信推广**@authorliufeng*@date2013-05-19*/publilassArticle{//图文消息名称privateStringTitle;//图文消息描述privateStringDescription;//链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80,限制链接的域名需要与开发者填写的基本资料中的Url一致privateStringPicUrl;//点击图文消息跳转链接y1t6d微信推广(){returnTitle;}publicvoidsetTitle(Stringtitle){Title=title;}publicStringgetDescription(){returnnull==Description:Description;}publicvoidsetDescription(Stringdescription){Description=description;}y1t6d微信推广(){returnnull==PicUrl:PicUrl;}publicvoidsetPicUrl(StringpicUrl){PicUrl=picUrl;}publicStringgetUrl(){returnnull==Url:Url;}publicvoidsetUrl(Stringurl){Url=url;}}这些类只要放在同一包里就可以了,你什么都不y1t6d微信推广用改!目前你的项目有两个包就完成了请求和响应消息的封装了!原作者:柳峰
本文标题:java开发微信公众平台04
链接地址:https://www.777doc.com/doc-1575190 .html