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

net.sf.weixinmp.outbound.passive.PassiveArticleMessage Maven / Gradle / Ivy

The newest version!
package net.sf.weixinmp.outbound.passive;

import java.text.MessageFormat;
import java.util.List;
/**
 * 回复图文消息




12345678

2


<![CDATA[title1]]> 





<![CDATA[title]]>





 
参数	是否必须	说明
ToUserName	是	接收方帐号(收到的OpenID)
FromUserName	是	开发者微信号
CreateTime	是	消息创建时间 (整型)
MsgType	是	news
ArticleCount	是	图文消息个数,限制为10条以内
Articles	是	多条图文消息信息,默认第一个item为大图,注意,如果图文数超过10,则将会无响应
Title	否	图文消息标题
Description	否	图文消息描述
PicUrl	否	图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
Url	否	点击图文消息跳转链接
 * @author Alex
 *
 */
public class PassiveArticleMessage extends PassiveStringMessage {
	private final static String xmlTemplate = "" +
			"" +
			"" +
			"{2}" +
			"" +
			"{3}" +
			"" +
			"{4}" +
			" ";
	public PassiveArticleMessage(String to, String from, ArticleItem item) {
		super("text/xml;charset=utf-8", MessageFormat.format(xmlTemplate, to, from, (System.currentTimeMillis()/1000)+"", 1, item));
	}
	public PassiveArticleMessage(String to, String from, List list) {
		super("text/xml;charset=utf-8", MessageFormat.format(xmlTemplate, to, from, (System.currentTimeMillis()/1000)+"", list.size(), toXMLSnaippt(list)));
	}
	private static String toXMLSnaippt(List list){
		StringBuilder b=new StringBuilder();
		for(ArticleItem i:list) b.append(i);
		return b.toString();
	}
	public static class ArticleItem {
		String title, description, picUrl, url;
		public ArticleItem(String title, String description, String picUrl, String url) {
			super();
			this.title = title;
			this.description = description;
			this.picUrl = picUrl;
			this.url = url;
		}

		public String toString() {
			StringBuilder b=new StringBuilder();
			
			b.append("")
			.append("<![CDATA["+title+"]]>")
			.append("")
			.append("")
			.append("")
			.append("");
			
			return b.toString();
		}
		
		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy