公众号开发
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
package com.stdiet.custom.utils;
|
||||
|
||||
public class WechatMessageUtil {
|
||||
// 各种消息类型,除了扫带二维码事件
|
||||
/**
|
||||
* 文本消息
|
||||
*/
|
||||
public static final String MESSAGE_TEXT = "text";
|
||||
/**
|
||||
* 图片消息
|
||||
*/
|
||||
public static final String MESSAtGE_IMAGE = "image";
|
||||
/**
|
||||
* 图文消息
|
||||
*/
|
||||
public static final String MESSAGE_NEWS = "news";
|
||||
/**
|
||||
* 语音消息
|
||||
*/
|
||||
public static final String MESSAGE_VOICE = "voice";
|
||||
/**
|
||||
* 视频消息
|
||||
*/
|
||||
public static final String MESSAGE_VIDEO = "video";
|
||||
/**
|
||||
* 小视频消息
|
||||
*/
|
||||
public static final String MESSAGE_SHORTVIDEO = "shortvideo";
|
||||
/**
|
||||
* 地理位置消息
|
||||
*/
|
||||
public static final String MESSAGE_LOCATION = "location";
|
||||
/**
|
||||
* 链接消息
|
||||
*/
|
||||
public static final String MESSAGE_LINK = "link";
|
||||
/**
|
||||
* 事件推送消息
|
||||
*/
|
||||
public static final String MESSAGE_EVENT = "event";
|
||||
/**
|
||||
* 事件推送消息中,事件类型,subscribe(订阅)
|
||||
*/
|
||||
public static final String MESSAGE_EVENT_SUBSCRIBE = "subscribe";
|
||||
/**
|
||||
* 事件推送消息中,事件类型,unsubscribe(取消订阅)
|
||||
*/
|
||||
public static final String MESSAGE_EVENT_UNSUBSCRIBE = "unsubscribe";
|
||||
/**
|
||||
* 事件推送消息中,上报地理位置事件
|
||||
*/
|
||||
public static final String MESSAGE_EVENT_LOCATION_UP = "LOCATION";
|
||||
/**
|
||||
* 事件推送消息中,自定义菜单事件,点击菜单拉取消息时的事件推送
|
||||
*/
|
||||
public static final String MESSAGE_EVENT_CLICK = "CLICK";
|
||||
/**
|
||||
* 事件推送消息中,自定义菜单事件,点击菜单跳转链接时的事件推送
|
||||
*/
|
||||
public static final String MESSAGE_EVENT_VIEW = "VIEW";
|
||||
|
||||
|
||||
}
|
@ -1,5 +1,11 @@
|
||||
package com.stdiet.custom.utils;
|
||||
|
||||
import com.stdiet.custom.domain.WxXmlData;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@ -81,4 +87,21 @@ public class WxTokenUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static WxXmlData resolveXmlData(InputStream in) {
|
||||
WxXmlData wxXmlData = null;
|
||||
try {
|
||||
String xmlData = IOUtils.toString(in, StandardCharsets.UTF_8.name());
|
||||
XStream xstream = new XStream();
|
||||
//这个必须要加 不然无法转换成WxXmlData对象
|
||||
xstream.setClassLoader(WxXmlData.class.getClassLoader());
|
||||
xstream.processAnnotations(WxXmlData.class);
|
||||
xstream.alias("xml", WxXmlData.class);
|
||||
wxXmlData = (WxXmlData) xstream.fromXML(xmlData);
|
||||
// log.info("【wxXmlData: {}】 ", wxXmlData);
|
||||
} catch (Exception e) {
|
||||
// log.error("【error】{}", e.getMessage());
|
||||
}
|
||||
return wxXmlData;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user