【大的调整】重新定义(手贱)了「被动消息」「客服消息」「群发消息」的传输实体,另外新增了企业号「多媒体管理接口」「菜单管理接口」「发送消息接口」三个接口
This commit is contained in:
@@ -12,7 +12,9 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||
* @date 2014年9月24日
|
||||
* @since JDK 1.7
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E">全局返回码</a>
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E">公众平台全局返回码说明</a>
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E">企业号全局返回码说明</a>
|
||||
*/
|
||||
public class JsonResult implements Serializable {
|
||||
|
||||
|
||||
@@ -5,13 +5,9 @@ import java.io.Serializable;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 普通消息基类
|
||||
* <p>
|
||||
* <font color="red">回复图片等多媒体消息时需要预先上传多媒体文件到微信服务器,
|
||||
* 假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试</font>
|
||||
* </p>
|
||||
* 消息基类
|
||||
*
|
||||
* @className BaseMessage
|
||||
* @className BaseMsg
|
||||
* @author jy.hu
|
||||
* @date 2014年4月6日
|
||||
* @since JDK 1.7
|
||||
@@ -26,12 +22,25 @@ public class BaseMsg implements Serializable {
|
||||
private String fromUserName; // 发送方帐号(一个OpenID)
|
||||
@XStreamAlias("CreateTime")
|
||||
private long createTime = System.currentTimeMillis(); // 消息创建时间 (整型)
|
||||
@XStreamAlias("MsgType")
|
||||
private String msgType; // 消息类型
|
||||
@XStreamAlias("MsgId")
|
||||
private long msgId; // 消息ID
|
||||
|
||||
public BaseMsg() {
|
||||
|
||||
}
|
||||
|
||||
public BaseMsg(String msgType) {
|
||||
this(msgType, null, null);
|
||||
}
|
||||
|
||||
public BaseMsg(String toUserName, String fromUserName) {
|
||||
this(null, toUserName, fromUserName);
|
||||
}
|
||||
|
||||
public BaseMsg(String msgType, String toUserName, String fromUserName) {
|
||||
this.msgType = msgType;
|
||||
this.toUserName = toUserName;
|
||||
this.fromUserName = fromUserName;
|
||||
}
|
||||
@@ -59,4 +68,35 @@ public class BaseMsg implements Serializable {
|
||||
public void setCreateTime(long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public long getMsgId() {
|
||||
return msgId;
|
||||
}
|
||||
|
||||
public void setMsgId(long msgId) {
|
||||
this.msgId = msgId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof BaseMsg) {
|
||||
return ((BaseMsg) obj).getMsgId() == msgId;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseMsg [toUserName=" + toUserName + ", fromUserName="
|
||||
+ fromUserName + ", createTime=" + createTime + ", msgType="
|
||||
+ msgType + ", msgId=" + msgId + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.foxinmy.weixin4j.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.ButtonType;
|
||||
|
||||
/**
|
||||
* 菜单按钮
|
||||
* <p>
|
||||
* 目前自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单,一级菜单最多4个汉字,二级菜单最多7个汉字,多出来的部分将会以"..."代替
|
||||
* 请注意,创建自定义菜单后,由于微信客户端缓存,需要24小时微信客户端才会展现出来,建议测试时可以尝试取消关注公众账号后再次关注,则可以看到创建后的效果
|
||||
* </p>
|
||||
*
|
||||
* @className Button
|
||||
* @author jy.hu
|
||||
* @date 2014年4月5日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.type.ButtonType
|
||||
*/
|
||||
public class Button implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6422234732203854866L;
|
||||
|
||||
private String name;
|
||||
private ButtonType type; // 菜单的响应动作类型
|
||||
private String key; // click等点击类型必须
|
||||
private String url; // view类型必须
|
||||
|
||||
@JSONField(name = "sub_button")
|
||||
private List<Button> subs;
|
||||
|
||||
public Button() {
|
||||
}
|
||||
|
||||
public Button(String name, String value, ButtonType buttonType) {
|
||||
this.name = name;
|
||||
this.type = buttonType;
|
||||
if (buttonType == ButtonType.view) {
|
||||
this.url = value;
|
||||
} else {
|
||||
this.key = value;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ButtonType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ButtonType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public List<Button> getSubs() {
|
||||
return subs;
|
||||
}
|
||||
|
||||
public void setSubs(List<Button> subs) {
|
||||
this.subs = subs;
|
||||
}
|
||||
|
||||
public Button pushSub(Button btn) {
|
||||
if (this.subs == null) {
|
||||
this.subs = new ArrayList<Button>();
|
||||
}
|
||||
this.subs.add(btn);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[Button name=").append(name);
|
||||
sb.append(" ,type=").append(type);
|
||||
sb.append(" ,key=").append(key);
|
||||
sb.append(" ,url=").append(url);
|
||||
if (subs != null && !subs.isEmpty()) {
|
||||
sb.append("{");
|
||||
for (Button sub : subs) {
|
||||
sb.append(sub.toString());
|
||||
}
|
||||
sb.append("}");
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.foxinmy.weixin4j.msg;
|
||||
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 普通消息基类
|
||||
* <p>
|
||||
* <font color="red">回复图片等多媒体消息时需要预先上传多媒体文件到微信服务器,
|
||||
* 假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试</font>
|
||||
* </p>
|
||||
*
|
||||
* @className BaseMessage
|
||||
* @author jy.hu
|
||||
* @date 2014年4月6日
|
||||
* @since JDK 1.7
|
||||
*/
|
||||
public class BaseMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = 7761192742840031607L;
|
||||
|
||||
@XStreamAlias("MsgType")
|
||||
private MessageType msgType; // 消息类型
|
||||
@XStreamAlias("MsgId")
|
||||
private long msgId; // 消息ID
|
||||
|
||||
public BaseMessage(MessageType msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public MessageType getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public void setMsgType(MessageType msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public long getMsgId() {
|
||||
return msgId;
|
||||
}
|
||||
|
||||
public void setMsgId(long msgId) {
|
||||
this.msgId = msgId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof BaseMessage) {
|
||||
return ((BaseMessage) obj).getMsgId() == msgId;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.msg;
|
||||
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%99%AE%E9%80%9A%E6%B6%88%E6%81%AF#.E5.9B.BE.E7.89.87.E6.B6.88.E6.81.AF">图片消息</a>
|
||||
*/
|
||||
public class ImageMessage extends BaseMessage {
|
||||
public class ImageMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = 8430800898756567016L;
|
||||
|
||||
public ImageMessage() {
|
||||
super(MessageType.image);
|
||||
super(MessageType.image.name());
|
||||
}
|
||||
|
||||
@XStreamAlias("PicUrl")
|
||||
@@ -39,7 +40,7 @@ public class ImageMessage extends BaseMessage {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[ImageMessage ,toUserName=").append(super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,picUrl=").append(picUrl);
|
||||
sb.append(" ,mediaId=").append(mediaId);
|
||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.msg;
|
||||
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%99%AE%E9%80%9A%E6%B6%88%E6%81%AF#.E9.93.BE.E6.8E.A5.E6.B6.88.E6.81.AF">链接消息</a>
|
||||
*/
|
||||
public class LinkMessage extends BaseMessage {
|
||||
public class LinkMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = 754952745115497030L;
|
||||
|
||||
public LinkMessage() {
|
||||
super(MessageType.link);
|
||||
super(MessageType.link.name());
|
||||
}
|
||||
|
||||
@XStreamAlias("Title")
|
||||
@@ -45,7 +46,7 @@ public class LinkMessage extends BaseMessage {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[LinkMessage ,toUserName=").append(super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,title=").append(title);
|
||||
sb.append(" ,description=").append(description);
|
||||
sb.append(" ,url=").append(url);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.msg;
|
||||
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%99%AE%E9%80%9A%E6%B6%88%E6%81%AF#.E5.9C.B0.E7.90.86.E4.BD.8D.E7.BD.AE.E6.B6.88.E6.81.AF">地理位置消息</a>
|
||||
*/
|
||||
public class LocationMessage extends BaseMessage {
|
||||
public class LocationMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = 2866021596599237334L;
|
||||
|
||||
public LocationMessage() {
|
||||
super(MessageType.location);
|
||||
super(MessageType.location.name());
|
||||
}
|
||||
|
||||
@XStreamAlias("Location_X")
|
||||
@@ -56,7 +57,7 @@ public class LocationMessage extends BaseMessage {
|
||||
sb.append("[LocationMessage ,toUserName=")
|
||||
.append(super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,location_X=").append(x);
|
||||
sb.append(" ,location_Y=").append(y);
|
||||
sb.append(" ,scale=").append(scale);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.msg;
|
||||
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@@ -14,15 +15,13 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%99%AE%E9%80%9A%E6%B6%88%E6%81%AF#.E6.96.87.E6.9C.AC.E6.B6.88.E6.81.AF">接收文本消息</a>
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E8%A2%AB%E5%8A%A8%E5%93%8D%E5%BA%94%E6%B6%88%E6%81%AF#.E5.9B.9E.E5.A4.8D.E6.96.87.E6.9C.AC.E6.B6.88.E6.81.AF">回复文本消息</a>
|
||||
* @see com.foxinmy.weixin4j.msg.BaseMessage
|
||||
* @see com.foxinmy.weixin4j.msg.BaseMessage#toXml()
|
||||
*/
|
||||
public class TextMessage extends BaseMessage {
|
||||
public class TextMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = -7018053906644190260L;
|
||||
|
||||
public TextMessage() {
|
||||
super(MessageType.text);
|
||||
super(MessageType.text.name());
|
||||
}
|
||||
|
||||
@XStreamAlias("Content")
|
||||
@@ -41,7 +40,7 @@ public class TextMessage extends BaseMessage {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[TextMessage ,toUserName=").append(super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,content=").append(content);
|
||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||
sb.append(" ,msgId=").append(super.getMsgId()).append("]");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.msg;
|
||||
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%99%AE%E9%80%9A%E6%B6%88%E6%81%AF#.E8.A7.86.E9.A2.91.E6.B6.88.E6.81.AF">视频消息</a>
|
||||
*/
|
||||
public class VideoMessage extends BaseMessage {
|
||||
public class VideoMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = -1013075358679078381L;
|
||||
|
||||
public VideoMessage() {
|
||||
super(MessageType.video);
|
||||
super(MessageType.video.name());
|
||||
}
|
||||
|
||||
@XStreamAlias("MediaId")
|
||||
@@ -39,7 +40,7 @@ public class VideoMessage extends BaseMessage {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[VideoMessage ,toUserName=").append(super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,mediaId=").append(mediaId);
|
||||
sb.append(" ,thumbMediaId=").append(thumbMediaId);
|
||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.msg;
|
||||
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@@ -16,12 +17,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%99%AE%E9%80%9A%E6%B6%88%E6%81%AF#.E8.AF.AD.E9.9F.B3.E6.B6.88.E6.81.AF">语音消息</a>
|
||||
*/
|
||||
public class VoiceMessage extends BaseMessage {
|
||||
public class VoiceMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = -7988380977182214003L;
|
||||
|
||||
public VoiceMessage() {
|
||||
super(MessageType.voice);
|
||||
super(MessageType.voice.name());
|
||||
}
|
||||
|
||||
@XStreamAlias("MediaId")
|
||||
@@ -49,7 +50,7 @@ public class VoiceMessage extends BaseMessage {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[VoiceMessage ,toUserName=").append(super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,mediaId=").append(mediaId);
|
||||
sb.append(" ,format=").append(format);
|
||||
sb.append(" ,recognition=").append(recognition);
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package com.foxinmy.weixin4j.msg.event;
|
||||
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.type.EventType;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 事件消息基类
|
||||
*
|
||||
* @className EventMessage
|
||||
* @author jy.hu
|
||||
* @date 2014年4月6日
|
||||
* @since JDK 1.7
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E4%BA%8B%E4%BB%B6%E6%8E%A8%E9%80%81">事件推送</a>
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E4%BA%8B%E4%BB%B6%E6%8E%A8%E9%80%81">事件推送</a>
|
||||
*/
|
||||
public class EventMessage extends BaseMessage {
|
||||
public class EventMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = 7703667223814088865L;
|
||||
|
||||
public EventMessage(EventType eventType) {
|
||||
super(MessageType.event);
|
||||
super(MessageType.event.name());
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
@@ -38,7 +40,7 @@ public class EventMessage extends BaseMessage {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[EventMessage ,toUserName=").append(super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,eventType=").append(eventType.name());
|
||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||
sb.append(" ,msgId=").append(super.getMsgId()).append("]");
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class LocationEventMessage extends EventMessage {
|
||||
sb.append("[LocationEventMessage ,toUserName=").append(
|
||||
super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,eventType=").append(super.getEventType().name());
|
||||
sb.append(" ,longitude=").append(longitude);
|
||||
sb.append(" ,latitude=").append(latitude);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MassEventMessage extends EventMessage {
|
||||
sb.append("[MassEventMessage ,toUserName=").append(
|
||||
super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,eventType=").append(super.getEventType().name());
|
||||
sb.append(" ,status=").append(status);
|
||||
sb.append(" ,totalCount=").append(totalCount);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ScanEventMessage extends EventMessage {
|
||||
sb.append("[ScanEventMessage ,toUserName=").append(
|
||||
super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,eventType=").append(super.getEventType().name());
|
||||
sb.append(" ,eventKey=").append(eventKey);
|
||||
sb.append(" ,ticket=").append(ticket);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.foxinmy.weixin4j.msg.event;
|
||||
|
||||
|
||||
/**
|
||||
* 关注/取消关注事件
|
||||
* <font color="red">包括直接关注与扫描关注</font>
|
||||
* 关注/取消关注事件 <font color="red">包括直接关注与扫描关注</font>
|
||||
*
|
||||
* @className ScribeEventMessage
|
||||
* @author jy.hu
|
||||
* @date 2014年4月6日
|
||||
* @since JDK 1.7
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E4%BA%8B%E4%BB%B6%E6%8E%A8%E9%80%81#.E5.85.B3.E6.B3.A8.2F.E5.8F.96.E6.B6.88.E5.85.B3.E6.B3.A8.E4.BA.8B.E4.BB.B6">关注/取消关注事件</a>
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E4%BA%8B%E4%BB%B6%E6%8E%A8%E9%80%81#.E5.85.B3.E6.B3.A8.2F.E5.8F.96.E6.B6.88.E5.85.B3.E6.B3.A8.E4.BA.8B.E4.BB.B6">关注/取消关注事件</a>
|
||||
*/
|
||||
public class ScribeEventMessage extends ScanEventMessage {
|
||||
|
||||
@@ -17,9 +17,10 @@ public class ScribeEventMessage extends ScanEventMessage {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[ScribeEventMessage ,toUserName=").append(super.getToUserName());
|
||||
sb.append("[ScribeEventMessage ,toUserName=").append(
|
||||
super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,eventType=").append(super.getEventType().name());
|
||||
sb.append(" ,eventKey=").append(super.getEventKey());
|
||||
sb.append(" ,ticket=").append(super.getTicket());
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class MenuEventMessage extends EventMessage {
|
||||
sb.append("[MenuEventMessage ,toUserName=").append(
|
||||
super.getToUserName());
|
||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
||||
sb.append(" ,msgType=").append(super.getMsgType());
|
||||
sb.append(" ,eventType=").append(super.getEventType().name());
|
||||
sb.append(" ,eventKey=").append(eventKey);
|
||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 客服消息图文
|
||||
*
|
||||
* @className Article
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Article implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1231352700301456395L;
|
||||
|
||||
@XStreamAlias("Title")
|
||||
private String title; // 图文消息标题
|
||||
@JSONField(name = "description")
|
||||
@XStreamAlias("Description")
|
||||
private String desc; // 图文消息描述
|
||||
@JSONField(name = "picurl")
|
||||
@XStreamAlias("PicUrl")
|
||||
private String picUrl; // 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
|
||||
@XStreamAlias("Url")
|
||||
private String url; // 点击图文消息跳转链接
|
||||
|
||||
public Article(String title, String desc, String picUrl, String url) {
|
||||
this.title = title;
|
||||
this.desc = desc;
|
||||
this.picUrl = picUrl;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
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 getPicUrl() {
|
||||
return picUrl;
|
||||
}
|
||||
|
||||
public void setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Article [title=" + title + ", desc=" + desc + ", picUrl="
|
||||
+ picUrl + ", url=" + url + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
||||
|
||||
public class Base implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8487251213352068227L;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@XStreamOmitField
|
||||
private MediaType mediaType;
|
||||
|
||||
public Base(MediaType mediaType) {
|
||||
this.mediaType = mediaType;
|
||||
}
|
||||
|
||||
public MediaType getMediaType() {
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Base [mediaType=" + mediaType + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 文件对象
|
||||
* <p>
|
||||
* <font color="red">可用于「企业号的客服消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className File
|
||||
* @author jy
|
||||
* @date 2014年11月21日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class File extends Base implements Notifyable {
|
||||
private static final long serialVersionUID = -8149837316289636110L;
|
||||
|
||||
@JSONField(name = "media_id")
|
||||
@XStreamAlias("MediaId")
|
||||
private String mediaId;
|
||||
|
||||
public File(String mediaId) {
|
||||
super(MediaType.file);
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "File [mediaId=" + mediaId + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 图片对象
|
||||
* <p>
|
||||
* <font color="red">可用于「被动消息」「客服消息」「群发消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className Image
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Image extends Base implements Responseable, Notifyable, Massable {
|
||||
|
||||
private static final long serialVersionUID = 6928681900960656161L;
|
||||
|
||||
@JSONField(name = "media_id")
|
||||
@XStreamAlias("MediaId")
|
||||
private String mediaId;
|
||||
|
||||
public Image(String mediaId) {
|
||||
super(MediaType.image);
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
public Image(MediaType mediaType, String mediaId) {
|
||||
super(mediaType);
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Image [mediaId=" + mediaId + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
/**
|
||||
* 标记群发消息
|
||||
*
|
||||
* @className Massable
|
||||
* @author jy
|
||||
* @date 2014年11月22日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.msg.model.Text
|
||||
* @see com.foxinmy.weixin4j.msg.model.Image
|
||||
* @see com.foxinmy.weixin4j.msg.model.Voice
|
||||
* @see com.foxinmy.weixin4j.msg.model.MpVideo
|
||||
* @see com.foxinmy.weixin4j.msg.model.MpNews
|
||||
*/
|
||||
public interface Massable {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* 群发消息图文(消息内容存储在微信后台)
|
||||
*
|
||||
* @author jy.hu
|
||||
* @date 2014年4月26日
|
||||
* @since JDK 1.7
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E9%AB%98%E7%BA%A7%E7%BE%A4%E5%8F%91%E6%8E%A5%E5%8F%A3#.E4.B8.8A.E4.BC.A0.E5.9B.BE.E6.96.87.E6.B6.88.E6.81.AF.E7.B4.A0.E6.9D.90">群发消息描述</a>
|
||||
*/
|
||||
public class MpArticle implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5583479943661639234L;
|
||||
|
||||
@JSONField(name = "thumb_media_id")
|
||||
private String thumbMediaId; // 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得 非空
|
||||
private String author;// 图文消息的作者 可为空
|
||||
private String title;// 图文消息的标题 非空
|
||||
@JSONField(name = "content_source_url")
|
||||
private String url;// 在图文消息页面点击“阅读原文”后的页面 可为空
|
||||
private String content;// 图文消息页面的内容,支持HTML标签 非空
|
||||
private String digest;// 图文消息的描述 可为空
|
||||
@JSONField(name = "show_cover_pic")
|
||||
private String showCoverPic; // 是否显示封面,1为显示,0为不显示 可为空
|
||||
|
||||
public MpArticle(String thumbMediaId, String title, String content) {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public MpArticle() {
|
||||
|
||||
}
|
||||
|
||||
public String getThumbMediaId() {
|
||||
return thumbMediaId;
|
||||
}
|
||||
|
||||
public void setThumbMediaId(String thumbMediaId) {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return digest;
|
||||
}
|
||||
|
||||
public void setDigest(String digest) {
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public String getShowCoverPic() {
|
||||
return showCoverPic;
|
||||
}
|
||||
|
||||
public void setShowCoverPic(boolean showCoverPic) {
|
||||
this.showCoverPic = showCoverPic ? "1" : "0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[MpArticle thumbMediaId=").append(thumbMediaId);
|
||||
sb.append(", author=").append(author);
|
||||
sb.append(", title=").append(title);
|
||||
sb.append(", url=").append(url);
|
||||
sb.append(", content=").append(content);
|
||||
sb.append(", digest=").append(digest);
|
||||
sb.append(", showCoverPic=").append(showCoverPic).append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
||||
|
||||
/**
|
||||
* 图文对象(消息内容存储在微信后台)
|
||||
* <p>
|
||||
* <font color="red">可用于「群发消息(其中mediaId与articles请至少保持一个有值)」「企业号的客服消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className MpNews
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class MpNews extends Base implements Massable, Notifyable {
|
||||
|
||||
private static final long serialVersionUID = 8853054484809101524L;
|
||||
|
||||
@JSONField(name = "media_id")
|
||||
@XStreamAlias("MediaId")
|
||||
private String mediaId;
|
||||
@JSONField(name = "articles")
|
||||
@XStreamOmitField
|
||||
private List<MpArticle> articles;
|
||||
|
||||
public MpNews() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public MpNews(String mediaId) {
|
||||
super(MediaType.mpnews);
|
||||
this.mediaId = mediaId;
|
||||
this.articles = new ArrayList<MpArticle>();
|
||||
}
|
||||
|
||||
public void pushArticle(String thumbMediaId, String title, String content) {
|
||||
articles.add(new MpArticle(thumbMediaId, title, content));
|
||||
}
|
||||
|
||||
public void pushFirstArticle(String thumbMediaId, String title,
|
||||
String content) {
|
||||
articles.add(0, new MpArticle(thumbMediaId, title, content));
|
||||
}
|
||||
|
||||
public void pushLastArticle(String thumbMediaId, String title,
|
||||
String content) {
|
||||
articles.add(articles.size(), new MpArticle(thumbMediaId, title,
|
||||
content));
|
||||
}
|
||||
|
||||
public MpArticle removeLastArticle() {
|
||||
return articles.remove(articles.size() - 1);
|
||||
}
|
||||
|
||||
public MpArticle removeFirstArticle() {
|
||||
return articles.remove(0);
|
||||
}
|
||||
|
||||
public void setArticles(List<MpArticle> articles) {
|
||||
this.articles = articles;
|
||||
}
|
||||
|
||||
public List<MpArticle> getArticles() {
|
||||
return articles;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MpNews [articles=" + articles + ", mediaId=" + mediaId
|
||||
+ ", getMediaType()=" + getMediaType() + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 群发视频对象
|
||||
* <p>
|
||||
* <font color="red">可用于「群发消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className MpVideo
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class MpVideo extends Base implements Massable {
|
||||
|
||||
private static final long serialVersionUID = 2167437425244069128L;
|
||||
|
||||
@JSONField(name = "media_id")
|
||||
@XStreamAlias("MediaId")
|
||||
private String mediaId;
|
||||
|
||||
public MpVideo(String mediaId) {
|
||||
super(MediaType.mpvideo);
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MpVideo [mediaId=" + mediaId + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 音乐对象
|
||||
* <p>
|
||||
* <font color="red">可用于「被动消息」「客服消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className Music
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Music extends Base implements Responseable, Notifyable {
|
||||
|
||||
private static final long serialVersionUID = -5952134916367253297L;
|
||||
|
||||
@XStreamAlias("Title")
|
||||
private String title;
|
||||
@JSONField(name = "description")
|
||||
@XStreamAlias("Description")
|
||||
private String desc;
|
||||
@JSONField(name = "musicurl")
|
||||
@XStreamAlias("MusicUrl")
|
||||
private String musicUrl;
|
||||
@JSONField(name = "hqmusicurl")
|
||||
@XStreamAlias("HQMusicUrl")
|
||||
private String hqMusicUrl;
|
||||
@JSONField(name = "thumb_media_id")
|
||||
@XStreamAlias("ThumbMediaId")
|
||||
private String thumbMediaId;
|
||||
|
||||
public Music(String thumbMediaId) {
|
||||
this(null, null, null, null, thumbMediaId);
|
||||
}
|
||||
|
||||
public Music(String title, String desc, String musicUrl, String hqMusicUrl,
|
||||
String thumbMediaId) {
|
||||
super(MediaType.music);
|
||||
this.title = title;
|
||||
this.desc = desc;
|
||||
this.musicUrl = musicUrl;
|
||||
this.hqMusicUrl = hqMusicUrl;
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
|
||||
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 getMusicUrl() {
|
||||
return musicUrl;
|
||||
}
|
||||
|
||||
public void setMusicUrl(String musicUrl) {
|
||||
this.musicUrl = musicUrl;
|
||||
}
|
||||
|
||||
public String getHqMusicUrl() {
|
||||
return hqMusicUrl;
|
||||
}
|
||||
|
||||
public void setHqMusicUrl(String hqMusicUrl) {
|
||||
this.hqMusicUrl = hqMusicUrl;
|
||||
}
|
||||
|
||||
public String getThumbMediaId() {
|
||||
return thumbMediaId;
|
||||
}
|
||||
|
||||
public void setThumbMediaId(String thumbMediaId) {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Music [title=" + title + ", desc=" + desc + ", musicUrl="
|
||||
+ musicUrl + ", hqMusicUrl=" + hqMusicUrl + ", thumbMediaId="
|
||||
+ thumbMediaId + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 图文对象
|
||||
* <p>
|
||||
* <font color="red">可用于「被动消息」「客服消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className News
|
||||
* @author jy
|
||||
* @date 2014年11月21日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
@XStreamAlias("Articles")
|
||||
public class News extends Base implements Responseable, Notifyable {
|
||||
private static final int MAX_ARTICLE_COUNT = 10;
|
||||
private static final long serialVersionUID = 3348756809039388415L;
|
||||
|
||||
@JSONField(name = "articles")
|
||||
@XStreamAlias("Articles")
|
||||
private List<Article> articles;
|
||||
|
||||
public News() {
|
||||
super(MediaType.news);
|
||||
this.articles = new ArrayList<Article>();
|
||||
}
|
||||
|
||||
public void pushArticle(String title, String desc, String picUrl, String url) {
|
||||
if ((articles.size() + 1) > MAX_ARTICLE_COUNT) {
|
||||
return;
|
||||
}
|
||||
articles.add(new Article(title, desc, picUrl, url));
|
||||
}
|
||||
|
||||
public void pushFirstArticle(String title, String desc, String picUrl,
|
||||
String url) {
|
||||
articles.add(0, new Article(title, desc, picUrl, url));
|
||||
}
|
||||
|
||||
public void pushLastArticle(String title, String desc, String picUrl,
|
||||
String url) {
|
||||
articles.add(articles.size(), new Article(title, desc, picUrl, url));
|
||||
}
|
||||
|
||||
public Article removeLastArticle() {
|
||||
return articles.remove(articles.size() - 1);
|
||||
}
|
||||
|
||||
public Article removeFirstArticle() {
|
||||
return articles.remove(0);
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public boolean isMaxCount() {
|
||||
return this.articles.size() == MAX_ARTICLE_COUNT;
|
||||
}
|
||||
|
||||
public void setArticles(List<Article> articles) {
|
||||
if (articles.size() > MAX_ARTICLE_COUNT) {
|
||||
articles = articles.subList(0, MAX_ARTICLE_COUNT);
|
||||
}
|
||||
this.articles = articles;
|
||||
}
|
||||
|
||||
public List<Article> getArticles() {
|
||||
return articles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Article article : articles) {
|
||||
sb.append("{title=").append(article.getTitle());
|
||||
sb.append(" ,description=").append(article.getDesc());
|
||||
sb.append(" ,picUrl=").append(article.getPicUrl());
|
||||
sb.append(" ,url=").append(article.getUrl()).append("}");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
/**
|
||||
* 标记客服消息
|
||||
*
|
||||
* @className Notifyable
|
||||
* @author jy
|
||||
* @date 2014年11月22日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.msg.model.Text
|
||||
* @see com.foxinmy.weixin4j.msg.model.Image
|
||||
* @see com.foxinmy.weixin4j.msg.model.Voice
|
||||
* @see com.foxinmy.weixin4j.msg.model.Video
|
||||
* @see com.foxinmy.weixin4j.msg.model.Music
|
||||
* @see com.foxinmy.weixin4j.msg.model.News
|
||||
*/
|
||||
public interface Notifyable {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
不同的消息类型中的模型
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
/**
|
||||
* 标记被动消息
|
||||
*
|
||||
* @className Responseable
|
||||
* @author jy
|
||||
* @date 2014年11月22日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.msg.model.Text
|
||||
* @see com.foxinmy.weixin4j.msg.model.Image
|
||||
* @see com.foxinmy.weixin4j.msg.model.Voice
|
||||
* @see com.foxinmy.weixin4j.msg.model.Video
|
||||
* @see com.foxinmy.weixin4j.msg.model.Music
|
||||
* @see com.foxinmy.weixin4j.msg.model.News
|
||||
* @see com.foxinmy.weixin4j.msg.model.Trans
|
||||
*/
|
||||
public interface Responseable {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 文本对象
|
||||
* <p>
|
||||
* <font color="red">可用于「被动消息」「客服消息」「群发消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className Text
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
@XStreamAlias("Content")
|
||||
public class Text extends Base implements Responseable, Notifyable, Massable {
|
||||
|
||||
private static final long serialVersionUID = 520050144519064503L;
|
||||
|
||||
private String content;
|
||||
|
||||
public Text(String content) {
|
||||
super(MediaType.text);
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Text [content=" + content + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 转移到客服
|
||||
* <p>
|
||||
* <font color="red">可用于「被动消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className Trans
|
||||
* @author jy
|
||||
* @date 2014年11月21日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
@XStreamAlias("TransInfo")
|
||||
public class Trans extends Base implements Responseable {
|
||||
|
||||
private static final long serialVersionUID = -214711609286629729L;
|
||||
|
||||
// 指定会话接入的客服账号
|
||||
@XStreamAlias("KfAccount")
|
||||
private String kfAccount;
|
||||
|
||||
public Trans() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public Trans(String kfAccount) {
|
||||
super(MediaType.transfer_customer_service);
|
||||
this.kfAccount = kfAccount;
|
||||
}
|
||||
|
||||
public String getKfAccount() {
|
||||
return kfAccount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Trans [kfAccount=" + kfAccount + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 视频对象
|
||||
* <p>
|
||||
* <font color="red">可用于「被动消息」「客服消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className Video
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Video extends Base implements Responseable, Notifyable {
|
||||
|
||||
private static final long serialVersionUID = 2167437425244069128L;
|
||||
|
||||
@JSONField(name = "media_id")
|
||||
@XStreamAlias("MediaId")
|
||||
private String mediaId;
|
||||
@JSONField(name = "thumb_media_id")
|
||||
private String thumbMediaId;
|
||||
@XStreamAlias("Title")
|
||||
private String title;
|
||||
@JSONField(name = "description")
|
||||
@XStreamAlias("Description")
|
||||
private String desc;
|
||||
|
||||
public Video(String mediaId) {
|
||||
super(MediaType.video);
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
public Video(String mediaId, String thumbMediaId) {
|
||||
this(mediaId, thumbMediaId, null, null);
|
||||
}
|
||||
|
||||
public Video(String mediaId, String title, String desc) {
|
||||
this(mediaId, null, title, desc);
|
||||
}
|
||||
|
||||
public Video(String mediaId, String thumbMediaId, String title, String desc) {
|
||||
super(MediaType.video);
|
||||
this.mediaId = mediaId;
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
this.title = title;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
public String getThumbMediaId() {
|
||||
return thumbMediaId;
|
||||
}
|
||||
|
||||
public void setThumbMediaId(String thumbMediaId) {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Video [thumbMediaId=" + thumbMediaId + ", title=" + title
|
||||
+ ", desc=" + desc + ", mediaId=" + mediaId
|
||||
+ ", getMediaType()=" + getMediaType() + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.foxinmy.weixin4j.msg.model;
|
||||
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
|
||||
/**
|
||||
* 语音对象
|
||||
* <p>
|
||||
* <font color="red">可用于「被动消息」「客服消息」「群发消息」</font>
|
||||
* </p>
|
||||
*
|
||||
* @className Voice
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Voice extends Image implements Responseable, Notifyable, Massable {
|
||||
|
||||
private static final long serialVersionUID = 8853054484809101524L;
|
||||
|
||||
public Voice(String mediaId) {
|
||||
super(MediaType.voice, mediaId);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 自定义菜单类型 <br/>
|
||||
* 自定义菜单类型 </br>
|
||||
* <font color="red">scancode_push 到 location_selec
|
||||
* 仅支持微信iPhone5.4.1以上版本,和Android5 .4以上版本的微信用户 旧版本微信用户点击后将没有回应
|
||||
* 开发者也不能正常接收到事件推送。</font>
|
||||
|
||||
@@ -1,40 +1,48 @@
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 上传的媒体类型<br/>
|
||||
* 图片(image): 128K,支持JPG格式<br/>
|
||||
* 语音(voice):256K,播放长度不超过60s,支持AMR\MP3格式<br/>
|
||||
* 视频(video):1MB,支持MP4格式<br/>
|
||||
* 缩略图(thumb):64KB,支持JPG格式<br/>
|
||||
* 上传的媒体类型</br>
|
||||
* <p>
|
||||
* 公众平台上传限制:</br> 图片(image): 128K,支持JPG格式</br>
|
||||
* 语音(voice):256K,播放长度不超过60s,支持AMR\MP3格式</br> 视频(video):1MB,支持MP4格式</br>
|
||||
* 缩略图(thumb):64KB,支持JPG格式</br>
|
||||
* </p>
|
||||
* <p>
|
||||
* 企业号上传限制:</br>图片(image):1MB,支持JPG格式</br> 语音(voice):2MB,播放长度不超过60s,支持AMR格式</br>
|
||||
* 视频(video):10MB,支持MP4格式</br> 普通文件(file):10MB</br>
|
||||
* </p>
|
||||
* <p>
|
||||
* <font color='red'>媒体文件在后台保存时间为3天,即3天后media_id失效</font>
|
||||
* <p/>
|
||||
* </p>
|
||||
*
|
||||
* @author jy.hu
|
||||
* @date 2014年4月2日
|
||||
* @since JDK 1.7
|
||||
*/
|
||||
public enum MediaType {
|
||||
image("image/jpeg", "jpg"), voice("binary/octet-stream", "amr"), vedio(
|
||||
"binary/octet-stream", "mp4"), thumb("image/jpeg", "jpg"), text(
|
||||
"application/json", ""), music("binary/octet-stream", "mp3"), news(
|
||||
"application/json", ""), mpnews("application/json", ""), mpvideo(
|
||||
"binary/octet-stream", "");
|
||||
image("jpg"), voice("amr/mp3"), video("mp4"), thumb("jpg"), file("unknown"), text(
|
||||
""), music(""), news(""), mpnews(""), mpvideo(""), transfer_customer_service(
|
||||
"");
|
||||
|
||||
MediaType(String contentType, String formatType) {
|
||||
this.contentType = contentType;
|
||||
this.formatType = formatType;
|
||||
MediaType(String formatName) {
|
||||
this.formatName = formatName;
|
||||
}
|
||||
|
||||
private String contentType;
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
public static MediaType getMediaType(String key) {
|
||||
if (key.equals("jpg")) {
|
||||
return MediaType.image;
|
||||
} else if ("amr/mp3".contains(key)) {
|
||||
return MediaType.voice;
|
||||
} else if (key.equals("mp4")) {
|
||||
return MediaType.video;
|
||||
} else {
|
||||
return MediaType.file;
|
||||
}
|
||||
}
|
||||
|
||||
private String formatType;
|
||||
private String formatName;
|
||||
|
||||
public String getFormatType() {
|
||||
return formatType;
|
||||
public String getFormatName() {
|
||||
return formatName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.msg.ImageMessage;
|
||||
import com.foxinmy.weixin4j.msg.LinkMessage;
|
||||
import com.foxinmy.weixin4j.msg.LocationMessage;
|
||||
@@ -21,17 +21,13 @@ public enum MessageType {
|
||||
VoiceMessage.class), video(VideoMessage.class), location(
|
||||
LocationMessage.class), link(LinkMessage.class), event(
|
||||
EventMessage.class);
|
||||
private Class<? extends BaseMessage> messageClass;
|
||||
private Class<? extends BaseMsg> messageClass;
|
||||
|
||||
MessageType(Class<? extends BaseMessage> messageClass) {
|
||||
MessageType(Class<? extends BaseMsg> messageClass) {
|
||||
this.messageClass = messageClass;
|
||||
}
|
||||
|
||||
public void setMessageClass(Class<? extends BaseMessage> messageClass) {
|
||||
this.messageClass = messageClass;
|
||||
}
|
||||
|
||||
public Class<? extends BaseMessage> getMessageClass() {
|
||||
public Class<? extends BaseMsg> getMessageClass() {
|
||||
return messageClass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.foxinmy.weixin4j.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件工具类
|
||||
*
|
||||
* @className FileUtil
|
||||
* @author jy
|
||||
* @date 2014年11月21日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
private final static Map<String, String> FILE_TYPE_MAP = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
FILE_TYPE_MAP.put("ffd8ffe000104a464946", "jpg");
|
||||
FILE_TYPE_MAP.put("89504e470d0a1a0a0000", "png");
|
||||
FILE_TYPE_MAP.put("47494638396126026f01", "gif");
|
||||
FILE_TYPE_MAP.put("49492a00227105008037", "tif");
|
||||
FILE_TYPE_MAP.put("424d228c010000000000", "bmp"); // 16色位图(bmp)
|
||||
FILE_TYPE_MAP.put("424d8240090000000000", "bmp"); // 24位位图(bmp)
|
||||
FILE_TYPE_MAP.put("424d8e1b030000000000", "bmp"); // 256色位图(bmp)
|
||||
FILE_TYPE_MAP.put("41433130313500000000", "dwg");
|
||||
FILE_TYPE_MAP.put("3c21444f435459504520", "html");
|
||||
FILE_TYPE_MAP.put("3c21646f637479706520", "htm");
|
||||
FILE_TYPE_MAP.put("48544d4c207b0d0a0942", "css");
|
||||
FILE_TYPE_MAP.put("696b2e71623d696b2e71", "js");
|
||||
FILE_TYPE_MAP.put("7b5c727466315c616e73", "rtf");
|
||||
FILE_TYPE_MAP.put("38425053000100000000", "psd");
|
||||
FILE_TYPE_MAP.put("46726f6d3a203d3f6762", "eml");
|
||||
FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "doc"); // MS Excel、Word、Msi
|
||||
FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "vsd");
|
||||
FILE_TYPE_MAP.put("5374616E64617264204A", "mdb");
|
||||
FILE_TYPE_MAP.put("255044462d312e350d0a", "pdf");
|
||||
FILE_TYPE_MAP.put("2e524d46000000120001", "rmvb"); // rmvb、rm
|
||||
FILE_TYPE_MAP.put("464c5601050000000900", "flv"); // flv、f4v
|
||||
FILE_TYPE_MAP.put("00000020667479706d70", "mp4");
|
||||
FILE_TYPE_MAP.put("49443303000000002176", "mp3");
|
||||
FILE_TYPE_MAP.put("000001ba210001000180", "mpg");
|
||||
FILE_TYPE_MAP.put("3026b2758e66cf11a6d9", "wmv"); // wmv、asf
|
||||
FILE_TYPE_MAP.put("52494646e27807005741", "wav");
|
||||
FILE_TYPE_MAP.put("52494646d07d60074156", "avi");
|
||||
FILE_TYPE_MAP.put("4d546864000000060001", "mid");
|
||||
FILE_TYPE_MAP.put("504b0304140000000800", "zip");
|
||||
FILE_TYPE_MAP.put("526172211a0700cf9073", "rar");
|
||||
FILE_TYPE_MAP.put("235468697320636f6e66", "ini");
|
||||
FILE_TYPE_MAP.put("504b03040a0000000000", "jar");
|
||||
FILE_TYPE_MAP.put("4d5a9000030000000400", "exe");
|
||||
FILE_TYPE_MAP.put("3c25402070616765206c", "jsp");
|
||||
FILE_TYPE_MAP.put("4d616e69666573742d56", "mf");
|
||||
FILE_TYPE_MAP.put("3c3f786d6c2076657273", "xml");
|
||||
FILE_TYPE_MAP.put("494e5345525420494e54", "sql");
|
||||
FILE_TYPE_MAP.put("7061636b616765207765", "java");
|
||||
FILE_TYPE_MAP.put("406563686f206f66660d", "bat");
|
||||
FILE_TYPE_MAP.put("1f8b0800000000000000", "gz");
|
||||
FILE_TYPE_MAP.put("6c6f67346a2e726f6f74", "properties");
|
||||
FILE_TYPE_MAP.put("cafebabe0000002e0041", "class");
|
||||
FILE_TYPE_MAP.put("49545346030000006000", "chm");
|
||||
FILE_TYPE_MAP.put("04000000010000001300", "mxp");
|
||||
FILE_TYPE_MAP.put("504b0304140006000800", "docx");
|
||||
FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "wps");// WPS(wps、et、dps)
|
||||
FILE_TYPE_MAP.put("6431303a637265617465", "torrent");
|
||||
FILE_TYPE_MAP.put("6D6F6F76", "mov");
|
||||
FILE_TYPE_MAP.put("FF575043", "wpd");
|
||||
FILE_TYPE_MAP.put("CFAD12FEC5FD746F", "dbx");
|
||||
FILE_TYPE_MAP.put("2142444E", "pst");
|
||||
FILE_TYPE_MAP.put("AC9EBD8F", "qdf");
|
||||
FILE_TYPE_MAP.put("E3828596", "pwl");
|
||||
FILE_TYPE_MAP.put("2E7261FD", "ram");
|
||||
}
|
||||
|
||||
private static String bytesToHexString(byte[] src) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < src.length; i++) {
|
||||
int v = src[i] & 0xFF;
|
||||
String hv = Integer.toHexString(v);
|
||||
if (hv.length() < 2) {
|
||||
stringBuilder.append(0);
|
||||
}
|
||||
stringBuilder.append(hv);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件类型
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String getFileType(File file) {
|
||||
String fileType = "unknown";
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
byte[] b = new byte[10];
|
||||
fis.read(b, 0, b.length);
|
||||
String fileCode = bytesToHexString(b).toLowerCase();
|
||||
Iterator<String> keyIter = FILE_TYPE_MAP.keySet().iterator();
|
||||
while (keyIter.hasNext()) {
|
||||
String key = keyIter.next().toLowerCase();
|
||||
if (key.startsWith(fileCode) || fileCode.startsWith(key)) {
|
||||
fileType = FILE_TYPE_MAP.get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileType;
|
||||
}
|
||||
}
|
||||
@@ -27,13 +27,15 @@ public class IOUtil {
|
||||
return toByteArray(input, Charset.defaultCharset());
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(Reader input, Charset encoding) throws IOException {
|
||||
public static byte[] toByteArray(Reader input, Charset encoding)
|
||||
throws IOException {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
copy(input, output, encoding);
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
public static void copy(Reader input, OutputStream output, Charset encoding) throws IOException {
|
||||
public static void copy(Reader input, OutputStream output, Charset encoding)
|
||||
throws IOException {
|
||||
OutputStreamWriter out = new OutputStreamWriter(output, encoding);
|
||||
copyLarge(input, out, new char[DEFAULT_BUFFER_SIZE]);
|
||||
out.flush();
|
||||
@@ -45,7 +47,8 @@ public class IOUtil {
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
private static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException {
|
||||
private static long copyLarge(InputStream input, OutputStream output,
|
||||
byte[] buffer) throws IOException {
|
||||
long count = 0;
|
||||
int n = 0;
|
||||
while (EOF != (n = input.read(buffer))) {
|
||||
@@ -55,7 +58,8 @@ public class IOUtil {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static long copyLarge(Reader input, Writer output, char[] buffer) throws IOException {
|
||||
private static long copyLarge(Reader input, Writer output, char[] buffer)
|
||||
throws IOException {
|
||||
long count = 0;
|
||||
int n = 0;
|
||||
while (EOF != (n = input.read(buffer))) {
|
||||
@@ -64,4 +68,16 @@ public class IOUtil {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static String getExtension(String filename) {
|
||||
int extensionPos = filename.lastIndexOf(".");
|
||||
if (extensionPos < 0) {
|
||||
return "";
|
||||
}
|
||||
int lastUnixPos = filename.lastIndexOf("/");
|
||||
int lastWindowsPos = filename.lastIndexOf("\\");
|
||||
int lastSeparator = Math.max(lastUnixPos, lastWindowsPos);
|
||||
return lastSeparator > extensionPos ? "" : filename
|
||||
.substring(extensionPos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.type.EventType;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
@@ -112,14 +112,14 @@ public class MessageUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 对xml消息解密
|
||||
* 对AES消息解密
|
||||
*
|
||||
* @param appId
|
||||
* @param encodingAesKey
|
||||
* aes加密的密钥
|
||||
* @param encryptContent
|
||||
* 加密的消息体
|
||||
* @return 解密后的xml
|
||||
* @return 解密后的字符
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public static String aesDecrypt(String appId, String encodingAesKey,
|
||||
@@ -191,14 +191,14 @@ public class MessageUtil {
|
||||
* @see com.foxinmy.weixin4j.msg.event.LocationEventMessage
|
||||
* @see com.foxinmy.weixin4j.msg.event.menu.MenuEventMessage
|
||||
*/
|
||||
public static BaseMessage xml2msg(String xmlMsg) throws DocumentException {
|
||||
public static BaseMsg xml2msg(String xmlMsg) throws DocumentException {
|
||||
Document doc = DocumentHelper.parseText(xmlMsg);
|
||||
String type = doc.selectSingleNode("/xml/MsgType").getStringValue();
|
||||
if (StringUtils.isBlank(type)) {
|
||||
return null;
|
||||
}
|
||||
MessageType messageType = MessageType.valueOf(type.toLowerCase());
|
||||
Class<? extends BaseMessage> messageClass = messageType
|
||||
Class<? extends BaseMsg> messageClass = messageType
|
||||
.getMessageClass();
|
||||
if (messageType == MessageType.event) {
|
||||
type = doc.selectSingleNode("/xml/Event").getStringValue();
|
||||
@@ -217,7 +217,7 @@ public class MessageUtil {
|
||||
* @throws DocumentException
|
||||
* @see {@link com.foxinmy.weixin4j.util.MessageUtil#xml2msg(String)}
|
||||
*/
|
||||
public static BaseMessage xml2msg(InputStream inputStream)
|
||||
public static BaseMsg xml2msg(InputStream inputStream)
|
||||
throws DocumentException {
|
||||
SAXReader reader = new SAXReader();
|
||||
Document doc = reader.read(inputStream);
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Arrays;
|
||||
import org.apache.http.Consts;
|
||||
|
||||
/**
|
||||
* 提供基于PKCS7算法的加解密接口<br/>
|
||||
* 提供基于PKCS7算法的加解密接口</br>
|
||||
* 提供接收和推送给公众平台消息的加解密接口(UTF8编码的字符串).
|
||||
* <ol>
|
||||
* <li>第三方回复加密消息给公众平台</li>
|
||||
|
||||
Reference in New Issue
Block a user