me.chanjar.weixin.mp.bean.WxMpXmlOutMessage Maven / Gradle / Ivy
package me.chanjar.weixin.mp.bean;
import me.chanjar.weixin.common.util.xml.AdapterCDATA;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.bean.outxmlbuilder.*;
import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil;
import me.chanjar.weixin.mp.util.xml.XmlTransformer;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class WxMpXmlOutMessage {
@XmlElement(name="ToUserName")
@XmlJavaTypeAdapter(AdapterCDATA.class)
protected String toUserName;
@XmlElement(name="FromUserName")
@XmlJavaTypeAdapter(AdapterCDATA.class)
protected String fromUserName;
@XmlElement(name="CreateTime")
protected Long createTime;
@XmlElement(name="MsgType")
@XmlJavaTypeAdapter(AdapterCDATA.class)
protected String msgType;
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public String getMsgType() {
return msgType;
}
public void setMsgType(String msgType) {
this.msgType = msgType;
}
public String toXml() {
try {
return XmlTransformer.toXml((Class)this.getClass(), this);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* 转换成加密的xml格式
* @return
*/
public String toEncryptedXml(WxMpConfigStorage wxMpConfigStorage) {
String plainXml = toXml();
WxMpCryptUtil pc = new WxMpCryptUtil(wxMpConfigStorage);
return pc.encrypt(plainXml);
}
/**
* 获得文本消息builder
* @return
*/
public static TextBuilder TEXT() {
return new TextBuilder();
}
/**
* 获得图片消息builder
* @return
*/
public static ImageBuilder IMAGE() {
return new ImageBuilder();
}
/**
* 获得语音消息builder
* @return
*/
public static VoiceBuilder VOICE() {
return new VoiceBuilder();
}
/**
* 获得视频消息builder
* @return
*/
public static VideoBuilder VIDEO() {
return new VideoBuilder();
}
/**
* 获得音乐消息builder
* @return
*/
public static MusicBuilder MUSIC() {
return new MusicBuilder();
}
/**
* 获得图文消息builder
* @return
*/
public static NewsBuilder NEWS() {
return new NewsBuilder();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy