All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.foxinmy.weixin4j.response.NewsResponse Maven / Gradle / Ivy

package com.foxinmy.weixin4j.response;

import java.util.ArrayList;
import java.util.List;

/**
 * 回复图文消息
 * 
 * @className NewsResponse
 * @author jinyu([email protected])
 * @date 2015年5月5日
 * @since JDK 1.6
 * @see
 */
public class NewsResponse implements WeixinResponse {

	/**
	 * 图文集合
	 */
	private List
articleList; public NewsResponse(List
articleList) { this.articleList = articleList; } public NewsResponse(Article article) { this.articleList = new ArrayList
(); this.articleList.add(article); } public void pushArticle(Article article) { articleList.add(article); } public void pushFirstArticle(Article article) { articleList.add(0, article); } public void pushLastArticle(Article article) { articleList.add(articleList.size(), article); } public Article removeLastArticle() { return articleList.remove(articleList.size() - 1); } public Article removeFirstArticle() { return articleList.remove(0); } public List
getArticleList() { return articleList; } @Override public String toContent() { StringBuilder content = new StringBuilder(); content.append(String.format("%d", articleList.size())); content.append(""); for (Article article : articleList) { content.append(""); content.append(String.format("<![CDATA[%s]]>", article.getTitle() != null ? article.getTitle() : "")); content.append(String.format( "", article.getDesc() != null ? article.getDesc() : "")); content.append(String.format("", article.getUrl() != null ? article.getUrl() : "")); content.append(String.format("", article.getPicUrl() != null ? article.getPicUrl() : "")); content.append(""); } content.append(""); return content.toString(); } @Override public String getMsgType() { return "news"; } /** * 图文消息对象 * * @className Article * @author jinyu([email protected]) * @date 2015年5月5日 * @since JDK 1.6 * @see */ public static class Article { /** * 图文消息标题 */ private String title; /** * 图文消息描述 */ private String desc; /** * 点击图文消息跳转链接 */ private String url; /** * 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200 */ private String picUrl; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getPicUrl() { return picUrl; } public void setPicUrl(String picUrl) { this.picUrl = picUrl; } public Article() { } public Article(String title, String desc, String url, String picUrl) { this.title = title; this.desc = desc; this.url = url; this.picUrl = picUrl; } @Override public String toString() { return "Article [title=" + title + ", desc=" + desc + ", url=" + url + ", picUrl=" + picUrl + "]"; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy