1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package com.yihu.wlyy.wechat.util;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- /**
- * 消息回复工具类
- *
- * Created by lyr on 2016/08/15.
- */
- public class WeiXinMessageReplyUtils {
- /**
- * 回复图文消息
- *
- * @param toUser
- * @param fromUser
- * @param articles
- * @return
- * @throws Exception
- */
- public static String replyNewsMessage(String toUser,String fromUser,List<Map<String,String>> articles) throws Exception {
- if(articles == null || articles.size() < 1){
- throw new Exception("图文信息不能为空!");
- }
- StringBuilder result = new StringBuilder();
- result.append("<xml>");
- result.append("<ToUserName>" + toUser + "</ToUserName>");
- result.append("<FromUserName>" + fromUser + "</FromUserName>");
- result.append("<CreateTime>" + new Date().getTime() + "</CreateTime>");
- result.append("<MsgType>news</MsgType>");
- result.append("<ArticleCount>" + articles.size() + "</ArticleCount>");
- result.append("<Articles>");
- for(Map<String,String> article : articles){
- result.append("<item>");
- result.append("<Title>" + article.get("Title") +"</Title>");
- result.append("<Description>" + article.get("Description") + "</Description>");
- result.append("<PicUrl>" + article.get("PicUrl") + "</PicUrl>");
- result.append("<Url>" + article.get("Url") + "</Url>");
- result.append("</item>");
- }
- result.append("</Articles>");
- result.append("</xml>");
- return result.toString();
- }
- /**
- * 公众号群发图文消息
- *
- * @param toUser
- * @param fromUser
- * @param articles
- * @return
- * @throws Exception
- */
- public static String mapNewsMessage(String toUser,String fromUser,List<Map<String,String>> articles) throws Exception {
- //1.上传图片到微信服务器
- //2.上传图文消息素材到微信服务器
- // 3.根据openID列表群发
- return null;
- }
- }
|