java图⽂消息_开发之回复图⽂消息java代码开发之回复图⽂消息,供⼤家参考,具体内容如下
图⽂消息的主要参数说明
通过官⽅的消息接⼝指南,可以看到对图⽂消息的参数介绍,如下图所⽰:
从上图可以了解到:
1、图⽂消息的个数限制为10,也就是图⽂中ArticleCount的值(图⽂消息的个数,限制在10条以内)
2、对于图⽂消息,第⼀条图⽂的图⽚显⽰为⼤图,其他图⽂的图⽚显⽰为⼩图。
3、第⼀条图⽂的图⽚⼤⼩建议为640*320,其他图⽂的图⽚建议为80*80
下⾯开始实现:
请求消息的基类:
import com.thoughtworks.xstream.annotations.XStreamAlias;
import java.io.Serializable;
/**
* @author inchlifc
*/
public class BaseMessage implements Serializable {
@XStreamAlias("ToUserName")
@XStreamCDATA
private String ToUserName;
@XStreamAlias("FromUserName")
@XStreamCDATA
private String FromUserName;
@XStreamAlias("CreateTime")
private Long CreateTime;
@XStreamAlias("MsgType")
@XStreamCDATA
private String MsgType;
public BaseMessage() {
super();
}
public BaseMessage(String fromUserName,String toUserName) { super();
FromUserName = fromUserName;
ToUserName = toUserName;代码转换
CreateTime = System.currentTimeMillis();
}
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 Long getCreateTime() {
return CreateTime;
}
public void setCreateTime(Long createTime) {
CreateTime = createTime;
}
public String getMsgType() {
return MsgType;
}
public void setMsgType(String msgType) {
MsgType = msgType;
}
}
图⽂消息类:
import com.thoughtworks.xstream.annotations.XStreamAlias; import java.util.List;
@XStreamAlias("xml")
public class ArticlesMessage extends BaseMessage {
@XStreamAlias("ArticleCount")
private int ArticleCount;
@XStreamAlias("Articles")
private List Articles;
public int getArticleCount() {
return ArticleCount;
}
public void setArticleCount(int articleCount) {
ArticleCount = articleCount;
}
public List getArticles() {
return Articles;
}
public void setArticles(List articles) {
Articles = articles;
}
}
图⽂消息中的Articles类:
import com.thoughtworks.xstream.annotations.XStreamAlias; import java.util.List;
@XStreamAlias("Articles")
public class Articles {
private List Articles;
}
图⽂消息中的ArticlesItem类:
import com.thoughtworks.xstream.annotations.XStreamAlias; import java.io.Serializable;
@XStreamAlias("item")
public class ArticlesItem implements Serializable { @XStreamAlias("Title")
@XStreamCDATA
private String Title;
@XStreamAlias("Description")
@XStreamCDATA
private String Description;
@XStreamAlias("PicUrl")
@XStreamCDATA
private String PicUrl;
@XStreamAlias("Url")
@XStreamCDATA
private String Url;
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;
}
}
service层实现⽅法:
封装⽅法
/
**
* 获取博客图⽂消息
*
* @param custermName
* @param serverName
* @param createTime
* @return
*/
private ArticlesMessage getBlogMessage(String custermName,String serverName,Long createTime) { ArticlesMessage outputMsg = new ArticlesMessage();
outputMsg.setFromUserName(serverName);
outputMsg.setToUserName(custermName);
outputMsg.setCreateTime(createTime);
outputMsg.setMsgType(Value());
List articles = new ArrayList<>();
ArticlesItem item1 = new ArticlesItem();
item1.setTitle("晚天吹凉风");
item1.setDescription("点击进⼊晚天吹凉风博客");
item1.setPicUrl(WechatConstant.BASE_SERVER + "resources/images/wechat/a.png");
item1.setUrl("my.oschina/inchlifc/blog");
articles.add(item1);
outputMsg.setArticles(articles);
outputMsg.setArticleCount(articles.size());
return outputMsg;
}
判断如果输⼊数字1,返回图⽂消息推送
// 处理接收消息

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。