【大的调整】重新定义(手贱)了「被动消息」「客服消息」「群发消息」的传输实体,另外新增了企业号「多媒体管理接口」「菜单管理接口」「发送消息接口」三个接口
This commit is contained in:
parent
5b213cd87f
commit
2ece136d46
16
README.md
16
README.md
@ -94,9 +94,23 @@ weixin4j
|
|||||||
|
|
||||||
+ **weixin4j-qy**: 新增`标签管理`接口
|
+ **weixin4j-qy**: 新增`标签管理`接口
|
||||||
|
|
||||||
|
* 2014-11-23
|
||||||
|
|
||||||
|
+ **weixin4j-base**: 新增企业号消息体以及用`Responseable`,`Notifyable`,`Massable`三个接口标记不同的可接受的消息类型
|
||||||
|
|
||||||
|
+ **weixin4j-mp**: 重新定义(手贱)了「被动消息」「客服消息」「群发消息」的传输实体
|
||||||
|
|
||||||
|
+ **weixin4j-mp**: `WeixinServerBootstrap`重命名为`WeixinMpServerBootstrap`
|
||||||
|
|
||||||
|
+ **weixin4j-qy**: 新增`多媒体管理`接口
|
||||||
|
|
||||||
|
+ **weixin4j-qy**: 新增`发送消息`接口
|
||||||
|
|
||||||
|
+ **weixin4j-qy**: 新增`菜单管理`接口
|
||||||
|
|
||||||
接下来
|
接下来
|
||||||
------
|
------
|
||||||
* 企业号API封装
|
* 企业号消息与事件
|
||||||
|
|
||||||
* 微信小店
|
* 微信小店
|
||||||
|
|
||||||
|
|||||||
1
pom.xml
1
pom.xml
@ -36,6 +36,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<weixin4j.base.version>0.0.1-SNAPSHOT</weixin4j.base.version>
|
<weixin4j.base.version>0.0.1-SNAPSHOT</weixin4j.base.version>
|
||||||
<weixin4j.mp.version>0.0.1-SNAPSHOT</weixin4j.mp.version>
|
<weixin4j.mp.version>0.0.1-SNAPSHOT</weixin4j.mp.version>
|
||||||
|
<weixin4j.qy.version>0.0.1-SNAPSHOT</weixin4j.qy.version>
|
||||||
<junit.version>4.8.2</junit.version>
|
<junit.version>4.8.2</junit.version>
|
||||||
<dom4j.version>1.6.1</dom4j.version>
|
<dom4j.version>1.6.1</dom4j.version>
|
||||||
<logback.version>1.0.9</logback.version>
|
<logback.version>1.0.9</logback.version>
|
||||||
|
|||||||
@ -29,4 +29,8 @@ weixin4j-base
|
|||||||
|
|
||||||
* 2014-11-19
|
* 2014-11-19
|
||||||
|
|
||||||
+ 新增`WeixinQyAccount`企业号账号信息类
|
+ 新增`WeixinQyAccount`企业号账号信息类
|
||||||
|
|
||||||
|
* 2014-11-23
|
||||||
|
|
||||||
|
+ 新增企业号消息体以及用`Responseable`,`Notifyable`,`Massable`三个接口标记不同的可接受的消息类型
|
||||||
@ -11,9 +11,6 @@
|
|||||||
<artifactId>weixin4j-base</artifactId>
|
<artifactId>weixin4j-base</artifactId>
|
||||||
<name>weixin4j-base</name>
|
<name>weixin4j-base</name>
|
||||||
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-base</url>
|
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-base</url>
|
||||||
<build>
|
|
||||||
<finalName>weixin4j-base</finalName>
|
|
||||||
</build>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.thoughtworks.xstream</groupId>
|
<groupId>com.thoughtworks.xstream</groupId>
|
||||||
|
|||||||
@ -12,7 +12,9 @@ import com.alibaba.fastjson.annotation.JSONField;
|
|||||||
* @date 2014年9月24日
|
* @date 2014年9月24日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see <a
|
* @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 {
|
public class JsonResult implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@ -5,13 +5,9 @@ import java.io.Serializable;
|
|||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通消息基类
|
* 消息基类
|
||||||
* <p>
|
|
||||||
* <font color="red">回复图片等多媒体消息时需要预先上传多媒体文件到微信服务器,
|
|
||||||
* 假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试</font>
|
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* @className BaseMessage
|
* @className BaseMsg
|
||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
* @date 2014年4月6日
|
* @date 2014年4月6日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
@ -26,12 +22,25 @@ public class BaseMsg implements Serializable {
|
|||||||
private String fromUserName; // 发送方帐号(一个OpenID)
|
private String fromUserName; // 发送方帐号(一个OpenID)
|
||||||
@XStreamAlias("CreateTime")
|
@XStreamAlias("CreateTime")
|
||||||
private long createTime = System.currentTimeMillis(); // 消息创建时间 (整型)
|
private long createTime = System.currentTimeMillis(); // 消息创建时间 (整型)
|
||||||
|
@XStreamAlias("MsgType")
|
||||||
|
private String msgType; // 消息类型
|
||||||
|
@XStreamAlias("MsgId")
|
||||||
|
private long msgId; // 消息ID
|
||||||
|
|
||||||
public BaseMsg() {
|
public BaseMsg() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BaseMsg(String msgType) {
|
||||||
|
this(msgType, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public BaseMsg(String toUserName, String fromUserName) {
|
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.toUserName = toUserName;
|
||||||
this.fromUserName = fromUserName;
|
this.fromUserName = fromUserName;
|
||||||
}
|
}
|
||||||
@ -59,4 +68,35 @@ public class BaseMsg implements Serializable {
|
|||||||
public void setCreateTime(long createTime) {
|
public void setCreateTime(long createTime) {
|
||||||
this.createTime = 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 + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package com.foxinmy.weixin4j.mp.model;
|
package com.foxinmy.weixin4j.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -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;
|
package com.foxinmy.weixin4j.msg;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @see <a
|
* @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>
|
* 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;
|
private static final long serialVersionUID = 8430800898756567016L;
|
||||||
|
|
||||||
public ImageMessage() {
|
public ImageMessage() {
|
||||||
super(MessageType.image);
|
super(MessageType.image.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@XStreamAlias("PicUrl")
|
@XStreamAlias("PicUrl")
|
||||||
@ -39,7 +40,7 @@ public class ImageMessage extends BaseMessage {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[ImageMessage ,toUserName=").append(super.getToUserName());
|
sb.append("[ImageMessage ,toUserName=").append(super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,picUrl=").append(picUrl);
|
||||||
sb.append(" ,mediaId=").append(mediaId);
|
sb.append(" ,mediaId=").append(mediaId);
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.msg;
|
package com.foxinmy.weixin4j.msg;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @see <a
|
* @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>
|
* 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;
|
private static final long serialVersionUID = 754952745115497030L;
|
||||||
|
|
||||||
public LinkMessage() {
|
public LinkMessage() {
|
||||||
super(MessageType.link);
|
super(MessageType.link.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@XStreamAlias("Title")
|
@XStreamAlias("Title")
|
||||||
@ -45,7 +46,7 @@ public class LinkMessage extends BaseMessage {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[LinkMessage ,toUserName=").append(super.getToUserName());
|
sb.append("[LinkMessage ,toUserName=").append(super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,title=").append(title);
|
||||||
sb.append(" ,description=").append(description);
|
sb.append(" ,description=").append(description);
|
||||||
sb.append(" ,url=").append(url);
|
sb.append(" ,url=").append(url);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.msg;
|
package com.foxinmy.weixin4j.msg;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @see <a
|
* @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>
|
* 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;
|
private static final long serialVersionUID = 2866021596599237334L;
|
||||||
|
|
||||||
public LocationMessage() {
|
public LocationMessage() {
|
||||||
super(MessageType.location);
|
super(MessageType.location.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@XStreamAlias("Location_X")
|
@XStreamAlias("Location_X")
|
||||||
@ -56,7 +57,7 @@ public class LocationMessage extends BaseMessage {
|
|||||||
sb.append("[LocationMessage ,toUserName=")
|
sb.append("[LocationMessage ,toUserName=")
|
||||||
.append(super.getToUserName());
|
.append(super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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_X=").append(x);
|
||||||
sb.append(" ,location_Y=").append(y);
|
sb.append(" ,location_Y=").append(y);
|
||||||
sb.append(" ,scale=").append(scale);
|
sb.append(" ,scale=").append(scale);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.msg;
|
package com.foxinmy.weixin4j.msg;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
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>
|
* 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
|
* @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>
|
* 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;
|
private static final long serialVersionUID = -7018053906644190260L;
|
||||||
|
|
||||||
public TextMessage() {
|
public TextMessage() {
|
||||||
super(MessageType.text);
|
super(MessageType.text.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@XStreamAlias("Content")
|
@XStreamAlias("Content")
|
||||||
@ -41,7 +40,7 @@ public class TextMessage extends BaseMessage {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[TextMessage ,toUserName=").append(super.getToUserName());
|
sb.append("[TextMessage ,toUserName=").append(super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,content=").append(content);
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||||
sb.append(" ,msgId=").append(super.getMsgId()).append("]");
|
sb.append(" ,msgId=").append(super.getMsgId()).append("]");
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.msg;
|
package com.foxinmy.weixin4j.msg;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
@ -13,12 +14,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @see <a
|
* @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>
|
* 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;
|
private static final long serialVersionUID = -1013075358679078381L;
|
||||||
|
|
||||||
public VideoMessage() {
|
public VideoMessage() {
|
||||||
super(MessageType.video);
|
super(MessageType.video.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@XStreamAlias("MediaId")
|
@XStreamAlias("MediaId")
|
||||||
@ -39,7 +40,7 @@ public class VideoMessage extends BaseMessage {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[VideoMessage ,toUserName=").append(super.getToUserName());
|
sb.append("[VideoMessage ,toUserName=").append(super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,mediaId=").append(mediaId);
|
||||||
sb.append(" ,thumbMediaId=").append(thumbMediaId);
|
sb.append(" ,thumbMediaId=").append(thumbMediaId);
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.msg;
|
package com.foxinmy.weixin4j.msg;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
@ -16,12 +17,12 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @see <a
|
* @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>
|
* 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;
|
private static final long serialVersionUID = -7988380977182214003L;
|
||||||
|
|
||||||
public VoiceMessage() {
|
public VoiceMessage() {
|
||||||
super(MessageType.voice);
|
super(MessageType.voice.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@XStreamAlias("MediaId")
|
@XStreamAlias("MediaId")
|
||||||
@ -49,7 +50,7 @@ public class VoiceMessage extends BaseMessage {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[VoiceMessage ,toUserName=").append(super.getToUserName());
|
sb.append("[VoiceMessage ,toUserName=").append(super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,mediaId=").append(mediaId);
|
||||||
sb.append(" ,format=").append(format);
|
sb.append(" ,format=").append(format);
|
||||||
sb.append(" ,recognition=").append(recognition);
|
sb.append(" ,recognition=").append(recognition);
|
||||||
|
|||||||
@ -1,24 +1,26 @@
|
|||||||
package com.foxinmy.weixin4j.msg.event;
|
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.EventType;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件消息基类
|
* 事件消息基类
|
||||||
|
*
|
||||||
* @className EventMessage
|
* @className EventMessage
|
||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
* @date 2014年4月6日
|
* @date 2014年4月6日
|
||||||
* @since JDK 1.7
|
* @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;
|
private static final long serialVersionUID = 7703667223814088865L;
|
||||||
|
|
||||||
public EventMessage(EventType eventType) {
|
public EventMessage(EventType eventType) {
|
||||||
super(MessageType.event);
|
super(MessageType.event.name());
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ public class EventMessage extends BaseMessage {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[EventMessage ,toUserName=").append(super.getToUserName());
|
sb.append("[EventMessage ,toUserName=").append(super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,eventType=").append(eventType.name());
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||||
sb.append(" ,msgId=").append(super.getMsgId()).append("]");
|
sb.append(" ,msgId=").append(super.getMsgId()).append("]");
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class LocationEventMessage extends EventMessage {
|
|||||||
sb.append("[LocationEventMessage ,toUserName=").append(
|
sb.append("[LocationEventMessage ,toUserName=").append(
|
||||||
super.getToUserName());
|
super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,eventType=").append(super.getEventType().name());
|
||||||
sb.append(" ,longitude=").append(longitude);
|
sb.append(" ,longitude=").append(longitude);
|
||||||
sb.append(" ,latitude=").append(latitude);
|
sb.append(" ,latitude=").append(latitude);
|
||||||
|
|||||||
@ -58,7 +58,7 @@ public class MassEventMessage extends EventMessage {
|
|||||||
sb.append("[MassEventMessage ,toUserName=").append(
|
sb.append("[MassEventMessage ,toUserName=").append(
|
||||||
super.getToUserName());
|
super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,eventType=").append(super.getEventType().name());
|
||||||
sb.append(" ,status=").append(status);
|
sb.append(" ,status=").append(status);
|
||||||
sb.append(" ,totalCount=").append(totalCount);
|
sb.append(" ,totalCount=").append(totalCount);
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public class ScanEventMessage extends EventMessage {
|
|||||||
sb.append("[ScanEventMessage ,toUserName=").append(
|
sb.append("[ScanEventMessage ,toUserName=").append(
|
||||||
super.getToUserName());
|
super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,eventType=").append(super.getEventType().name());
|
||||||
sb.append(" ,eventKey=").append(eventKey);
|
sb.append(" ,eventKey=").append(eventKey);
|
||||||
sb.append(" ,ticket=").append(ticket);
|
sb.append(" ,ticket=").append(ticket);
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
package com.foxinmy.weixin4j.msg.event;
|
package com.foxinmy.weixin4j.msg.event;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关注/取消关注事件
|
* 关注/取消关注事件 <font color="red">包括直接关注与扫描关注</font>
|
||||||
* <font color="red">包括直接关注与扫描关注</font>
|
*
|
||||||
* @className ScribeEventMessage
|
* @className ScribeEventMessage
|
||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
* @date 2014年4月6日
|
* @date 2014年4月6日
|
||||||
* @since JDK 1.7
|
* @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 {
|
public class ScribeEventMessage extends ScanEventMessage {
|
||||||
|
|
||||||
@ -17,9 +17,10 @@ public class ScribeEventMessage extends ScanEventMessage {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
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(" ,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(" ,eventType=").append(super.getEventType().name());
|
||||||
sb.append(" ,eventKey=").append(super.getEventKey());
|
sb.append(" ,eventKey=").append(super.getEventKey());
|
||||||
sb.append(" ,ticket=").append(super.getTicket());
|
sb.append(" ,ticket=").append(super.getTicket());
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public class MenuEventMessage extends EventMessage {
|
|||||||
sb.append("[MenuEventMessage ,toUserName=").append(
|
sb.append("[MenuEventMessage ,toUserName=").append(
|
||||||
super.getToUserName());
|
super.getToUserName());
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
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(" ,eventType=").append(super.getEventType().name());
|
||||||
sb.append(" ,eventKey=").append(eventKey);
|
sb.append(" ,eventKey=").append(eventKey);
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime());
|
sb.append(" ,createTime=").append(super.getCreateTime());
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.model;
|
package com.foxinmy.weixin4j.msg.model;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图文对象
|
* 客服消息图文
|
||||||
*
|
*
|
||||||
* @className Article
|
* @className Article
|
||||||
* @author jy
|
* @author jy
|
||||||
@ -12,15 +14,19 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public class Article extends BaseMsg {
|
public class Article implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1231352700301456395L;
|
||||||
|
|
||||||
|
@XStreamAlias("Title")
|
||||||
private String title; // 图文消息标题
|
private String title; // 图文消息标题
|
||||||
@XStreamAlias("description")
|
@JSONField(name = "description")
|
||||||
|
@XStreamAlias("Description")
|
||||||
private String desc; // 图文消息描述
|
private String desc; // 图文消息描述
|
||||||
@XStreamAlias("picurl")
|
@JSONField(name = "picurl")
|
||||||
|
@XStreamAlias("PicUrl")
|
||||||
private String picUrl; // 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
|
private String picUrl; // 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
|
||||||
|
@XStreamAlias("Url")
|
||||||
private String url; // 点击图文消息跳转链接
|
private String url; // 点击图文消息跳转链接
|
||||||
|
|
||||||
public Article(String title, String desc, String picUrl, String url) {
|
public Article(String title, String desc, String picUrl, String url) {
|
||||||
@ -67,9 +73,4 @@ public class Article extends BaseMsg {
|
|||||||
return "Article [title=" + title + ", desc=" + desc + ", picUrl="
|
return "Article [title=" + title + ", desc=" + desc + ", picUrl="
|
||||||
+ picUrl + ", url=" + url + "]";
|
+ picUrl + ", url=" + url + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaType getMediaType() {
|
|
||||||
return MediaType.mpnews;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -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 {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package com.foxinmy.weixin4j.mp.model;
|
package com.foxinmy.weixin4j.msg.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群发图文消息
|
* 群发消息图文(消息内容存储在微信后台)
|
||||||
*
|
*
|
||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
* @date 2014年4月26日
|
* @date 2014年4月26日
|
||||||
@ -28,6 +28,16 @@ public class MpArticle implements Serializable {
|
|||||||
@JSONField(name = "show_cover_pic")
|
@JSONField(name = "show_cover_pic")
|
||||||
private String showCoverPic; // 是否显示封面,1为显示,0为不显示 可为空
|
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() {
|
public String getThumbMediaId() {
|
||||||
return thumbMediaId;
|
return thumbMediaId;
|
||||||
}
|
}
|
||||||
@ -84,16 +94,6 @@ public class MpArticle implements Serializable {
|
|||||||
this.showCoverPic = showCoverPic ? "1" : "0";
|
this.showCoverPic = showCoverPic ? "1" : "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
public MpArticle(String thumbMediaId, String title, String content) {
|
|
||||||
this.thumbMediaId = thumbMediaId;
|
|
||||||
this.title = title;
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MpArticle() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@ -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 + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,14 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.model;
|
package com.foxinmy.weixin4j.msg.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import com.foxinmy.weixin4j.type.MediaType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 音乐对象
|
* 音乐对象
|
||||||
|
* <p>
|
||||||
|
* <font color="red">可用于「被动消息」「客服消息」</font>
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @className Music
|
* @className Music
|
||||||
* @author jy
|
* @author jy
|
||||||
@ -12,18 +16,23 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public class Music extends BaseMsg {
|
public class Music extends Base implements Responseable, Notifyable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = -5952134916367253297L;
|
||||||
|
|
||||||
|
@XStreamAlias("Title")
|
||||||
private String title;
|
private String title;
|
||||||
@XStreamAlias("description")
|
@JSONField(name = "description")
|
||||||
|
@XStreamAlias("Description")
|
||||||
private String desc;
|
private String desc;
|
||||||
@XStreamAlias("musicurl")
|
@JSONField(name = "musicurl")
|
||||||
|
@XStreamAlias("MusicUrl")
|
||||||
private String musicUrl;
|
private String musicUrl;
|
||||||
@XStreamAlias("hqmusicurl")
|
@JSONField(name = "hqmusicurl")
|
||||||
|
@XStreamAlias("HQMusicUrl")
|
||||||
private String hqMusicUrl;
|
private String hqMusicUrl;
|
||||||
@XStreamAlias("thumb_media_id")
|
@JSONField(name = "thumb_media_id")
|
||||||
|
@XStreamAlias("ThumbMediaId")
|
||||||
private String thumbMediaId;
|
private String thumbMediaId;
|
||||||
|
|
||||||
public Music(String thumbMediaId) {
|
public Music(String thumbMediaId) {
|
||||||
@ -32,6 +41,7 @@ public class Music extends BaseMsg {
|
|||||||
|
|
||||||
public Music(String title, String desc, String musicUrl, String hqMusicUrl,
|
public Music(String title, String desc, String musicUrl, String hqMusicUrl,
|
||||||
String thumbMediaId) {
|
String thumbMediaId) {
|
||||||
|
super(MediaType.music);
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
this.musicUrl = musicUrl;
|
this.musicUrl = musicUrl;
|
||||||
@ -85,9 +95,4 @@ public class Music extends BaseMsg {
|
|||||||
+ musicUrl + ", hqMusicUrl=" + hqMusicUrl + ", thumbMediaId="
|
+ musicUrl + ", hqMusicUrl=" + hqMusicUrl + ", thumbMediaId="
|
||||||
+ thumbMediaId + "]";
|
+ thumbMediaId + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaType getMediaType() {
|
|
||||||
return MediaType.music;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -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,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 {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,21 +1,32 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.model;
|
package com.foxinmy.weixin4j.msg.model;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import com.foxinmy.weixin4j.type.MediaType;
|
||||||
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文本对象
|
* 文本对象
|
||||||
|
* <p>
|
||||||
|
* <font color="red">可用于「被动消息」「客服消息」「群发消息」</font>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
* @className Text
|
* @className Text
|
||||||
* @author jy
|
* @author jy
|
||||||
* @date 2014年9月29日
|
* @date 2014年9月29日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public class Text extends BaseMsg {
|
@XStreamAlias("Content")
|
||||||
|
public class Text extends Base implements Responseable, Notifyable, Massable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 520050144519064503L;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
|
public Text(String content) {
|
||||||
|
super(MediaType.text);
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
@ -24,17 +35,8 @@ public class Text extends BaseMsg {
|
|||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text(String content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Text [content=" + content + "]";
|
return "Text [content=" + content + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaType getMediaType() {
|
|
||||||
return MediaType.text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -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 + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,14 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.model;
|
package com.foxinmy.weixin4j.msg.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import com.foxinmy.weixin4j.type.MediaType;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 视频对象
|
* 视频对象
|
||||||
|
* <p>
|
||||||
|
* <font color="red">可用于「被动消息」「客服消息」</font>
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @className Video
|
* @className Video
|
||||||
* @author jy
|
* @author jy
|
||||||
@ -12,20 +16,24 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public class Video extends BaseMsg {
|
public class Video extends Base implements Responseable, Notifyable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 2167437425244069128L;
|
||||||
|
|
||||||
@XStreamAlias("media_id")
|
@JSONField(name = "media_id")
|
||||||
|
@XStreamAlias("MediaId")
|
||||||
private String mediaId;
|
private String mediaId;
|
||||||
@XStreamAlias("thumb_media_id")
|
@JSONField(name = "thumb_media_id")
|
||||||
private String thumbMediaId;
|
private String thumbMediaId;
|
||||||
|
@XStreamAlias("Title")
|
||||||
private String title;
|
private String title;
|
||||||
@XStreamAlias("description")
|
@JSONField(name = "description")
|
||||||
|
@XStreamAlias("Description")
|
||||||
private String desc;
|
private String desc;
|
||||||
|
|
||||||
public Video(String mediaId) {
|
public Video(String mediaId) {
|
||||||
this(mediaId, null, null, null);
|
super(MediaType.video);
|
||||||
|
this.mediaId = mediaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Video(String mediaId, String thumbMediaId) {
|
public Video(String mediaId, String thumbMediaId) {
|
||||||
@ -37,6 +45,7 @@ public class Video extends BaseMsg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Video(String mediaId, String thumbMediaId, String title, String desc) {
|
public Video(String mediaId, String thumbMediaId, String title, String desc) {
|
||||||
|
super(MediaType.video);
|
||||||
this.mediaId = mediaId;
|
this.mediaId = mediaId;
|
||||||
this.thumbMediaId = thumbMediaId;
|
this.thumbMediaId = thumbMediaId;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
@ -77,12 +86,8 @@ public class Video extends BaseMsg {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Video [mediaId=" + mediaId + ", thumbMediaId=" + thumbMediaId
|
return "Video [thumbMediaId=" + thumbMediaId + ", title=" + title
|
||||||
+ ", title=" + title + ", desc=" + desc + "]";
|
+ ", desc=" + desc + ", mediaId=" + mediaId
|
||||||
}
|
+ ", getMediaType()=" + getMediaType() + "]";
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaType getMediaType() {
|
|
||||||
return MediaType.vedio;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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;
|
package com.foxinmy.weixin4j.type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义菜单类型 <br/>
|
* 自定义菜单类型 </br>
|
||||||
* <font color="red">scancode_push 到 location_selec
|
* <font color="red">scancode_push 到 location_selec
|
||||||
* 仅支持微信iPhone5.4.1以上版本,和Android5 .4以上版本的微信用户 旧版本微信用户点击后将没有回应
|
* 仅支持微信iPhone5.4.1以上版本,和Android5 .4以上版本的微信用户 旧版本微信用户点击后将没有回应
|
||||||
* 开发者也不能正常接收到事件推送。</font>
|
* 开发者也不能正常接收到事件推送。</font>
|
||||||
|
|||||||
@ -1,40 +1,48 @@
|
|||||||
package com.foxinmy.weixin4j.type;
|
package com.foxinmy.weixin4j.type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传的媒体类型<br/>
|
* 上传的媒体类型</br>
|
||||||
* 图片(image): 128K,支持JPG格式<br/>
|
* <p>
|
||||||
* 语音(voice):256K,播放长度不超过60s,支持AMR\MP3格式<br/>
|
* 公众平台上传限制:</br> 图片(image): 128K,支持JPG格式</br>
|
||||||
* 视频(video):1MB,支持MP4格式<br/>
|
* 语音(voice):256K,播放长度不超过60s,支持AMR\MP3格式</br> 视频(video):1MB,支持MP4格式</br>
|
||||||
* 缩略图(thumb):64KB,支持JPG格式<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>
|
* <p>
|
||||||
* <font color='red'>媒体文件在后台保存时间为3天,即3天后media_id失效</font>
|
* <font color='red'>媒体文件在后台保存时间为3天,即3天后media_id失效</font>
|
||||||
* <p/>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
* @date 2014年4月2日
|
* @date 2014年4月2日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
*/
|
*/
|
||||||
public enum MediaType {
|
public enum MediaType {
|
||||||
image("image/jpeg", "jpg"), voice("binary/octet-stream", "amr"), vedio(
|
image("jpg"), voice("amr/mp3"), video("mp4"), thumb("jpg"), file("unknown"), text(
|
||||||
"binary/octet-stream", "mp4"), thumb("image/jpeg", "jpg"), text(
|
""), music(""), news(""), mpnews(""), mpvideo(""), transfer_customer_service(
|
||||||
"application/json", ""), music("binary/octet-stream", "mp3"), news(
|
"");
|
||||||
"application/json", ""), mpnews("application/json", ""), mpvideo(
|
|
||||||
"binary/octet-stream", "");
|
|
||||||
|
|
||||||
MediaType(String contentType, String formatType) {
|
MediaType(String formatName) {
|
||||||
this.contentType = contentType;
|
this.formatName = formatName;
|
||||||
this.formatType = formatType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String contentType;
|
public static MediaType getMediaType(String key) {
|
||||||
|
if (key.equals("jpg")) {
|
||||||
public String getContentType() {
|
return MediaType.image;
|
||||||
return contentType;
|
} 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() {
|
public String getFormatName() {
|
||||||
return formatType;
|
return formatName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.type;
|
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.ImageMessage;
|
||||||
import com.foxinmy.weixin4j.msg.LinkMessage;
|
import com.foxinmy.weixin4j.msg.LinkMessage;
|
||||||
import com.foxinmy.weixin4j.msg.LocationMessage;
|
import com.foxinmy.weixin4j.msg.LocationMessage;
|
||||||
@ -21,17 +21,13 @@ public enum MessageType {
|
|||||||
VoiceMessage.class), video(VideoMessage.class), location(
|
VoiceMessage.class), video(VideoMessage.class), location(
|
||||||
LocationMessage.class), link(LinkMessage.class), event(
|
LocationMessage.class), link(LinkMessage.class), event(
|
||||||
EventMessage.class);
|
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;
|
this.messageClass = messageClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessageClass(Class<? extends BaseMessage> messageClass) {
|
public Class<? extends BaseMsg> getMessageClass() {
|
||||||
this.messageClass = messageClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<? extends BaseMessage> getMessageClass() {
|
|
||||||
return messageClass;
|
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());
|
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();
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
copy(input, output, encoding);
|
copy(input, output, encoding);
|
||||||
return output.toByteArray();
|
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);
|
OutputStreamWriter out = new OutputStreamWriter(output, encoding);
|
||||||
copyLarge(input, out, new char[DEFAULT_BUFFER_SIZE]);
|
copyLarge(input, out, new char[DEFAULT_BUFFER_SIZE]);
|
||||||
out.flush();
|
out.flush();
|
||||||
@ -45,7 +47,8 @@ public class IOUtil {
|
|||||||
return output.toByteArray();
|
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;
|
long count = 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (EOF != (n = input.read(buffer))) {
|
while (EOF != (n = input.read(buffer))) {
|
||||||
@ -55,7 +58,8 @@ public class IOUtil {
|
|||||||
return count;
|
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;
|
long count = 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (EOF != (n = input.read(buffer))) {
|
while (EOF != (n = input.read(buffer))) {
|
||||||
@ -64,4 +68,16 @@ public class IOUtil {
|
|||||||
}
|
}
|
||||||
return count;
|
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 org.dom4j.io.SAXReader;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.model.Consts;
|
import com.foxinmy.weixin4j.model.Consts;
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.foxinmy.weixin4j.type.EventType;
|
import com.foxinmy.weixin4j.type.EventType;
|
||||||
import com.foxinmy.weixin4j.type.MessageType;
|
import com.foxinmy.weixin4j.type.MessageType;
|
||||||
import com.foxinmy.weixin4j.xml.XStream;
|
import com.foxinmy.weixin4j.xml.XStream;
|
||||||
@ -112,14 +112,14 @@ public class MessageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对xml消息解密
|
* 对AES消息解密
|
||||||
*
|
*
|
||||||
* @param appId
|
* @param appId
|
||||||
* @param encodingAesKey
|
* @param encodingAesKey
|
||||||
* aes加密的密钥
|
* aes加密的密钥
|
||||||
* @param encryptContent
|
* @param encryptContent
|
||||||
* 加密的消息体
|
* 加密的消息体
|
||||||
* @return 解密后的xml
|
* @return 解密后的字符
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public static String aesDecrypt(String appId, String encodingAesKey,
|
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.LocationEventMessage
|
||||||
* @see com.foxinmy.weixin4j.msg.event.menu.MenuEventMessage
|
* @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);
|
Document doc = DocumentHelper.parseText(xmlMsg);
|
||||||
String type = doc.selectSingleNode("/xml/MsgType").getStringValue();
|
String type = doc.selectSingleNode("/xml/MsgType").getStringValue();
|
||||||
if (StringUtils.isBlank(type)) {
|
if (StringUtils.isBlank(type)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
MessageType messageType = MessageType.valueOf(type.toLowerCase());
|
MessageType messageType = MessageType.valueOf(type.toLowerCase());
|
||||||
Class<? extends BaseMessage> messageClass = messageType
|
Class<? extends BaseMsg> messageClass = messageType
|
||||||
.getMessageClass();
|
.getMessageClass();
|
||||||
if (messageType == MessageType.event) {
|
if (messageType == MessageType.event) {
|
||||||
type = doc.selectSingleNode("/xml/Event").getStringValue();
|
type = doc.selectSingleNode("/xml/Event").getStringValue();
|
||||||
@ -217,7 +217,7 @@ public class MessageUtil {
|
|||||||
* @throws DocumentException
|
* @throws DocumentException
|
||||||
* @see {@link com.foxinmy.weixin4j.util.MessageUtil#xml2msg(String)}
|
* @see {@link com.foxinmy.weixin4j.util.MessageUtil#xml2msg(String)}
|
||||||
*/
|
*/
|
||||||
public static BaseMessage xml2msg(InputStream inputStream)
|
public static BaseMsg xml2msg(InputStream inputStream)
|
||||||
throws DocumentException {
|
throws DocumentException {
|
||||||
SAXReader reader = new SAXReader();
|
SAXReader reader = new SAXReader();
|
||||||
Document doc = reader.read(inputStream);
|
Document doc = reader.read(inputStream);
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import java.util.Arrays;
|
|||||||
import org.apache.http.Consts;
|
import org.apache.http.Consts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提供基于PKCS7算法的加解密接口<br/>
|
* 提供基于PKCS7算法的加解密接口</br>
|
||||||
* 提供接收和推送给公众平台消息的加解密接口(UTF8编码的字符串).
|
* 提供接收和推送给公众平台消息的加解密接口(UTF8编码的字符串).
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>第三方回复加密消息给公众平台</li>
|
* <li>第三方回复加密消息给公众平台</li>
|
||||||
|
|||||||
@ -82,4 +82,10 @@ weixin4j-mp
|
|||||||
|
|
||||||
* 2014-11-17
|
* 2014-11-17
|
||||||
|
|
||||||
+ **weixin4j-mp-api**: 新增`冲正`和`被扫支付`接口
|
+ **weixin4j-mp-api**: 新增`冲正`和`被扫支付`接口
|
||||||
|
|
||||||
|
* 2014-11-23
|
||||||
|
|
||||||
|
+ **weixin4j-mp-api**: 重新定义(手贱)了「被动消息」「客服消息」「群发消息」的传输实体
|
||||||
|
|
||||||
|
+ **weixin4j-mp-server**: `WeixinServerBootstrap`重命名为`WeixinMpServerBootstrap`
|
||||||
@ -17,9 +17,6 @@
|
|||||||
<module>weixin4j-mp-api</module>
|
<module>weixin4j-mp-api</module>
|
||||||
<module>weixin4j-mp-server</module>
|
<module>weixin4j-mp-server</module>
|
||||||
</modules>
|
</modules>
|
||||||
<build>
|
|
||||||
<finalName>weixin4j-mp</finalName>
|
|
||||||
</build>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.foxinmy.weixin4j</groupId>
|
<groupId>com.foxinmy.weixin4j</groupId>
|
||||||
|
|||||||
@ -47,17 +47,17 @@ weixin.properties说明
|
|||||||
示例(properties中换行用右斜杆\\)
|
示例(properties中换行用右斜杆\\)
|
||||||
|
|
||||||
> account={"id":"appId","secret":"appSecret",
|
> account={"id":"appId","secret":"appSecret",
|
||||||
> "token":"开放者的token 非必须","openId":"公众号的openid 非必须",
|
> "token":"开放者的token 必须","openId":"公众号的openid 非必须",
|
||||||
> "encodingAesKey":"公众号设置了加密方式且为「安全模式」需要填入",
|
> "encodingAesKey":"公众号设置了加密方式且为「安全模式」需要填入",
|
||||||
> "mchId":"V3.x版本下的微信商户号",
|
> "mchId":"V3.x版本下的微信商户号",
|
||||||
> "partnerId":"财付通的商户号","partnerKey":"财付通商户权限密钥Key",
|
> "partnerId":"财付通的商户号","partnerKey":"财付通商户权限密钥Key",
|
||||||
> "version":"针对微信支付的版本号(2,3),如果不填则按照mchId非空与否来判断",
|
> "version":"针对微信支付的版本号(2,3),如果不填则按照mchId非空与否来判断",
|
||||||
> "paySignKey":"微信支付中调用API的密钥"} <br/>
|
> "paySignKey":"微信支付中调用API的密钥"} </br>
|
||||||
> token_path=/tmp/weixin/token <br/>
|
> token_path=/tmp/weixin/token </br>
|
||||||
> qr_path=/tmp/weixin/qr <br/>
|
> qr_path=/tmp/weixin/qr </br>
|
||||||
> media_path=/tmp/weixin/media <br/>
|
> media_path=/tmp/weixin/media </br>
|
||||||
> bill_path=/tmp/weixin/bill <br/>
|
> bill_path=/tmp/weixin/bill </br>
|
||||||
> ca_file=/tmp/weixin/xxxxx.p12 | xxxx.pfx <br/>
|
> ca_file=/tmp/weixin/xxxxx.p12 | xxxx.pfx </br>
|
||||||
|
|
||||||
2.实例化一个`WeixinProxy`对象,调用API,需要强调的是如果只传入appid,appsecret两个参数将无法调用支付相关接口
|
2.实例化一个`WeixinProxy`对象,调用API,需要强调的是如果只传入appid,appsecret两个参数将无法调用支付相关接口
|
||||||
|
|
||||||
|
|||||||
@ -13,11 +13,13 @@
|
|||||||
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-mp/weixin4j-mp-api</url>
|
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-mp/weixin4j-mp-api</url>
|
||||||
<description>微信公众号API</description>
|
<description>微信公众号API</description>
|
||||||
<build>
|
<build>
|
||||||
<finalName>weixin4j-mp-api</finalName>
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.name}</finalName>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@ -6,10 +6,10 @@ import java.io.InputStream;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.XmlResult;
|
import com.foxinmy.weixin4j.http.XmlResult;
|
||||||
|
import com.foxinmy.weixin4j.model.Button;
|
||||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||||
import com.foxinmy.weixin4j.mp.api.CustomApi;
|
import com.foxinmy.weixin4j.mp.api.CustomApi;
|
||||||
import com.foxinmy.weixin4j.mp.api.GroupApi;
|
import com.foxinmy.weixin4j.mp.api.GroupApi;
|
||||||
@ -22,27 +22,26 @@ import com.foxinmy.weixin4j.mp.api.PayApi;
|
|||||||
import com.foxinmy.weixin4j.mp.api.QrApi;
|
import com.foxinmy.weixin4j.mp.api.QrApi;
|
||||||
import com.foxinmy.weixin4j.mp.api.TmplApi;
|
import com.foxinmy.weixin4j.mp.api.TmplApi;
|
||||||
import com.foxinmy.weixin4j.mp.api.UserApi;
|
import com.foxinmy.weixin4j.mp.api.UserApi;
|
||||||
import com.foxinmy.weixin4j.mp.model.Button;
|
import com.foxinmy.weixin4j.mp.message.NotifyMessage;
|
||||||
|
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||||
import com.foxinmy.weixin4j.mp.model.CustomRecord;
|
import com.foxinmy.weixin4j.mp.model.CustomRecord;
|
||||||
import com.foxinmy.weixin4j.mp.model.Following;
|
import com.foxinmy.weixin4j.mp.model.Following;
|
||||||
import com.foxinmy.weixin4j.mp.model.Group;
|
import com.foxinmy.weixin4j.mp.model.Group;
|
||||||
import com.foxinmy.weixin4j.mp.model.KfAccount;
|
import com.foxinmy.weixin4j.mp.model.KfAccount;
|
||||||
import com.foxinmy.weixin4j.mp.model.MpArticle;
|
|
||||||
import com.foxinmy.weixin4j.mp.model.OauthToken;
|
import com.foxinmy.weixin4j.mp.model.OauthToken;
|
||||||
import com.foxinmy.weixin4j.mp.model.QRParameter;
|
import com.foxinmy.weixin4j.mp.model.QRParameter;
|
||||||
import com.foxinmy.weixin4j.mp.model.SemQuery;
|
import com.foxinmy.weixin4j.mp.model.SemQuery;
|
||||||
import com.foxinmy.weixin4j.mp.model.SemResult;
|
import com.foxinmy.weixin4j.mp.model.SemResult;
|
||||||
import com.foxinmy.weixin4j.mp.model.User;
|
import com.foxinmy.weixin4j.mp.model.User;
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Article;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.BaseMsg;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.BaseNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.payment.ApiResult;
|
import com.foxinmy.weixin4j.mp.payment.ApiResult;
|
||||||
import com.foxinmy.weixin4j.mp.payment.Refund;
|
import com.foxinmy.weixin4j.mp.payment.Refund;
|
||||||
import com.foxinmy.weixin4j.mp.payment.RefundResult;
|
import com.foxinmy.weixin4j.mp.payment.RefundResult;
|
||||||
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
||||||
import com.foxinmy.weixin4j.mp.response.TemplateMessage;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Base;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.MpArticle;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Video;
|
||||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.type.AccountType;
|
import com.foxinmy.weixin4j.type.AccountType;
|
||||||
@ -119,10 +118,20 @@ public class WeixinProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件
|
* 上传媒体文件
|
||||||
* <p>
|
*
|
||||||
* 正常情况下返回{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789},
|
* @param file
|
||||||
* 否则抛出异常.
|
* 媒体对象
|
||||||
* </p>
|
* @return 上传到微信服务器返回的媒体标识
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#uploadMedia(File, MediaType)}
|
||||||
|
* @throws WeixinException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public String uploadMedia(File file) throws WeixinException, IOException {
|
||||||
|
return mediaApi.uploadMedia(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传媒体文件
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* 文件对象
|
* 文件对象
|
||||||
@ -131,10 +140,8 @@ public class WeixinProxy {
|
|||||||
* @return 上传到微信服务器返回的媒体标识
|
* @return 上传到微信服务器返回的媒体标识
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#uploadMedia(String, byte[],String)}
|
||||||
*/
|
*/
|
||||||
public String uploadMedia(File file, MediaType mediaType)
|
public String uploadMedia(File file, MediaType mediaType)
|
||||||
throws WeixinException, IOException {
|
throws WeixinException, IOException {
|
||||||
@ -143,17 +150,24 @@ public class WeixinProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件
|
* 上传媒体文件
|
||||||
|
* <p>
|
||||||
|
* 正常情况下返回{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789},
|
||||||
|
* 否则抛出异常.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param fileName
|
||||||
|
* 文件名
|
||||||
* @param bytes
|
* @param bytes
|
||||||
* 媒体数据包
|
* 媒体数据包
|
||||||
* @param mediaType
|
* @param mediaType
|
||||||
* 媒体类型
|
* 媒体类型
|
||||||
* @return 上传到微信服务器返回的媒体标识
|
* @return 上传到微信服务器返回的媒体标识
|
||||||
* @throws WeixinException
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#uploadMedia(File, MediaType)}
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public String uploadMedia(String fileName, byte[] data, MediaType mediaType)
|
public String uploadMedia(String fileName, byte[] data, String mediaType)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
return mediaApi.uploadMedia(fileName, data, mediaType);
|
return mediaApi.uploadMedia(fileName, data, mediaType);
|
||||||
}
|
}
|
||||||
@ -175,6 +189,7 @@ public class WeixinProxy {
|
|||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#downloadMedia(String)}
|
||||||
*/
|
*/
|
||||||
public File downloadMedia(String mediaId, MediaType mediaType)
|
public File downloadMedia(String mediaId, MediaType mediaType)
|
||||||
throws WeixinException, IOException {
|
throws WeixinException, IOException {
|
||||||
@ -185,15 +200,13 @@ public class WeixinProxy {
|
|||||||
* 下载媒体文件
|
* 下载媒体文件
|
||||||
*
|
*
|
||||||
* @param mediaId
|
* @param mediaId
|
||||||
* @param mediaType
|
* 媒体ID
|
||||||
* @return 二进制数据包
|
* @return 二进制数据包
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#downloadMedia(String, MediaType)}
|
|
||||||
*/
|
*/
|
||||||
public byte[] downloadMediaData(String mediaId, MediaType mediaType)
|
public byte[] downloadMedia(String mediaId) throws WeixinException {
|
||||||
throws WeixinException {
|
return mediaApi.downloadMedia(mediaId);
|
||||||
return mediaApi.downloadMediaData(mediaId, mediaType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,57 +217,18 @@ public class WeixinProxy {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">发送客服消息</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">发送客服消息</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.TextNotify
|
* @see com.foxinmy.weixin4j.msg.model.Text
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ImageNotify
|
* @see com.foxinmy.weixin4j.msg.model.Image
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.MusicNotify
|
* @see com.foxinmy.weixin4j.msg.model.Voice
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.VideoNotify
|
* @see com.foxinmy.weixin4j.msg.model.Video
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.VoiceNotify
|
* @see com.foxinmy.weixin4j.msg.model.Music
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify
|
* @see com.foxinmy.weixin4j.msg.model.News
|
||||||
* @see com.foxinmy.weixin4j.mp.api.NotifyApi
|
* @see com.foxinmy.weixin4j.mp.api.NotifyApi
|
||||||
*/
|
*/
|
||||||
public JsonResult sendNotify(BaseNotify notify) throws WeixinException {
|
public JsonResult sendNotify(NotifyMessage notify) throws WeixinException {
|
||||||
return notifyApi.sendNotify(notify);
|
return notifyApi.sendNotify(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送图文消息
|
|
||||||
*
|
|
||||||
* @param touser
|
|
||||||
* 目标ID
|
|
||||||
* @param articles
|
|
||||||
* 图文列表
|
|
||||||
* @return 发送结果
|
|
||||||
* @throws WeixinException
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Article
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.api.NotifyApi
|
|
||||||
*/
|
|
||||||
public JsonResult sendNotify(String touser, List<Article> articles)
|
|
||||||
throws WeixinException {
|
|
||||||
return notifyApi.sendNotify(touser, articles);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送客服消息(不包含图文消息)
|
|
||||||
*
|
|
||||||
* @param touser
|
|
||||||
* 目标用户
|
|
||||||
* @param baseMsg
|
|
||||||
* 消息类型
|
|
||||||
* @return 发送结果
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Text
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Image
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Music
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Video
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Voice
|
|
||||||
* @see com.foxinmy.weixin4j.mp.api.NotifyApi
|
|
||||||
* @throws WeixinException
|
|
||||||
*/
|
|
||||||
public JsonResult sendNotify(String touser, BaseMsg baseMsg)
|
|
||||||
throws WeixinException {
|
|
||||||
return notifyApi.sendNotify(touser, baseMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客服聊天记录
|
* 客服聊天记录
|
||||||
*
|
*
|
||||||
@ -310,7 +284,7 @@ public class WeixinProxy {
|
|||||||
* 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">高级群发</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">高级群发</a>
|
||||||
* @see <a
|
* @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>
|
* 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>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MpArticle
|
* @see com.foxinmy.weixin4j.msg.model.MpArticle
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||||
*/
|
*/
|
||||||
public String uploadArticle(List<MpArticle> articles)
|
public String uploadArticle(List<MpArticle> articles)
|
||||||
@ -321,106 +295,96 @@ public class WeixinProxy {
|
|||||||
/**
|
/**
|
||||||
* 上传分组群发的视频素材
|
* 上传分组群发的视频素材
|
||||||
*
|
*
|
||||||
* @param mediaId
|
* @param video
|
||||||
* 媒体文件中上传得到的Id
|
* 视频对象 其中mediaId媒体文件中上传得到的Id 不能为空
|
||||||
* @param title
|
|
||||||
* 标题 可为空
|
|
||||||
* @param desc
|
|
||||||
* 描述 可为空
|
|
||||||
* @return 上传后的ID
|
* @return 上传后的ID
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*
|
*
|
||||||
* @see <a
|
* @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">高级群发</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">高级群发</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
* @see com.foxinmy.weixin4j.msg.model.Video
|
||||||
|
* @see com.foxinmy.weixin4j.msg.model.MpVideo
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||||
*/
|
*/
|
||||||
public String uploadVideo(String mediaId, String title, String desc)
|
public String uploadVideo(Video video) throws WeixinException {
|
||||||
throws WeixinException {
|
return massApi.uploadVideo(video);
|
||||||
return massApi.uploadVideo(mediaId, title, desc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分组群发
|
* 分组群发
|
||||||
*
|
*
|
||||||
* @param mediaId
|
* @param box
|
||||||
* 媒体ID 如果为text 则表示content
|
* 消息项
|
||||||
* @param mediaType
|
|
||||||
* 媒体类型
|
|
||||||
* @param groupId
|
* @param groupId
|
||||||
* 分组ID
|
* 分组ID
|
||||||
* @return
|
* @return 群发后的消息ID
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
* @see com.foxinmy.weixin4j.mp.model.Group
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
* @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
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroupByOpenId(String)}
|
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroupByOpenId(String)}
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroups()}
|
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroups()}
|
||||||
*/
|
*/
|
||||||
public String massByGroup(String mediaId, MediaType mediaType,
|
public String massByGroupId(Base box, int groupId) throws WeixinException {
|
||||||
String groupId) throws WeixinException {
|
return massApi.massByGroupId(box, groupId);
|
||||||
return massApi.massByGroup(mediaId, mediaType, groupId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分组群发图文消息
|
* 分组ID群发图文消息
|
||||||
*
|
*
|
||||||
* @param articles
|
* @param articles
|
||||||
* 图文消息列表
|
* 图文列表
|
||||||
* @param groupId
|
* @param openIds
|
||||||
* 分组ID
|
* openId列表
|
||||||
* @return 发送出去的消息ID
|
* @return 群发后的消息ID
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByGroupId(Base,int)}
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MpArticle
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#uploadNews(List)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByGroup(String,MediaType,String)}
|
|
||||||
*/
|
*/
|
||||||
public String massArticleByGroup(List<MpArticle> articles, String groupId)
|
public String massArticleByGroupId(List<MpArticle> articles, int groupId)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
return massApi.massArticleByGroup(articles, groupId);
|
return massApi.massArticleByGroupId(articles, groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* openId群发
|
* openId群发
|
||||||
*
|
*
|
||||||
* @param mediaId
|
* @param box
|
||||||
* 媒体ID 如果为text 则表示content
|
* 消息项
|
||||||
* @param mediaType
|
|
||||||
* 媒体类型
|
|
||||||
* @param openIds
|
* @param openIds
|
||||||
* openId列表
|
* openId列表
|
||||||
* @return
|
* @return 群发后的消息ID
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.mp.model.User
|
* @see com.foxinmy.weixin4j.mp.model.User
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
* @see com.foxinmy.weixin4j.msg.model.Text
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByOpenIds(JSONObject,String...)}
|
* @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
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.UserApi#getUser(String)}
|
||||||
*/
|
*/
|
||||||
public String massByOpenIds(String mediaId, MediaType mediaType,
|
public String massByOpenIds(Base box, String... openIds)
|
||||||
String... openIds) throws WeixinException {
|
throws WeixinException {
|
||||||
return massApi.massByOpenIds(mediaId, mediaType, openIds);
|
return massApi.massByOpenIds(box, openIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* openId图文群发
|
* 根据openid群发图文消息
|
||||||
*
|
*
|
||||||
* @param articles
|
* @param articles
|
||||||
* 图文消息列表
|
* 图文列表
|
||||||
* @param openIds
|
* @param openIds
|
||||||
* 目标ID列表
|
* openId列表
|
||||||
* @return 发送出去的消息ID
|
* @return 群发后的消息ID
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByOpenIds(Base,String...)}
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MpArticle
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.User
|
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadNews(List)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByOpenIds(String,MediaType,String...)}
|
|
||||||
*/
|
*/
|
||||||
public String massArticleByOpenIds(List<MpArticle> articles,
|
public String massArticleByOpenIds(List<MpArticle> articles,
|
||||||
String... openIds) throws WeixinException {
|
String... openIds) throws WeixinException {
|
||||||
@ -439,8 +403,8 @@ public class WeixinProxy {
|
|||||||
* @see <a
|
* @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#.E5.88.A0.E9.99.A4.E7.BE.A4.E5.8F.91">删除群发</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#.E5.88.A0.E9.99.A4.E7.BE.A4.E5.8F.91">删除群发</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByGroup(JSONObject, String)}
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByGroupId(Base, int)}
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByOpenIds(JSONObject, String...)
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByOpenIds(Base, String...)
|
||||||
*/
|
*/
|
||||||
public JsonResult deleteMassNews(String msgid) throws WeixinException {
|
public JsonResult deleteMassNews(String msgid) throws WeixinException {
|
||||||
return massApi.deleteMassNews(msgid);
|
return massApi.deleteMassNews(msgid);
|
||||||
@ -643,7 +607,7 @@ public class WeixinProxy {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3">创建自定义菜单</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3">创建自定义菜单</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
* @see com.foxinmy.weixin4j.model.Button
|
||||||
* @see com.foxinmy.weixin4j.type.ButtonType
|
* @see com.foxinmy.weixin4j.type.ButtonType
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MenuApi
|
* @see com.foxinmy.weixin4j.mp.api.MenuApi
|
||||||
*/
|
*/
|
||||||
@ -658,7 +622,7 @@ public class WeixinProxy {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E6%9F%A5%E8%AF%A2%E6%8E%A5%E5%8F%A3">查询菜单</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E6%9F%A5%E8%AF%A2%E6%8E%A5%E5%8F%A3">查询菜单</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
* @see com.foxinmy.weixin4j.model.Button
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MenuApi
|
* @see com.foxinmy.weixin4j.mp.api.MenuApi
|
||||||
*/
|
*/
|
||||||
public List<Button> getMenu() throws WeixinException {
|
public List<Button> getMenu() throws WeixinException {
|
||||||
@ -671,7 +635,7 @@ public class WeixinProxy {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%A0%E9%99%A4%E6%8E%A5%E5%8F%A3">删除菜单</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%A0%E9%99%A4%E6%8E%A5%E5%8F%A3">删除菜单</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
* @see com.foxinmy.weixin4j.model.Button
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MenuApi
|
* @see com.foxinmy.weixin4j.mp.api.MenuApi
|
||||||
*/
|
*/
|
||||||
public JsonResult deleteMenu() throws WeixinException {
|
public JsonResult deleteMenu() throws WeixinException {
|
||||||
@ -737,7 +701,7 @@ public class WeixinProxy {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%A8%A1%E6%9D%BF%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3">模板消息</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%A8%A1%E6%9D%BF%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3">模板消息</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.response.TemplateMessage
|
* @see com.foxinmy.weixin4j.mp.message.TemplateMessage
|
||||||
* @seee com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
|
* @seee com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
|
||||||
* @see com.foxinmy.weixin4j.mp.api.TmplApi
|
* @see com.foxinmy.weixin4j.mp.api.TmplApi
|
||||||
*/
|
*/
|
||||||
@ -854,11 +818,10 @@ public class WeixinProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 申请退款(V3请求需要双向证书)<br/>
|
* 申请退款(V3请求需要双向证书)</br>
|
||||||
* <p style="color:red">
|
* <p style="color:red">
|
||||||
* 交易时间超过 1 年的订单无法提交退款; <br/>
|
* 交易时间超过 1 年的订单无法提交退款; </br> 支持部分退款,部分退需要设置相同的订单号和不同的 out_refund_no。一笔退款失
|
||||||
* 支持部分退款,部分退需要设置相同的订单号和不同的 out_refund_no。一笔退款失 败后重新提交,要采用原来的
|
* 败后重新提交,要采用原来的 out_refund_no。总退款金额不能超过用户实际支付金额。</br>
|
||||||
* out_refund_no。总退款金额不能超过用户实际支付金额。<br/>
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param ca
|
* @param ca
|
||||||
@ -893,9 +856,8 @@ public class WeixinProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不同的退款接口选择<br/>
|
* 不同的退款接口选择</br> V3支付则采用properties中配置的ca文件</br>
|
||||||
* V3支付则采用properties中配置的ca文件<br/>
|
* V2支付则需要传入opUserPasswd参数</br>
|
||||||
* V2支付则需要传入opUserPasswd参数<br/>
|
|
||||||
*
|
*
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#refund(InputStream, IdQuery, String, double, double, String,String)}
|
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#refund(InputStream, IdQuery, String, double, double, String,String)}
|
||||||
*/
|
*/
|
||||||
@ -907,8 +869,7 @@ public class WeixinProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退款查询<br/>
|
* 退款查询</br> 退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款 3 个工作日后重新查询退款状态
|
||||||
* 退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款 3 个工作日后重新查询退款状态
|
|
||||||
*
|
*
|
||||||
* @param idQuery
|
* @param idQuery
|
||||||
* 单号 refund_id、out_refund_no、 out_trade_no 、 transaction_id
|
* 单号 refund_id、out_refund_no、 out_trade_no 、 transaction_id
|
||||||
@ -925,8 +886,7 @@ public class WeixinProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭订单<br/>
|
* 关闭订单</br> 当订单支付失败,调用关单接口后用新订单号重新发起支付,如果关单失败,返回已完
|
||||||
* 当订单支付失败,调用关单接口后用新订单号重新发起支付,如果关单失败,返回已完
|
|
||||||
* 成支付请按正常支付处理。如果出现银行掉单,调用关单成功后,微信后台会主动发起退款。
|
* 成支付请按正常支付处理。如果出现银行掉单,调用关单成功后,微信后台会主动发起退款。
|
||||||
*
|
*
|
||||||
* @param outTradeNo
|
* @param outTradeNo
|
||||||
|
|||||||
@ -3,14 +3,20 @@ package com.foxinmy.weixin4j.mp.api;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.mp.model.MpArticle;
|
import com.foxinmy.weixin4j.msg.model.Base;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Massable;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.MpArticle;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.MpNews;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Video;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群发相关API
|
* 群发相关API
|
||||||
@ -21,7 +27,7 @@ import com.foxinmy.weixin4j.type.MediaType;
|
|||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see <a
|
* @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">群发接口</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">群发接口</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MpArticle
|
* @see com.foxinmy.weixin4j.msg.model.MpArticle
|
||||||
*/
|
*/
|
||||||
public class MassApi extends BaseApi {
|
public class MassApi extends BaseApi {
|
||||||
|
|
||||||
@ -32,8 +38,7 @@ public class MassApi extends BaseApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传图文消息,一个图文消息支持1到10条图文<br/>
|
* 上传图文消息,一个图文消息支持1到10条图文</br> <font
|
||||||
* <font
|
|
||||||
* color="red">具备微信支付权限的公众号,在使用高级群发接口上传、群发图文消息类型时,可使用<a>标签加入外链</font>
|
* color="red">具备微信支付权限的公众号,在使用高级群发接口上传、群发图文消息类型时,可使用<a>标签加入外链</font>
|
||||||
*
|
*
|
||||||
* @param articles
|
* @param articles
|
||||||
@ -44,7 +49,7 @@ public class MassApi extends BaseApi {
|
|||||||
* 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">高级群发</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">高级群发</a>
|
||||||
* @see <a
|
* @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>
|
* 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>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MpArticle
|
* @see com.foxinmy.weixin4j.msg.model.MpArticle
|
||||||
*/
|
*/
|
||||||
public String uploadArticle(List<MpArticle> articles)
|
public String uploadArticle(List<MpArticle> articles)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
@ -62,29 +67,22 @@ public class MassApi extends BaseApi {
|
|||||||
/**
|
/**
|
||||||
* 上传分组群发的视频素材
|
* 上传分组群发的视频素材
|
||||||
*
|
*
|
||||||
* @param mediaId
|
* @param video
|
||||||
* 媒体文件中上传得到的Id
|
* 视频对象 其中mediaId媒体文件中上传得到的Id 不能为空
|
||||||
* @param title
|
* @return 上传后的ID 可用于群发视频消息
|
||||||
* 标题 可为空
|
|
||||||
* @param desc
|
|
||||||
* 描述 可为空
|
|
||||||
* @return 上传后的ID
|
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @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">高级群发</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">高级群发</a>
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
* @see com.foxinmy.weixin4j.msg.model.Video
|
||||||
|
* @see com.foxinmy.weixin4j.msg.model.MpVideo
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||||
*/
|
*/
|
||||||
public String uploadVideo(String mediaId, String title, String desc)
|
public String uploadVideo(Video video) throws WeixinException {
|
||||||
throws WeixinException {
|
|
||||||
String video_upload_uri = getRequestUri("video_upload_uri");
|
String video_upload_uri = getRequestUri("video_upload_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
obj.put("media_id", mediaId);
|
|
||||||
obj.put("title", title);
|
|
||||||
obj.put("description", desc);
|
|
||||||
Response response = request.post(
|
Response response = request.post(
|
||||||
String.format(video_upload_uri, token.getAccessToken()),
|
String.format(video_upload_uri, token.getAccessToken()),
|
||||||
obj.toJSONString());
|
JSON.toJSONString(video));
|
||||||
|
|
||||||
return response.getAsJson().getString("media_id");
|
return response.getAsJson().getString("media_id");
|
||||||
}
|
}
|
||||||
@ -96,151 +94,128 @@ public class MassApi extends BaseApi {
|
|||||||
* 如消息有时会进行审核、服务器不稳定等,此外,群发任务一般需要较长的时间才能全部发送完毕
|
* 如消息有时会进行审核、服务器不稳定等,此外,群发任务一般需要较长的时间才能全部发送完毕
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param jsonPara
|
* @param box
|
||||||
* json格式的参数
|
* 消息项
|
||||||
* @param groupId
|
* @param groupId
|
||||||
* 分组ID
|
* 分组ID
|
||||||
* @return 发送出去的消息ID
|
* @return 群发后的消息ID
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @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#.E6.A0.B9.E6.8D.AE.E5.88.86.E7.BB.84.E8.BF.9B.E8.A1.8C.E7.BE.A4.E5.8F.91">分组群发</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
* @see com.foxinmy.weixin4j.mp.model.Group
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroupByOpenId(String)}
|
* @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
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroups()}
|
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroups()}
|
||||||
*/
|
*/
|
||||||
private String massByGroup(JSONObject jsonPara, String groupId)
|
public String massByGroupId(Base box, int groupId) throws WeixinException {
|
||||||
throws WeixinException {
|
if (box instanceof MpNews) {
|
||||||
|
MpNews _news = (MpNews) box;
|
||||||
|
List<MpArticle> _articles = _news.getArticles();
|
||||||
|
if (StringUtils.isBlank(_news.getMediaId()) && _articles != null
|
||||||
|
&& !_articles.isEmpty()) {
|
||||||
|
return massArticleByGroupId(_articles, groupId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(box instanceof Massable)) {
|
||||||
|
throw new WeixinException("-1", String.format(
|
||||||
|
"%s not implement Massable", box.getClass()));
|
||||||
|
}
|
||||||
|
String msgtype = box.getMediaType().name();
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
item.put("group_id", groupId);
|
||||||
|
obj.put("filter", item);
|
||||||
|
obj.put(msgtype, JSON.toJSON(box));
|
||||||
|
obj.put("msgtype", msgtype);
|
||||||
String mass_group_uri = getRequestUri("mass_group_uri");
|
String mass_group_uri = getRequestUri("mass_group_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
Response response = request.post(
|
Response response = request.post(
|
||||||
String.format(mass_group_uri, token.getAccessToken()),
|
String.format(mass_group_uri, token.getAccessToken()),
|
||||||
jsonPara.toJSONString());
|
obj.toJSONString());
|
||||||
|
|
||||||
return response.getAsJson().getString("msg_id");
|
return response.getAsJson().getString("msg_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组ID群发图文消息
|
||||||
|
*
|
||||||
|
* @param articles
|
||||||
|
* 图文列表
|
||||||
|
* @param openIds
|
||||||
|
* openId列表
|
||||||
|
* @return 群发后的消息ID
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByGroupId(Base,int)}
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public String massArticleByGroupId(List<MpArticle> articles, int groupId)
|
||||||
|
throws WeixinException {
|
||||||
|
String mediaId = uploadArticle(articles);
|
||||||
|
return massByGroupId(new MpNews(mediaId), groupId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* openId群发
|
* openId群发
|
||||||
*
|
*
|
||||||
* @param jsonPara
|
* @param box
|
||||||
* json格式的参数
|
* 消息项
|
||||||
* @param openIds
|
* @param openIds
|
||||||
* 目标ID列表
|
* openId列表
|
||||||
* @return 发送出去的消息ID
|
* @return 群发后的消息ID
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @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#.E6.A0.B9.E6.8D.AEOpenID.E5.88.97.E8.A1.A8.E7.BE.A4.E5.8F.91">openId群发</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.User
|
* @see com.foxinmy.weixin4j.mp.model.User
|
||||||
|
* @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
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File)}
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.UserApi#getUser(String)}
|
||||||
*/
|
*/
|
||||||
private String massByOpenIds(JSONObject jsonPara, String... openIds)
|
public String massByOpenIds(Base box, String... openIds)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
|
if (box instanceof MpNews) {
|
||||||
|
MpNews _news = (MpNews) box;
|
||||||
|
List<MpArticle> _articles = _news.getArticles();
|
||||||
|
if (StringUtils.isBlank(_news.getMediaId()) && _articles != null
|
||||||
|
&& !_articles.isEmpty()) {
|
||||||
|
return massArticleByOpenIds(_articles, openIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(box instanceof Massable)) {
|
||||||
|
throw new WeixinException("-1", String.format(
|
||||||
|
"%s not implement Massable", box.getClass()));
|
||||||
|
}
|
||||||
|
String msgtype = box.getMediaType().name();
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
obj.put("touser", openIds);
|
||||||
|
obj.put(msgtype, JSON.toJSON(box));
|
||||||
|
obj.put("msgtype", msgtype);
|
||||||
String mass_openid_uri = getRequestUri("mass_openid_uri");
|
String mass_openid_uri = getRequestUri("mass_openid_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
Response response = request.post(
|
Response response = request.post(
|
||||||
String.format(mass_openid_uri, token.getAccessToken()),
|
String.format(mass_openid_uri, token.getAccessToken()),
|
||||||
jsonPara.toJSONString());
|
obj.toJSONString());
|
||||||
|
|
||||||
return response.getAsJson().getString("msg_id");
|
return response.getAsJson().getString("msg_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分组群发
|
* 根据openid群发图文消息
|
||||||
*
|
|
||||||
* @param mediaId
|
|
||||||
* 媒体ID 如果为text 则表示content
|
|
||||||
* @param mediaType
|
|
||||||
* 媒体类型
|
|
||||||
* @param groupId
|
|
||||||
* 分组ID
|
|
||||||
* @return
|
|
||||||
* @throws WeixinException
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroupByOpenId(String)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.GroupApi#getGroups()}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByGroup(JSONObject,String)}
|
|
||||||
*/
|
|
||||||
public String massByGroup(String mediaId, MediaType mediaType,
|
|
||||||
String groupId) throws WeixinException {
|
|
||||||
JSONObject jsonPara = new JSONObject();
|
|
||||||
jsonPara.put("filter", new JSONObject().put("group_id", groupId));
|
|
||||||
jsonPara.put(mediaType.name(), new JSONObject().put(
|
|
||||||
mediaType == MediaType.text ? "content" : "media_id", mediaId));
|
|
||||||
jsonPara.put("msgtype", mediaType.name());
|
|
||||||
|
|
||||||
return massByGroup(jsonPara, groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分组群发图文消息
|
|
||||||
*
|
*
|
||||||
* @param articles
|
* @param articles
|
||||||
* 图文消息列表
|
* 图文列表
|
||||||
* @param groupId
|
|
||||||
* 分组ID
|
|
||||||
* @return 发送出去的消息ID
|
|
||||||
* @throws WeixinException
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MpArticle
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#uploadNews(List)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByGroup(String,MediaType,String)}
|
|
||||||
*/
|
|
||||||
public String massArticleByGroup(List<MpArticle> articles, String groupId)
|
|
||||||
throws WeixinException {
|
|
||||||
String mediaId = uploadArticle(articles);
|
|
||||||
|
|
||||||
return massByGroup(mediaId, MediaType.mpnews, groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* openId群发
|
|
||||||
*
|
|
||||||
* @param mediaId
|
|
||||||
* 媒体ID 如果为text 则表示content
|
|
||||||
* @param mediaType
|
|
||||||
* 媒体类型
|
|
||||||
* @param openIds
|
* @param openIds
|
||||||
* openId列表
|
* openId列表
|
||||||
* @return
|
* @return 群发后的消息ID
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByOpenIds(Base,String...)}
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.mp.model.User
|
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByOpenIds(JSONObject,String...)}
|
|
||||||
*/
|
|
||||||
public String massByOpenIds(String mediaId, MediaType mediaType,
|
|
||||||
String... openIds) throws WeixinException {
|
|
||||||
JSONObject jsonPara = new JSONObject();
|
|
||||||
jsonPara.put("touser", openIds);
|
|
||||||
jsonPara.put(mediaType.name(), new JSONObject().put(
|
|
||||||
mediaType == MediaType.text ? "content" : "media_id", mediaId));
|
|
||||||
jsonPara.put("msgtype", mediaType.name());
|
|
||||||
|
|
||||||
return massByOpenIds(jsonPara, openIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* openId图文群发
|
|
||||||
*
|
|
||||||
* @param articles
|
|
||||||
* 图文消息列表
|
|
||||||
* @param openIds
|
|
||||||
* 目标ID列表
|
|
||||||
* @return 发送出去的消息ID
|
|
||||||
* @throws WeixinException
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MpArticle
|
|
||||||
* @see com.foxinmy.weixin4j.mp.model.User
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadNews(List)}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByOpenIds(String,MediaType,String...)}
|
|
||||||
*/
|
*/
|
||||||
public String massArticleByOpenIds(List<MpArticle> articles,
|
public String massArticleByOpenIds(List<MpArticle> articles,
|
||||||
String... openIds) throws WeixinException {
|
String... openIds) throws WeixinException {
|
||||||
String mediaId = uploadArticle(articles);
|
String mediaId = uploadArticle(articles);
|
||||||
|
return massByOpenIds(new MpNews(mediaId), openIds);
|
||||||
return massByOpenIds(mediaId, MediaType.mpnews, openIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,8 +229,8 @@ public class MassApi extends BaseApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @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#.E5.88.A0.E9.99.A4.E7.BE.A4.E5.8F.91">删除群发</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#.E5.88.A0.E9.99.A4.E7.BE.A4.E5.8F.91">删除群发</a>
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByGroup(JSONObject, String)}
|
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByGroup(Base, int)}
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByOpenIds(JSONObject, String...)
|
* @see {@link com.foxinmy.weixin4j.mp.api.MassApi#massByOpenIds(Base, String...)
|
||||||
*/
|
*/
|
||||||
public JsonResult deleteMassNews(String msgid) throws WeixinException {
|
public JsonResult deleteMassNews(String msgid) throws WeixinException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.entity.mime.content.ByteArrayBody;
|
import org.apache.http.entity.mime.content.ByteArrayBody;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
@ -13,6 +14,8 @@ import com.foxinmy.weixin4j.http.Response;
|
|||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import com.foxinmy.weixin4j.type.MediaType;
|
||||||
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
|
import com.foxinmy.weixin4j.util.FileUtil;
|
||||||
import com.foxinmy.weixin4j.util.IOUtil;
|
import com.foxinmy.weixin4j.util.IOUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +39,25 @@ public class MediaApi extends BaseApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件
|
* 上传媒体文件
|
||||||
* <p>
|
*
|
||||||
* 正常情况下返回{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789},
|
* @param file
|
||||||
* 否则抛出异常.
|
* 媒体对象
|
||||||
* </p>
|
* @return 上传到微信服务器返回的媒体标识
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
||||||
|
* @throws WeixinException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public String uploadMedia(File file) throws WeixinException, IOException {
|
||||||
|
String mediaTypeKey = IOUtil.getExtension(file.getName());
|
||||||
|
if (StringUtils.isBlank(mediaTypeKey)) {
|
||||||
|
mediaTypeKey = FileUtil.getFileType(file);
|
||||||
|
}
|
||||||
|
MediaType mediaType = MediaType.getMediaType(mediaTypeKey);
|
||||||
|
return uploadMedia(file, mediaType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传媒体文件
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* 文件对象
|
* 文件对象
|
||||||
@ -48,35 +66,40 @@ public class MediaApi extends BaseApi {
|
|||||||
* @return 上传到微信服务器返回的媒体标识
|
* @return 上传到微信服务器返回的媒体标识
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(String, byte[],String)}
|
||||||
*/
|
*/
|
||||||
public String uploadMedia(File file, MediaType mediaType)
|
public String uploadMedia(File file, MediaType mediaType)
|
||||||
throws WeixinException, IOException {
|
throws WeixinException, IOException {
|
||||||
byte[] datas = IOUtil.toByteArray(new FileInputStream(file));
|
byte[] datas = IOUtil.toByteArray(new FileInputStream(file));
|
||||||
return uploadMedia(file.getName(), datas, mediaType);
|
return uploadMedia(file.getName(), datas, mediaType.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件
|
* 上传媒体文件
|
||||||
|
* <p>
|
||||||
|
* 正常情况下返回{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789},
|
||||||
|
* 否则抛出异常.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param fileName
|
||||||
|
* 文件名
|
||||||
* @param bytes
|
* @param bytes
|
||||||
* 媒体数据包
|
* 媒体数据包
|
||||||
* @param mediaType
|
* @param mediaType
|
||||||
* 媒体类型
|
* 媒体类型
|
||||||
* @return 上传到微信服务器返回的媒体标识
|
* @return 上传到微信服务器返回的媒体标识
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(File, MediaType)}
|
|
||||||
*/
|
*/
|
||||||
public String uploadMedia(String fileName, byte[] bytes, MediaType mediaType)
|
public String uploadMedia(String fileName, byte[] bytes, String mediaType)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
String file_upload_uri = getRequestUri("file_upload_uri");
|
String file_upload_uri = getRequestUri("file_upload_uri");
|
||||||
Response response = request.post(String.format(file_upload_uri,
|
Response response = request.post(String.format(file_upload_uri,
|
||||||
token.getAccessToken(), mediaType.name()), new PartParameter(
|
token.getAccessToken(), mediaType), new PartParameter("media",
|
||||||
"media", new ByteArrayBody(bytes, fileName)));
|
new ByteArrayBody(bytes, fileName)));
|
||||||
|
|
||||||
return response.getAsJson().getString("media_id");
|
return response.getAsJson().getString("media_id");
|
||||||
}
|
}
|
||||||
@ -97,16 +120,17 @@ public class MediaApi extends BaseApi {
|
|||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
|
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#downloadMedia(String)}
|
||||||
*/
|
*/
|
||||||
public File downloadMedia(String mediaId, MediaType mediaType)
|
public File downloadMedia(String mediaId, MediaType mediaType)
|
||||||
throws WeixinException, IOException {
|
throws WeixinException, IOException {
|
||||||
String media_path = getRequestUri("media_path");
|
String media_path = ConfigUtil.getValue("media_path");
|
||||||
byte[] datas = downloadMediaData(mediaId, mediaType);
|
File file = new File(media_path + File.separator + mediaId + "."
|
||||||
String filename = mediaId + "." + mediaType.getFormatType();
|
+ mediaType.getFormatName());
|
||||||
File file = new File(media_path + File.separator + filename);
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
byte[] datas = downloadMedia(mediaId);
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
out.write(datas);
|
out.write(datas);
|
||||||
@ -118,13 +142,13 @@ public class MediaApi extends BaseApi {
|
|||||||
* 下载媒体文件
|
* 下载媒体文件
|
||||||
*
|
*
|
||||||
* @param mediaId
|
* @param mediaId
|
||||||
* @param mediaType
|
* 媒体ID
|
||||||
* @return 二进制数据包
|
* @return 二进制数据包
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#downloadMedia(String, MediaType)}
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6">上传下载说明</a>
|
||||||
*/
|
*/
|
||||||
public byte[] downloadMediaData(String mediaId, MediaType mediaType)
|
public byte[] downloadMedia(String mediaId) throws WeixinException {
|
||||||
throws WeixinException {
|
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
String file_download_uri = getRequestUri("file_download_uri");
|
String file_download_uri = getRequestUri("file_download_uri");
|
||||||
Response response = request.get(String.format(file_download_uri,
|
Response response = request.get(String.format(file_download_uri,
|
||||||
|
|||||||
@ -7,8 +7,8 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
|
import com.foxinmy.weixin4j.model.Button;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.mp.model.Button;
|
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
|||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
* @date 2014年9月25日
|
* @date 2014年9月25日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
* @see com.foxinmy.weixin4j.model.Button
|
||||||
*/
|
*/
|
||||||
public class MenuApi extends BaseApi {
|
public class MenuApi extends BaseApi {
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ public class MenuApi extends BaseApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3">创建自定义菜单</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3">创建自定义菜单</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
* @see com.foxinmy.weixin4j.model.Button
|
||||||
*/
|
*/
|
||||||
public JsonResult createMenu(List<Button> btnList) throws WeixinException {
|
public JsonResult createMenu(List<Button> btnList) throws WeixinException {
|
||||||
String menu_create_uri = getRequestUri("menu_create_uri");
|
String menu_create_uri = getRequestUri("menu_create_uri");
|
||||||
@ -56,7 +56,7 @@ public class MenuApi extends BaseApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E6%9F%A5%E8%AF%A2%E6%8E%A5%E5%8F%A3">查询菜单</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E6%9F%A5%E8%AF%A2%E6%8E%A5%E5%8F%A3">查询菜单</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
* @see com.foxinmy.weixin4j.model.Button
|
||||||
*/
|
*/
|
||||||
public List<Button> getMenu() throws WeixinException {
|
public List<Button> getMenu() throws WeixinException {
|
||||||
String menu_get_uri = getRequestUri("menu_get_uri");
|
String menu_get_uri = getRequestUri("menu_get_uri");
|
||||||
@ -75,7 +75,7 @@ public class MenuApi extends BaseApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%A0%E9%99%A4%E6%8E%A5%E5%8F%A3">删除菜单</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%A0%E9%99%A4%E6%8E%A5%E5%8F%A3">删除菜单</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
* @return 处理结果
|
||||||
*/
|
*/
|
||||||
public JsonResult deleteMenu() throws WeixinException {
|
public JsonResult deleteMenu() throws WeixinException {
|
||||||
String menu_delete_uri = getRequestUri("menu_delete_uri");
|
String menu_delete_uri = getRequestUri("menu_delete_uri");
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
package com.foxinmy.weixin4j.mp.api;
|
package com.foxinmy.weixin4j.mp.api;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Article;
|
import com.foxinmy.weixin4j.mp.message.NotifyMessage;
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.BaseMsg;
|
import com.foxinmy.weixin4j.msg.model.Notifyable;
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.BaseNotify;
|
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,12 +17,7 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
|||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">客服消息</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">客服消息</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.TextNotify
|
* @see com.foxinmy.weixin4j.mp.message.NotifyMessage
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ImageNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.MusicNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.VideoNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.VoiceNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify
|
|
||||||
*/
|
*/
|
||||||
public class NotifyApi extends BaseApi {
|
public class NotifyApi extends BaseApi {
|
||||||
|
|
||||||
@ -36,25 +27,6 @@ public class NotifyApi extends BaseApi {
|
|||||||
this.tokenHolder = tokenHolder;
|
this.tokenHolder = tokenHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送客服消息
|
|
||||||
*
|
|
||||||
* @param jsonPara
|
|
||||||
* @return
|
|
||||||
* @throws WeixinException
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E9.9F.B3.E4.B9.90.E6.B6.88.E6.81.AF">发送客服消息</a>
|
|
||||||
*/
|
|
||||||
private JsonResult sendNotify(String jsonPara) throws WeixinException {
|
|
||||||
String custom_notify_uri = getRequestUri("custom_notify_uri");
|
|
||||||
Token token = tokenHolder.getToken();
|
|
||||||
Response response = request.post(
|
|
||||||
String.format(custom_notify_uri, token.getAccessToken()),
|
|
||||||
jsonPara);
|
|
||||||
|
|
||||||
return response.getAsJsonResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送客服消息(在48小时内不限制发送次数)
|
* 发送客服消息(在48小时内不限制发送次数)
|
||||||
*
|
*
|
||||||
@ -63,64 +35,25 @@ public class NotifyApi extends BaseApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">发送客服消息</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">发送客服消息</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.TextNotify
|
* @see com.foxinmy.weixin4j.msg.model.Text
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ImageNotify
|
* @see com.foxinmy.weixin4j.msg.model.Image
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.MusicNotify
|
* @see com.foxinmy.weixin4j.msg.model.Voice
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.VideoNotify
|
* @see com.foxinmy.weixin4j.msg.model.Video
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.VoiceNotify
|
* @see com.foxinmy.weixin4j.msg.model.Music
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify
|
* @see com.foxinmy.weixin4j.msg.model.News
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.NotifyApi#sendNotify(String)}
|
* @see com.foxinmy.weixin4j.mp.message.NotifyMessage
|
||||||
*/
|
*/
|
||||||
public JsonResult sendNotify(BaseNotify notify) throws WeixinException {
|
public JsonResult sendNotify(NotifyMessage notify) throws WeixinException {
|
||||||
return sendNotify(notify.toJson());
|
if (!(notify.getBox() instanceof Notifyable)) {
|
||||||
}
|
throw new WeixinException("-1", String.format(
|
||||||
|
"%s not implement Notifyable", notify.getBox().getClass()));
|
||||||
|
}
|
||||||
|
String custom_notify_uri = getRequestUri("custom_notify_uri");
|
||||||
|
Token token = tokenHolder.getToken();
|
||||||
|
Response response = request.post(
|
||||||
|
String.format(custom_notify_uri, token.getAccessToken()),
|
||||||
|
notify.toJson());
|
||||||
|
|
||||||
/**
|
return response.getAsJsonResult();
|
||||||
* 发送图文消息
|
|
||||||
*
|
|
||||||
* @param touser
|
|
||||||
* 目标ID
|
|
||||||
* @param articles
|
|
||||||
* 图文列表
|
|
||||||
* @return 发送结果
|
|
||||||
* @throws WeixinException
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Article
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify
|
|
||||||
*/
|
|
||||||
public JsonResult sendNotify(String touser, List<Article> articles)
|
|
||||||
throws WeixinException {
|
|
||||||
ArticleNotify notify = new ArticleNotify(touser);
|
|
||||||
notify.pushAll(articles);
|
|
||||||
return sendNotify(notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送客服消息(不包含图文消息)
|
|
||||||
*
|
|
||||||
* @param touser
|
|
||||||
* 目标用户
|
|
||||||
* @param baseMsg
|
|
||||||
* 消息类型
|
|
||||||
* @return 发送结果
|
|
||||||
* @throws WeixinException
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Text
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Image
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Music
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Video
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Voice
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.msg.model.BaseMsg#toNotifyJson()}
|
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.NotifyApi#sendNotify(String)}
|
|
||||||
*/
|
|
||||||
public JsonResult sendNotify(String touser, BaseMsg baseMsg)
|
|
||||||
throws WeixinException {
|
|
||||||
StringBuilder jsonPara = new StringBuilder();
|
|
||||||
String mediaType = baseMsg.getMediaType().name();
|
|
||||||
jsonPara.append("{");
|
|
||||||
jsonPara.append("\"touser\":\"").append(touser).append("\",");
|
|
||||||
jsonPara.append("\"msgtype\":\"").append(mediaType).append("\",");
|
|
||||||
jsonPara.append("\"").append(mediaType).append("\":");
|
|
||||||
jsonPara.append(baseMsg.toNotifyJson()).append("}");
|
|
||||||
|
|
||||||
return sendNotify(jsonPara.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,10 +42,10 @@ import com.foxinmy.weixin4j.http.SSLHttpRequest;
|
|||||||
import com.foxinmy.weixin4j.http.XmlResult;
|
import com.foxinmy.weixin4j.http.XmlResult;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||||
|
import com.foxinmy.weixin4j.mp.converter.RefundConverter;
|
||||||
import com.foxinmy.weixin4j.mp.payment.ApiResult;
|
import com.foxinmy.weixin4j.mp.payment.ApiResult;
|
||||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||||
import com.foxinmy.weixin4j.mp.payment.Refund;
|
import com.foxinmy.weixin4j.mp.payment.Refund;
|
||||||
import com.foxinmy.weixin4j.mp.payment.RefundConverter;
|
|
||||||
import com.foxinmy.weixin4j.mp.payment.RefundResult;
|
import com.foxinmy.weixin4j.mp.payment.RefundResult;
|
||||||
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
||||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.mp.api;
|
package com.foxinmy.weixin4j.mp.api;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -11,6 +10,7 @@ import com.foxinmy.weixin4j.model.Token;
|
|||||||
import com.foxinmy.weixin4j.mp.model.QRParameter;
|
import com.foxinmy.weixin4j.mp.model.QRParameter;
|
||||||
import com.foxinmy.weixin4j.mp.type.QRType;
|
import com.foxinmy.weixin4j.mp.type.QRType;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 二维码相关API
|
* 二维码相关API
|
||||||
@ -34,9 +34,9 @@ public class QrApi extends BaseApi {
|
|||||||
* 生成带参数的二维码
|
* 生成带参数的二维码
|
||||||
*
|
*
|
||||||
* @param parameter
|
* @param parameter
|
||||||
|
* 二维码参数
|
||||||
* @return byte数据包
|
* @return byte数据包
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see {@link com.foxinmy.weixin4j.mp.api.QrApi#getQR(QRParameter)}
|
|
||||||
*/
|
*/
|
||||||
public byte[] getQRData(QRParameter parameter) throws WeixinException {
|
public byte[] getQRData(QRParameter parameter) throws WeixinException {
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
@ -78,14 +78,14 @@ public class QrApi extends BaseApi {
|
|||||||
* 二维码参数
|
* 二维码参数
|
||||||
* @return 硬盘存储的文件对象
|
* @return 硬盘存储的文件对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @throws FileNotFoundException
|
* @throws IOException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E7%94%9F%E6%88%90%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%E4%BA%8C%E7%BB%B4%E7%A0%81">二维码</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E7%94%9F%E6%88%90%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%E4%BA%8C%E7%BB%B4%E7%A0%81">二维码</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.model.QRParameter
|
* @see com.foxinmy.weixin4j.mp.model.QRParameter
|
||||||
*/
|
*/
|
||||||
public File getQR(QRParameter parameter) throws WeixinException,
|
public File getQR(QRParameter parameter) throws WeixinException,
|
||||||
IOException {
|
IOException {
|
||||||
String qr_path = getRequestUri("qr_path");
|
String qr_path = ConfigUtil.getValue("qr_path");
|
||||||
String filename = String.format("%s_%d_%d.jpg", parameter.getQrType()
|
String filename = String.format("%s_%d_%d.jpg", parameter.getQrType()
|
||||||
.name(), parameter.getSceneId(), parameter.getExpireSeconds());
|
.name(), parameter.getSceneId(), parameter.getExpireSeconds());
|
||||||
File file = new File(qr_path + File.separator + filename);
|
File file = new File(qr_path + File.separator + filename);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.mp.response.TemplateMessage;
|
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +33,7 @@ public class TmplApi extends BaseApi {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%A8%A1%E6%9D%BF%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3">模板消息</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%A8%A1%E6%9D%BF%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3">模板消息</a>
|
||||||
* @see com.foxinmy.weixin4j.mp.response.TemplateMessage
|
* @see com.foxinmy.weixin4j.mp.message.TemplateMessage
|
||||||
* @seee com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
|
* @seee com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
|
||||||
*/
|
*/
|
||||||
public JsonResult sendTmplMessage(TemplateMessage tplMessage)
|
public JsonResult sendTmplMessage(TemplateMessage tplMessage)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package com.foxinmy.weixin4j.mp.payment;
|
package com.foxinmy.weixin4j.mp.converter;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -9,6 +9,8 @@ import java.util.Map.Entry;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.mp.payment.Refund;
|
||||||
|
import com.foxinmy.weixin4j.mp.payment.RefundDetail;
|
||||||
import com.foxinmy.weixin4j.xml.XStream;
|
import com.foxinmy.weixin4j.xml.XStream;
|
||||||
import com.thoughtworks.xstream.converters.Converter;
|
import com.thoughtworks.xstream.converters.Converter;
|
||||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.foxinmy.weixin4j.mp.converter;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Text;
|
||||||
|
import com.thoughtworks.xstream.converters.SingleValueConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text回复消息转换
|
||||||
|
*
|
||||||
|
* @className TextConverter
|
||||||
|
* @author jy
|
||||||
|
* @date 2014年11月22日
|
||||||
|
* @since JDK 1.7
|
||||||
|
*/
|
||||||
|
public class TextConverter implements SingleValueConverter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canConvert(@SuppressWarnings("rawtypes") Class clazz) {
|
||||||
|
return clazz.equals(Text.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(Object obj) {
|
||||||
|
return ((Text) obj).getContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object fromString(String text) {
|
||||||
|
return new Text(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package com.foxinmy.weixin4j.mp.message;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服消息(48小时内不限制发送次数)
|
||||||
|
*
|
||||||
|
* @author jy.hu
|
||||||
|
* @date 2014年4月4日
|
||||||
|
* @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 <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">发送客服消息</a>
|
||||||
|
*/
|
||||||
|
public class NotifyMessage implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7190233634431087729L;
|
||||||
|
|
||||||
|
private String touser;
|
||||||
|
@JSONField(name = "%s")
|
||||||
|
private Base box;// 消息项
|
||||||
|
|
||||||
|
public NotifyMessage(Base box) {
|
||||||
|
this(null, box);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyMessage(String touser, Base box) {
|
||||||
|
this.touser = touser;
|
||||||
|
this.box = box;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTouser() {
|
||||||
|
return touser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTouser(String touser) {
|
||||||
|
this.touser = touser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Base getBox() {
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBox(Base box) {
|
||||||
|
this.box = box;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服消息json化
|
||||||
|
*
|
||||||
|
* @return {"touser": "to","msgtype": "text","text": {"content": "123"}}
|
||||||
|
*/
|
||||||
|
public String toJson() {
|
||||||
|
String msgtype = box.getMediaType().name();
|
||||||
|
JSONObject obj = (JSONObject) JSON.toJSON(this);
|
||||||
|
obj.put("msgtype", msgtype);
|
||||||
|
return String.format(obj.toJSONString(), msgtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "NotifyMessage [touser=" + touser + ", box=" + box + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
NotifyMessage: 客服消息
|
||||||
|
|
||||||
|
ResponseMessage: 被动消息
|
||||||
|
|
||||||
|
TemplateMessage: 模板消息
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
package com.foxinmy.weixin4j.mp.message;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
|
import com.foxinmy.weixin4j.mp.converter.TextConverter;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Article;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Base;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.News;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Responseable;
|
||||||
|
import com.foxinmy.weixin4j.util.ClassUtil;
|
||||||
|
import com.foxinmy.weixin4j.xml.XStream;
|
||||||
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 被动消息
|
||||||
|
* <p>
|
||||||
|
* <font color="red">回复图片等多媒体消息时需要预先上传多媒体文件到微信服务器,
|
||||||
|
* 假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试</font>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @className ResponseMessage
|
||||||
|
* @author jy.hu
|
||||||
|
* @date 2014年4月6日
|
||||||
|
* @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
|
||||||
|
* @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"
|
||||||
|
* >回复被动消息</a>
|
||||||
|
*/
|
||||||
|
@XStreamAlias("xml")
|
||||||
|
public class ResponseMessage extends BaseMsg {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7761192742840031607L;
|
||||||
|
|
||||||
|
protected final static XStream xmlStream = XStream.get();
|
||||||
|
static {
|
||||||
|
Class<?>[] classes = ClassUtil.getClasses(Base.class.getPackage())
|
||||||
|
.toArray(new Class[0]);
|
||||||
|
xmlStream.autodetectAnnotations(true);
|
||||||
|
xmlStream.processAnnotations(classes);
|
||||||
|
xmlStream.processAnnotations(ResponseMessage.class);
|
||||||
|
xmlStream.registerConverter(new TextConverter());
|
||||||
|
|
||||||
|
xmlStream.omitField(BaseMsg.class, "msgId");
|
||||||
|
xmlStream.alias("item", Article.class);
|
||||||
|
xmlStream.addImplicitCollection(News.class, "articles");
|
||||||
|
xmlStream.aliasSystemAttribute(null, "class");
|
||||||
|
}
|
||||||
|
private String attach; // 附加数据
|
||||||
|
private final Base box;
|
||||||
|
|
||||||
|
public ResponseMessage(Base box) {
|
||||||
|
this(box, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseMessage(Base box, BaseMsg inMessage) {
|
||||||
|
this(box, inMessage.getFromUserName(), inMessage.getToUserName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseMessage(Base box, String toUserName, String fromUserName) {
|
||||||
|
super(box.getMediaType().name(), toUserName, fromUserName);
|
||||||
|
this.box = box;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAttach() {
|
||||||
|
return attach;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Base getBox() {
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息对象转换为微信服务器接受的xml格式消息 </br> <font
|
||||||
|
* color="color">需Responseable标识,否则返回空</font>
|
||||||
|
*
|
||||||
|
* @see com.foxinmy.weixin4j.msg.model.Responseable
|
||||||
|
* @return xml字符串
|
||||||
|
*/
|
||||||
|
public String toXml() {
|
||||||
|
// check responseable
|
||||||
|
if (!(box instanceof Responseable)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String boxAlias = StringUtils.capitalize(getMsgType());
|
||||||
|
XStreamAlias alias = box.getClass().getAnnotation(XStreamAlias.class);
|
||||||
|
if (alias != null) {
|
||||||
|
boxAlias = alias.value();
|
||||||
|
}
|
||||||
|
xmlStream.aliasField(boxAlias, ResponseMessage.class, "box");
|
||||||
|
if (box instanceof News) {
|
||||||
|
attach = Integer.toString(((News) box).getArticles().size());
|
||||||
|
xmlStream.aliasField("ArticleCount", ResponseMessage.class,
|
||||||
|
"attach");
|
||||||
|
}
|
||||||
|
return xmlStream.toXML(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ResponseMessage [box=" + box + ", getToUserName()="
|
||||||
|
+ getToUserName() + ", getFromUserName()=" + getFromUserName()
|
||||||
|
+ ", getCreateTime()=" + getCreateTime() + ", getMsgType()="
|
||||||
|
+ getMsgType() + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
package com.foxinmy.weixin4j.mp.message;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -4,7 +4,6 @@ import java.io.Serializable;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.type.CustomRecordOperCode;
|
import com.foxinmy.weixin4j.mp.type.CustomRecordOperCode;
|
||||||
import com.foxinmy.weixin4j.mp.util.EntityUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客服聊天记录
|
* 客服聊天记录
|
||||||
@ -46,7 +45,7 @@ public class CustomRecord implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setOpercode(int opercode) {
|
public void setOpercode(int opercode) {
|
||||||
this.opercode = EntityUtil.getCustomRecordOperCode(opercode);
|
this.opercode = CustomRecordOperCode.getOper(opercode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getTime() {
|
public Date getTime() {
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.model;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.BaseNotify;
|
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
|
||||||
import com.foxinmy.weixin4j.util.ClassUtil;
|
|
||||||
import com.foxinmy.weixin4j.xml.XStream;
|
|
||||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
|
||||||
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
|
|
||||||
import com.thoughtworks.xstream.io.json.JsonWriter;
|
|
||||||
|
|
||||||
public abstract class BaseMsg implements Serializable {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private final static XStream xstream = new XStream(
|
|
||||||
new JsonHierarchicalStreamDriver() {
|
|
||||||
public HierarchicalStreamWriter createWriter(Writer writer) {
|
|
||||||
return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
static {
|
|
||||||
xstream.setMode(XStream.NO_REFERENCES);
|
|
||||||
xstream.autodetectAnnotations(true);
|
|
||||||
xstream.processAnnotations(ClassUtil.getClasses(
|
|
||||||
BaseNotify.class.getPackage()).toArray(new Class[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract MediaType getMediaType();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服消息json化,适用于客服消息接口
|
|
||||||
*
|
|
||||||
* @return {"touser": "to","msgtype": "text","text": {"content": "123"}}
|
|
||||||
*/
|
|
||||||
public String toNotifyJson() {
|
|
||||||
return xstream.toXML(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.model;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图片对象
|
|
||||||
*
|
|
||||||
* @className Image
|
|
||||||
* @author jy
|
|
||||||
* @date 2014年9月29日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see
|
|
||||||
*/
|
|
||||||
public class Image extends BaseMsg {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@XStreamAlias("media_id")
|
|
||||||
private String mediaId;
|
|
||||||
|
|
||||||
public Image(String mediaId) {
|
|
||||||
this.mediaId = mediaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMediaId() {
|
|
||||||
return mediaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMediaId(String mediaId) {
|
|
||||||
this.mediaId = mediaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaType getMediaType() {
|
|
||||||
return MediaType.image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.model;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 语音对象
|
|
||||||
*
|
|
||||||
* @className Image
|
|
||||||
* @author jy
|
|
||||||
* @date 2014年9月29日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see
|
|
||||||
*/
|
|
||||||
public class Voice extends BaseMsg {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@XStreamAlias("media_id")
|
|
||||||
private String mediaId;
|
|
||||||
|
|
||||||
public Voice(String mediaId) {
|
|
||||||
this.mediaId = mediaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMediaId() {
|
|
||||||
return mediaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMediaId(String mediaId) {
|
|
||||||
this.mediaId = mediaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaType getMediaType() {
|
|
||||||
return MediaType.voice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,102 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.notify;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Article;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服图文消息
|
|
||||||
*
|
|
||||||
* @className ArticleNotify
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月6日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E5.9B.BE.E6.96.87.E6.B6.88.E6.81.AF">客服图文消息</a>
|
|
||||||
* @see com.foxinmy.weixin.msg.model.Article
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify#toJson()
|
|
||||||
*/
|
|
||||||
public class ArticleNotify extends BaseNotify {
|
|
||||||
private static final int MAX_ARTICLE_COUNT = 10;
|
|
||||||
private static final long serialVersionUID = 1740696901128709998L;
|
|
||||||
|
|
||||||
public ArticleNotify() {
|
|
||||||
this(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArticleNotify(String touser) {
|
|
||||||
super(touser, ResponseType.news);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("news")
|
|
||||||
private News news;
|
|
||||||
|
|
||||||
@XStreamOmitField
|
|
||||||
private int count; // 图文消息个数,限制为10条以内
|
|
||||||
|
|
||||||
public void pushArticle(String title, String desc, String picUrl, String url) {
|
|
||||||
if ((count + 1) > MAX_ARTICLE_COUNT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.news == null) {
|
|
||||||
this.news = new News();
|
|
||||||
}
|
|
||||||
this.news.pushArticle(title, desc, picUrl, url);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushAll(List<Article> articles) {
|
|
||||||
count = articles.size();
|
|
||||||
if (articles.size() > MAX_ARTICLE_COUNT) {
|
|
||||||
count = MAX_ARTICLE_COUNT;
|
|
||||||
articles = articles.subList(0, count);
|
|
||||||
}
|
|
||||||
if (this.news == null) {
|
|
||||||
this.news = new News();
|
|
||||||
}
|
|
||||||
this.news.setArticles(articles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class News {
|
|
||||||
@XStreamAlias("articles")
|
|
||||||
private List<Article> articles;
|
|
||||||
|
|
||||||
public News() {
|
|
||||||
this.articles = new LinkedList<Article>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushArticle(String title, String desc, String picUrl,
|
|
||||||
String url) {
|
|
||||||
this.articles.add(new Article(title, desc, picUrl, url));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArticles(List<Article> articles) {
|
|
||||||
this.articles = 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format(
|
|
||||||
"[ArticleNotify touser=%s ,msgtype=%s ,articles=%s]",
|
|
||||||
super.getTouser(), super.getMsgtype().name(),
|
|
||||||
this.news.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.notify;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.util.ClassUtil;
|
|
||||||
import com.foxinmy.weixin4j.xml.XStream;
|
|
||||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
|
||||||
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
|
|
||||||
import com.thoughtworks.xstream.io.json.JsonWriter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服消息基类(48小时内不限制发送次数)
|
|
||||||
*
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月4日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF">发送客服消息</a>
|
|
||||||
*/
|
|
||||||
public class BaseNotify implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7190233634431087729L;
|
|
||||||
|
|
||||||
private final static XStream jsonStream = new XStream(
|
|
||||||
new JsonHierarchicalStreamDriver() {
|
|
||||||
public HierarchicalStreamWriter createWriter(Writer writer) {
|
|
||||||
return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
static {
|
|
||||||
Class<?>[] classes = ClassUtil
|
|
||||||
.getClasses(BaseNotify.class.getPackage())
|
|
||||||
.toArray(new Class[0]);
|
|
||||||
|
|
||||||
jsonStream.setMode(XStream.NO_REFERENCES);
|
|
||||||
jsonStream.autodetectAnnotations(true);
|
|
||||||
jsonStream.processAnnotations(classes);
|
|
||||||
}
|
|
||||||
private String touser;
|
|
||||||
private ResponseType msgtype;
|
|
||||||
|
|
||||||
public BaseNotify(ResponseType msgtype) {
|
|
||||||
this.msgtype = msgtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseNotify(String touser, ResponseType msgtype) {
|
|
||||||
this.touser = touser;
|
|
||||||
this.msgtype = msgtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTouser() {
|
|
||||||
return touser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTouser(String touser) {
|
|
||||||
this.touser = touser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseType getMsgtype() {
|
|
||||||
return msgtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMsgtype(ResponseType msgtype) {
|
|
||||||
this.msgtype = msgtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服消息json化
|
|
||||||
*
|
|
||||||
* @return {"touser": "to","msgtype": "text","text": {"content": "123"}}
|
|
||||||
*/
|
|
||||||
public String toJson() {
|
|
||||||
return jsonStream.toXML(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[BaseNotify touser=%s ,msgtype=%s]", touser,
|
|
||||||
msgtype.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.notify;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Image;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服图片消息
|
|
||||||
*
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月4日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E5.9B.BE.E7.89.87.E6.B6.88.E6.81.AF">客服图片消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Image
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify#toJson()
|
|
||||||
*/
|
|
||||||
public class ImageNotify extends BaseNotify {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7698823863398518425L;
|
|
||||||
|
|
||||||
public ImageNotify() {
|
|
||||||
this(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageNotify(String touser) {
|
|
||||||
this(null, touser);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageNotify(String mediaId, String touser) {
|
|
||||||
super(touser, ResponseType.image);
|
|
||||||
this.pushMediaId(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushMediaId(String mediaId) {
|
|
||||||
this.image = new Image(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Image image;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[ImageNotify touser=%s ,msgtype=%s ,mediaId=%s]",
|
|
||||||
super.getTouser(), super.getMsgtype().name(),
|
|
||||||
this.image.getMediaId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.notify;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Music;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服音乐消息
|
|
||||||
*
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月4日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E9.9F.B3.E4.B9.90.E6.B6.88.E6.81.AF">客服音乐消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Music
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify#toJson()
|
|
||||||
*/
|
|
||||||
public class MusicNotify extends BaseNotify {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7698823863398518425L;
|
|
||||||
|
|
||||||
public MusicNotify() {
|
|
||||||
this(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MusicNotify(String touser) {
|
|
||||||
super(touser, ResponseType.music);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushMusic(String musicurl, String hqUrl, String mediaId) {
|
|
||||||
this.music = new Music(null, null, musicurl, hqUrl, mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Music music;
|
|
||||||
|
|
||||||
public void setMusic(Music music) {
|
|
||||||
this.music = music;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[MusicNotify touser=%s ,msgtype=%s ,music=%s]",
|
|
||||||
super.getTouser(), super.getMsgtype().name(),
|
|
||||||
this.music.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
客服消息
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.notify;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Text;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服文本消息
|
|
||||||
*
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月4日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E6.96.87.E6.9C.AC.E6.B6.88.E6.81.AF">客服文本消息</a>
|
|
||||||
* @see com.foxinmy.weixin.msg.model.Text
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify#toJson()
|
|
||||||
*/
|
|
||||||
public class TextNotify extends BaseNotify {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7698823863398518425L;
|
|
||||||
|
|
||||||
public TextNotify() {
|
|
||||||
this(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextNotify(String content) {
|
|
||||||
this(content,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextNotify(String content, String touser) {
|
|
||||||
super(touser, ResponseType.text);
|
|
||||||
this.text = new Text(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(String content) {
|
|
||||||
this.text = new Text(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Text text;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[TextNotify touser=%s ,msgtype=%s ,content=%s]",
|
|
||||||
super.getTouser(), super.getMsgtype().name(),
|
|
||||||
this.text.getContent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.notify;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Video;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服视频消息
|
|
||||||
*
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月4日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E8.A7.86.E9.A2.91.E6.B6.88.E6.81.AF">客服视频消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Video
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify#toJson()
|
|
||||||
*/
|
|
||||||
public class VideoNotify extends BaseNotify {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7698823863398518425L;
|
|
||||||
|
|
||||||
public VideoNotify() {
|
|
||||||
this(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VideoNotify(String touser) {
|
|
||||||
super(touser, ResponseType.video);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushVideo(String mediaId, String thumbMediaId) {
|
|
||||||
this.video = new Video(mediaId, thumbMediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Video video;
|
|
||||||
|
|
||||||
public void setVideo(Video video) {
|
|
||||||
this.video = video;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[VideoNotify touser=%s ,msgtype=%s ,video=%s]",
|
|
||||||
super.getTouser(), super.getMsgtype().name(),
|
|
||||||
this.video.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.msg.notify;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Voice;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客服语音消息
|
|
||||||
*
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月4日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E8.AF.AD.E9.9F.B3.E6.B6.88.E6.81.AF">客服语音消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Voice
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.notify.BaseNotify#toJson()
|
|
||||||
*/
|
|
||||||
public class VoiceNotify extends BaseNotify {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7698823863398518425L;
|
|
||||||
|
|
||||||
public VoiceNotify() {
|
|
||||||
this(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VoiceNotify(String touser) {
|
|
||||||
this(null, touser);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VoiceNotify(String mediaId, String touser) {
|
|
||||||
super(touser, ResponseType.voice);
|
|
||||||
this.pushMediaId(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushMediaId(String mediaId) {
|
|
||||||
this.voice = new Voice(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Voice voice;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[VoiceNotify touser=%s ,msgtype=%s ,mediaId=%s]",
|
|
||||||
super.getTouser(), super.getMsgtype().name(),
|
|
||||||
this.voice.getMediaId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -79,16 +79,16 @@ public class PayAction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* JSAPI(V2)支付成功(前端)时的回调通知<br>
|
* JSAPI(V2)支付成功(前端)时的回调通知<br>
|
||||||
* <xml><br/>
|
* <xml></br>
|
||||||
* <OpenId><![CDATA[111222]]></OpenId><br/>
|
* <OpenId><![CDATA[111222]]></OpenId></br>
|
||||||
* <AppId><![CDATA[wwwwb4f85f3a797777]]></AppId><br/>
|
* <AppId><![CDATA[wwwwb4f85f3a797777]]></AppId></br>
|
||||||
* <IsSubscribe>1</IsSubscribe><br/>
|
* <IsSubscribe>1</IsSubscribe></br>
|
||||||
* <TimeStamp>1369743511</TimeStamp><br/>
|
* <TimeStamp>1369743511</TimeStamp></br>
|
||||||
* <NonceStr><![CDATA[jALldRTHAFd5Tgs5]]></NonceStr><br/>
|
* <NonceStr><![CDATA[jALldRTHAFd5Tgs5]]></NonceStr></br>
|
||||||
* <AppSignature><![CDATA[bafe07f060f22dcda0bfdb4b5ff756f973aecffa]]>
|
* <AppSignature><![CDATA[bafe07f060f22dcda0bfdb4b5ff756f973aecffa]]>
|
||||||
* </AppSignature><br/>
|
* </AppSignature></br>
|
||||||
* <SignMethod><![CDATA[sha1]]></SignMethod><br/>
|
* <SignMethod><![CDATA[sha1]]></SignMethod></br>
|
||||||
* </xml><br/>
|
* </xml></br>
|
||||||
* 参与签名的字段为: appid、appkey、timestamp、noncestr、openid、issubscribe
|
* 参与签名的字段为: appid、appkey、timestamp、noncestr、openid、issubscribe
|
||||||
*
|
*
|
||||||
* @param 订单信息
|
* @param 订单信息
|
||||||
@ -165,17 +165,17 @@ public class PayAction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* V2.x版本Native支付时POST数据<br>
|
* V2.x版本Native支付时POST数据<br>
|
||||||
* <xml><br/>
|
* <xml></br>
|
||||||
* <OpenId><![CDATA[111222]]></OpenId><br/>
|
* <OpenId><![CDATA[111222]]></OpenId></br>
|
||||||
* <AppId><![CDATA[wwwwb4f85f3a797777]]></AppId><br/>
|
* <AppId><![CDATA[wwwwb4f85f3a797777]]></AppId></br>
|
||||||
* <IsSubscribe>1</IsSubscribe><br/>
|
* <IsSubscribe>1</IsSubscribe></br>
|
||||||
* <ProductId>[CDATA[000000]]</ProductId><br/>
|
* <ProductId>[CDATA[000000]]</ProductId></br>
|
||||||
* <TimeStamp>1369743511</TimeStamp><br/>
|
* <TimeStamp>1369743511</TimeStamp></br>
|
||||||
* <NonceStr><![CDATA[jALldRTHAFd5Tgs5]]></NonceStr><br/>
|
* <NonceStr><![CDATA[jALldRTHAFd5Tgs5]]></NonceStr></br>
|
||||||
* <AppSignature><![CDATA[bafe07f060f22dcda0bfdb4b5ff756f973aecffa]]>
|
* <AppSignature><![CDATA[bafe07f060f22dcda0bfdb4b5ff756f973aecffa]]>
|
||||||
* </AppSignature><br/>
|
* </AppSignature></br>
|
||||||
* <SignMethod><![CDATA[sha1]]></SignMethod><br/>
|
* <SignMethod><![CDATA[sha1]]></SignMethod></br>
|
||||||
* </xml><br/>
|
* </xml></br>
|
||||||
* 参与签名的字段为: appid、appkey、timestamp、noncestr、openid、issubscribe、productId
|
* 参与签名的字段为: appid、appkey、timestamp、noncestr、openid、issubscribe、productId
|
||||||
*
|
*
|
||||||
* @param inputStream
|
* @param inputStream
|
||||||
@ -208,16 +208,16 @@ public class PayAction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* V3.x版本native回调<br>
|
* V3.x版本native回调<br>
|
||||||
* <xml><br/>
|
* <xml></br>
|
||||||
* <openid><![CDATA[111222]]></openid><br/>
|
* <openid><![CDATA[111222]]></openid></br>
|
||||||
* <appid><![CDATA[wwwwb4f85f3a797777]]></appid><br/>
|
* <appid><![CDATA[wwwwb4f85f3a797777]]></appid></br>
|
||||||
* <mch_id><![CDATA[1100022]]></mch_id><br/>
|
* <mch_id><![CDATA[1100022]]></mch_id></br>
|
||||||
* <is_subscribe>1</is_subscribe><br/>
|
* <is_subscribe>1</is_subscribe></br>
|
||||||
* <product_id>[CDATA[000000]]</product_id><br/>
|
* <product_id>[CDATA[000000]]</product_id></br>
|
||||||
* <nonce_str><![CDATA[jALldRTHAFd5Tgs5]]></nonce_str><br/>
|
* <nonce_str><![CDATA[jALldRTHAFd5Tgs5]]></nonce_str></br>
|
||||||
* <sign><![CDATA[bafe07f060f22dcda0bfdb4b5ff756f973aecffa]]></sign&
|
* <sign><![CDATA[bafe07f060f22dcda0bfdb4b5ff756f973aecffa]]></sign&
|
||||||
* gt<br/>
|
* gt</br>
|
||||||
* </xml><br/>
|
* </xml></br>
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* @throws PayException
|
* @throws PayException
|
||||||
@ -251,17 +251,17 @@ public class PayAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 告警通知 需要成功返回 success <br/>
|
* 告警通知 需要成功返回 success </br>
|
||||||
* <xml><br/>
|
* <xml></br>
|
||||||
* <AppId><![CDATA[wxf8b4f85f3a794e77]]></AppId><br/>
|
* <AppId><![CDATA[wxf8b4f85f3a794e77]]></AppId></br>
|
||||||
* <ErrorType>1001</ErrorType><br/>
|
* <ErrorType>1001</ErrorType></br>
|
||||||
* <Description><![CDATA[错误描述]]></Description><br/>
|
* <Description><![CDATA[错误描述]]></Description></br>
|
||||||
* <AlarmContent><![CDATA[错误详情]]></AlarmContent><br/>
|
* <AlarmContent><![CDATA[错误详情]]></AlarmContent></br>
|
||||||
* <TimeStamp>1393860740</TimeStamp><br/>
|
* <TimeStamp>1393860740</TimeStamp></br>
|
||||||
* <AppSignature><![CDATA[签名方式跟JsPayRequest中的paySign一样]]></
|
* <AppSignature><![CDATA[签名方式跟JsPayRequest中的paySign一样]]></
|
||||||
* AppSignature><br/>
|
* AppSignature></br>
|
||||||
* <SignMethod><![CDATA[sha1]]></SignMethod><br/>
|
* <SignMethod><![CDATA[sha1]]></SignMethod></br>
|
||||||
* </xml><br/>
|
* </xml></br>
|
||||||
* 参与签名字段:alarmcontent、appid、appkey、description、errortype、timestamp
|
* 参与签名字段:alarmcontent、appid、appkey、description、errortype、timestamp
|
||||||
*
|
*
|
||||||
* @param inputStream
|
* @param inputStream
|
||||||
|
|||||||
@ -211,16 +211,16 @@ public class PayUtil {
|
|||||||
* 生成编辑地址请求
|
* 生成编辑地址请求
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* err_msg edit_address:ok获取编辑收货地址成功<br/>
|
* err_msg edit_address:ok获取编辑收货地址成功</br>
|
||||||
* edit_address:fail获取编辑收货地址失败<br/>
|
* edit_address:fail获取编辑收货地址失败</br>
|
||||||
* userName 收货人姓名<br/>
|
* userName 收货人姓名</br>
|
||||||
* telNumber 收货人电话<br/>
|
* telNumber 收货人电话</br>
|
||||||
* addressPostalCode 邮编<br/>
|
* addressPostalCode 邮编</br>
|
||||||
* proviceFirstStageName 国标收货地址第一级地址<br/>
|
* proviceFirstStageName 国标收货地址第一级地址</br>
|
||||||
* addressCitySecondStageName 国标收货地址第二级地址<br/>
|
* addressCitySecondStageName 国标收货地址第二级地址</br>
|
||||||
* addressCountiesThirdStageName 国标收货地址第三级地址<br/>
|
* addressCountiesThirdStageName 国标收货地址第三级地址</br>
|
||||||
* addressDetailInfo 详细收货地址信息<br/>
|
* addressDetailInfo 详细收货地址信息</br>
|
||||||
* nationalCode 收货地址国家码<br/>
|
* nationalCode 收货地址国家码</br>
|
||||||
*
|
*
|
||||||
* @param appId
|
* @param appId
|
||||||
* 公众号的ID
|
* 公众号的ID
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import com.foxinmy.weixin4j.mp.payment.PayRequest;
|
|||||||
import com.foxinmy.weixin4j.util.MapUtil;
|
import com.foxinmy.weixin4j.util.MapUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信JS支付:get_brand_wcpay_request<br/>
|
* 微信JS支付:get_brand_wcpay_request</br>
|
||||||
* <font color="red">所列参数均为非空字符串</font>
|
* <font color="red">所列参数均为非空字符串</font>
|
||||||
* <p>
|
* <p>
|
||||||
* get_brand_wcpay_request:ok 支付成功<br>
|
* get_brand_wcpay_request:ok 支付成功<br>
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
|||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* V3支付的订单详情<br/>
|
* V3支付的订单详情</br>
|
||||||
* 注意: <font color="red">total_fee字段传入时单位为元,创建支付时会转换为分</font>
|
* 注意: <font color="red">total_fee字段传入时单位为元,创建支付时会转换为分</font>
|
||||||
*
|
*
|
||||||
* @className PayPackageV3
|
* @className PayPackageV3
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.mp.payment.PayRequest;
|
|||||||
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JS支付:get_brand_wcpay_request<br/>
|
* JS支付:get_brand_wcpay_request</br>
|
||||||
* <p>
|
* <p>
|
||||||
* get_brand_wcpay_request:ok 支付成功<br>
|
* get_brand_wcpay_request:ok 支付成功<br>
|
||||||
* get_brand_wcpay_request:cancel 支付过程中用户取消<br>
|
* get_brand_wcpay_request:cancel 支付过程中用户取消<br>
|
||||||
|
|||||||
@ -1,103 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Article;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 回复图文消息
|
|
||||||
*
|
|
||||||
* @className ArticleResponse
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年3月23日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @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.E5.9B.BE.E6.96.87.E6.B6.88.E6.81.AF">回复图文消息</a>
|
|
||||||
* @see com.foxinmy.weixin.msg.model.Article
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
|
||||||
*/
|
|
||||||
@XStreamAlias("xml")
|
|
||||||
public class ArticleResponse extends BaseResponse {
|
|
||||||
private static final int MAX_ARTICLE_COUNT = 10;
|
|
||||||
private static final long serialVersionUID = -7331603018352309317L;
|
|
||||||
|
|
||||||
public ArticleResponse(BaseMessage inMessage) {
|
|
||||||
super(ResponseType.news, inMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("ArticleCount")
|
|
||||||
private int count; // 图文消息个数,限制为10条以内
|
|
||||||
@XStreamAlias("Articles")
|
|
||||||
private LinkedList<Article> articles;
|
|
||||||
|
|
||||||
public void pushArticle(String title, String desc, String picUrl, String url) {
|
|
||||||
if (this.articles == null) {
|
|
||||||
this.articles = new LinkedList<Article>();
|
|
||||||
}
|
|
||||||
if ((articles.size() + 1) > MAX_ARTICLE_COUNT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.articles.add(new Article(title, desc, picUrl, url));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushFirstArticle(String title, String desc, String picUrl,
|
|
||||||
String url) {
|
|
||||||
if (this.articles == null) {
|
|
||||||
this.articles = new LinkedList<Article>();
|
|
||||||
}
|
|
||||||
this.articles.addFirst(new Article(title, desc, picUrl, url));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushLastArticle(String title, String desc, String picUrl,
|
|
||||||
String url) {
|
|
||||||
if (this.articles == null) {
|
|
||||||
this.articles = new LinkedList<Article>();
|
|
||||||
}
|
|
||||||
this.articles.addLast(new Article(title, desc, picUrl, url));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Article removeLastArticle() {
|
|
||||||
Article article = null;
|
|
||||||
if (this.articles != null) {
|
|
||||||
article = this.articles.removeLast();
|
|
||||||
}
|
|
||||||
return article;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Article removeFirstArticle() {
|
|
||||||
if (this.articles != null) {
|
|
||||||
return this.articles.removeFirst();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMaxCount() {
|
|
||||||
return this.articles.size() == MAX_ARTICLE_COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toXml() {
|
|
||||||
this.count = articles.size();
|
|
||||||
xmlStream.alias("item", Article.class);
|
|
||||||
xmlStream.aliasField("Title", Article.class, "title");
|
|
||||||
xmlStream.aliasField("Description", Article.class, "desc");
|
|
||||||
xmlStream.aliasField("PicUrl", Article.class, "picUrl");
|
|
||||||
xmlStream.aliasField("Url", Article.class, "url");
|
|
||||||
return xmlStream.toXML(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("[BaseResponse ,toUserName=").append(super.getToUserName());
|
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
|
||||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
|
||||||
sb.append(" ,articles=").append(this.articles.toString());
|
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime()).append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,67 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.foxinmy.weixin4j.util.ClassUtil;
|
|
||||||
import com.foxinmy.weixin4j.xml.XStream;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 响应消息基类
|
|
||||||
* <p>
|
|
||||||
* <font color="red">回复图片等多媒体消息时需要预先上传多媒体文件到微信服务器,
|
|
||||||
* 假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试</font>
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @className BaseResponse
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月6日
|
|
||||||
* @since JDK 1.7
|
|
||||||
*/
|
|
||||||
public class BaseResponse extends BaseMsg {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7761192742840031607L;
|
|
||||||
protected final static XStream xmlStream = XStream.get();
|
|
||||||
static {
|
|
||||||
Class<?>[] classes = ClassUtil.getClasses(
|
|
||||||
BaseResponse.class.getPackage()).toArray(new Class[0]);
|
|
||||||
|
|
||||||
xmlStream.autodetectAnnotations(true);
|
|
||||||
xmlStream.processAnnotations(classes);
|
|
||||||
}
|
|
||||||
@XStreamAlias("MsgType")
|
|
||||||
private ResponseType msgType; // 消息类型
|
|
||||||
|
|
||||||
public BaseResponse(ResponseType msgType) {
|
|
||||||
this.msgType = msgType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseResponse(ResponseType msgType, BaseMessage inMessage) {
|
|
||||||
this(msgType, inMessage.getFromUserName(), inMessage.getToUserName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseResponse(ResponseType msgType, String toUserName,
|
|
||||||
String fromUserName) {
|
|
||||||
super(toUserName, fromUserName);
|
|
||||||
this.msgType = msgType;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseType getMsgType() {
|
|
||||||
return msgType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMsgType(ResponseType msgType) {
|
|
||||||
this.msgType = msgType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息对象转换为微信服务器接受的xml格式消息
|
|
||||||
*
|
|
||||||
* @return xml字符串
|
|
||||||
*/
|
|
||||||
public String toXml() {
|
|
||||||
return xmlStream.toXML(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Image;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 回复图片消息
|
|
||||||
*
|
|
||||||
* @className ImageResponse
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年3月23日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @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.E5.9B.BE.E7.89.87.E6.B6.88.E6.81.AF">回复图片消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Image
|
|
||||||
* @see com.foxinmy.weixin4j.msg.BaseMessage
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
|
||||||
*/
|
|
||||||
@XStreamAlias("xml")
|
|
||||||
public class ImageResponse extends BaseResponse {
|
|
||||||
private static final long serialVersionUID = 6998255203997554731L;
|
|
||||||
|
|
||||||
public ImageResponse(BaseMessage inMessage) {
|
|
||||||
this(null, inMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageResponse(String mediaId, BaseMessage inMessage) {
|
|
||||||
super(ResponseType.image, inMessage);
|
|
||||||
super.getMsgType().setMessageClass(ImageResponse.class);
|
|
||||||
this.pushMediaId(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("Image")
|
|
||||||
private Image image;
|
|
||||||
|
|
||||||
public void pushMediaId(String mediaId) {
|
|
||||||
this.image = new Image(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toXml() {
|
|
||||||
xmlStream.aliasField("MediaId", Image.class, "mediaId");
|
|
||||||
return xmlStream.toXML(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("[ImageResponse ,toUserName=").append(super.getToUserName());
|
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
|
||||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
|
||||||
sb.append(" ,mediaId=").append(this.image.getMediaId());
|
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime()).append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Music;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 回复音乐消息
|
|
||||||
*
|
|
||||||
* @className MusicResponse
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年3月23日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @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.E9.9F.B3.E4.B9.90.E6.B6.88.E6.81.AF">回复音乐消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Music
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
|
||||||
*/
|
|
||||||
@XStreamAlias("xml")
|
|
||||||
public class MusicResponse extends BaseResponse {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 4384403772658796395L;
|
|
||||||
|
|
||||||
public MusicResponse(BaseMessage inMessage) {
|
|
||||||
super(ResponseType.music, inMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("Music")
|
|
||||||
private Music music;
|
|
||||||
|
|
||||||
public void pushMusic(String mediaId) {
|
|
||||||
this.music = new Music(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMusic(Music music) {
|
|
||||||
this.music = music;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toXml() {
|
|
||||||
xmlStream.aliasField("MediaId", Music.class, "musicUrl");
|
|
||||||
xmlStream.aliasField("Title", Music.class, "title");
|
|
||||||
xmlStream.aliasField("Description", Music.class, "desc");
|
|
||||||
xmlStream.aliasField("HQMusicUrl", Music.class, "hqMusicUrl");
|
|
||||||
xmlStream.aliasField("ThumbMediaId", Music.class, "thumbMediaId");
|
|
||||||
return xmlStream.toXML(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("[MusicResponse ,toUserName=").append(super.getToUserName());
|
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
|
||||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
|
||||||
sb.append(" ,music=").append(music.toString());
|
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime()).append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
被动响应消息
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 回复文本消息
|
|
||||||
*
|
|
||||||
* @className TextResponse
|
|
||||||
* @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%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.mp.response.BaseResponse
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
|
||||||
*/
|
|
||||||
@XStreamAlias("xml")
|
|
||||||
public class TextResponse extends BaseResponse {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7018053906644190260L;
|
|
||||||
|
|
||||||
public TextResponse() {
|
|
||||||
super(ResponseType.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextResponse(String content, BaseMessage inMessage) {
|
|
||||||
super(ResponseType.text, inMessage);
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("Content")
|
|
||||||
private String content; // 消息内容
|
|
||||||
|
|
||||||
public String getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(String content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("[TextResponse ,toUserName=").append(super.getToUserName());
|
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
|
||||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
|
||||||
sb.append(" ,content=").append(content);
|
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime()).append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 转移消息到多客服端消息
|
|
||||||
*
|
|
||||||
* @className TransferResponse
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年6月28日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see <a
|
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%B0%86%E6%B6%88%E6%81%AF%E8%BD%AC%E5%8F%91%E5%88%B0%E5%A4%9A%E5%AE%A2%E6%9C%8D">多客服转移消息</a>
|
|
||||||
* @see <a href="http://dkf.qq.com/document-4_1.html">将消息转发到多客服</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
|
||||||
*/
|
|
||||||
@XStreamAlias("xml")
|
|
||||||
public class TransferResponse extends BaseResponse {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -5479496746108594940L;
|
|
||||||
|
|
||||||
public TransferResponse(BaseMessage inMessage) {
|
|
||||||
super(ResponseType.transfer_customer_service, inMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 需如果指定的客服没有接入能力(不在线、没有开启自动接入或者自动接入已满) 该用户会一直等待指定客服有接入能力后才会被接入 而不会被其他客服接待
|
|
||||||
*
|
|
||||||
* @param inMessage
|
|
||||||
* @param kfAccount
|
|
||||||
* 转移客服的账号
|
|
||||||
*/
|
|
||||||
public TransferResponse(BaseMessage inMessage, String kfAccount) {
|
|
||||||
super(ResponseType.transfer_customer_service, inMessage);
|
|
||||||
this.transInfo = new TransInfo(kfAccount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("TransInfo")
|
|
||||||
private TransInfo transInfo;
|
|
||||||
|
|
||||||
public String getTransAccount() {
|
|
||||||
if (transInfo != null) {
|
|
||||||
return transInfo.getKfAccount();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransAccount(String kfAccount) {
|
|
||||||
this.transInfo = new TransInfo(kfAccount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TransInfo {
|
|
||||||
// 指定会话接入的客服账号
|
|
||||||
@XStreamAlias("KfAccount")
|
|
||||||
private String kfAccount;
|
|
||||||
|
|
||||||
public TransInfo(String kfAccount) {
|
|
||||||
this.kfAccount = kfAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKfAccount() {
|
|
||||||
return kfAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "TransInfo [kfAccount=" + kfAccount + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Video;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 回复视频消息
|
|
||||||
*
|
|
||||||
* @className VideoResponse
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年4月6日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @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.E8.A7.86.E9.A2.91.E6.B6.88.E6.81.AF">回复视频消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Video
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
|
||||||
*/
|
|
||||||
@XStreamAlias("xml")
|
|
||||||
public class VideoResponse extends BaseResponse {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -1013075358679078381L;
|
|
||||||
|
|
||||||
public VideoResponse(BaseMessage inMessage) {
|
|
||||||
super(ResponseType.video, inMessage);
|
|
||||||
super.getMsgType().setMessageClass(VideoResponse.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("Video")
|
|
||||||
private Video video;
|
|
||||||
|
|
||||||
public void pushVideo(String mediaId) {
|
|
||||||
this.video = new Video(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVideo(Video video) {
|
|
||||||
this.video = video;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toXml() {
|
|
||||||
xmlStream.aliasField("MediaId", Video.class, "mediaId");
|
|
||||||
xmlStream.aliasField("Title", Video.class, "title");
|
|
||||||
xmlStream.aliasField("Description", Video.class, "desc");
|
|
||||||
xmlStream.omitField(Video.class, "thumbMediaId");
|
|
||||||
return xmlStream.toXML(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("[VideoResponse ,toUserName=").append(super.getToUserName());
|
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
|
||||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
|
||||||
sb.append(" ,video=").append(video.toString());
|
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime()).append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.response;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.model.Voice;
|
|
||||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 回复语音消息
|
|
||||||
*
|
|
||||||
* @className VoiceResponse
|
|
||||||
* @author jy.hu
|
|
||||||
* @date 2014年3月23日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @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.E8.AF.AD.E9.9F.B3.E6.B6.88.E6.81.AF">回复语音消息</a>
|
|
||||||
* @see com.foxinmy.weixin4j.mp.msg.model.Voice
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
|
||||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
|
||||||
*/
|
|
||||||
@XStreamAlias("xml")
|
|
||||||
public class VoiceResponse extends BaseResponse {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7944926238652243793L;
|
|
||||||
|
|
||||||
public VoiceResponse(BaseMessage inMessage) {
|
|
||||||
this(null, inMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VoiceResponse(String mediaId, BaseMessage inMessage) {
|
|
||||||
super(ResponseType.voice, inMessage);
|
|
||||||
super.getMsgType().setMessageClass(VoiceResponse.class);
|
|
||||||
this.pushMediaId(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@XStreamAlias("Voice")
|
|
||||||
private Voice voice;
|
|
||||||
|
|
||||||
public void pushMediaId(String mediaId) {
|
|
||||||
this.voice = new Voice(mediaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toXml() {
|
|
||||||
xmlStream.aliasField("MediaId", Voice.class, "mediaId");
|
|
||||||
return xmlStream.toXML(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("[VoiceResponse ,toUserName=").append(super.getToUserName());
|
|
||||||
sb.append(" ,fromUserName=").append(super.getFromUserName());
|
|
||||||
sb.append(" ,msgType=").append(super.getMsgType().name());
|
|
||||||
sb.append(" ,mediaId=").append(voice.getMediaId());
|
|
||||||
sb.append(" ,createTime=").append(super.getCreateTime()).append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +1,11 @@
|
|||||||
package com.foxinmy.weixin4j.mp.type;
|
package com.foxinmy.weixin4j.mp.type;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客服消息记录中的回话状态
|
* 客服消息记录中的回话状态
|
||||||
|
*
|
||||||
* @className CustomRecordOperCode
|
* @className CustomRecordOperCode
|
||||||
* @author jy
|
* @author jy
|
||||||
* @date 2014年11月16日
|
* @date 2014年11月16日
|
||||||
@ -14,6 +18,17 @@ public enum CustomRecordOperCode {
|
|||||||
2002, "客服发送消息"), RECEIVE2(2003, "客服收到消息");
|
2002, "客服发送消息"), RECEIVE2(2003, "客服收到消息");
|
||||||
private int code;
|
private int code;
|
||||||
private String desc;
|
private String desc;
|
||||||
|
private static Map<Integer, CustomRecordOperCode> customRecordOperCodeMap;
|
||||||
|
static {
|
||||||
|
customRecordOperCodeMap = new HashMap<Integer, CustomRecordOperCode>();
|
||||||
|
for (CustomRecordOperCode operCode : CustomRecordOperCode.values()) {
|
||||||
|
customRecordOperCodeMap.put(operCode.getCode(), operCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CustomRecordOperCode getOper(int code) {
|
||||||
|
return customRecordOperCodeMap.get(code);
|
||||||
|
}
|
||||||
|
|
||||||
CustomRecordOperCode(int code, String desc) {
|
CustomRecordOperCode(int code, String desc) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.type;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.response.ArticleResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.BaseResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.ImageResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.MusicResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.TextResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.TransferResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.VideoResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.VoiceResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 被动响应类型
|
|
||||||
* @className ResponseType
|
|
||||||
* @author jy
|
|
||||||
* @date 2014年11月5日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see
|
|
||||||
*/
|
|
||||||
public enum ResponseType {
|
|
||||||
text(TextResponse.class), image(ImageResponse.class), voice(
|
|
||||||
VoiceResponse.class), video(VideoResponse.class), music(
|
|
||||||
MusicResponse.class), news(ArticleResponse.class), transfer_customer_service(
|
|
||||||
TransferResponse.class);
|
|
||||||
private Class<? extends BaseResponse> messageClass;
|
|
||||||
|
|
||||||
ResponseType(Class<? extends BaseResponse> messageClass) {
|
|
||||||
this.messageClass = messageClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageClass(Class<? extends BaseResponse> messageClass) {
|
|
||||||
this.messageClass = messageClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<? extends BaseResponse> getMessageClass() {
|
|
||||||
return messageClass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.mp.util;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.type.CustomRecordOperCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 实体帮助类
|
|
||||||
*
|
|
||||||
* @className EntityUtil
|
|
||||||
* @author jy
|
|
||||||
* @date 2014年11月16日
|
|
||||||
* @since JDK 1.7
|
|
||||||
* @see
|
|
||||||
*/
|
|
||||||
public class EntityUtil {
|
|
||||||
private static Map<Integer, CustomRecordOperCode> customRecordOperCodeMap;
|
|
||||||
static {
|
|
||||||
customRecordOperCodeMap = new HashMap<Integer, CustomRecordOperCode>();
|
|
||||||
for (CustomRecordOperCode operCode : CustomRecordOperCode.values()) {
|
|
||||||
customRecordOperCodeMap.put(operCode.getCode(), operCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CustomRecordOperCode getCustomRecordOperCode(int code) {
|
|
||||||
return customRecordOperCodeMap.get(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +1,12 @@
|
|||||||
# \u6d4b\u8bd5\u4e4b\u7528 \u6b63\u5f0f\u73af\u5883\u4e0bcopy\u4e00\u4efd\u5230classpath
|
# \u6d4b\u8bd5\u4e4b\u7528 \u6b63\u5f0f\u73af\u5883\u4e0bcopy\u4e00\u4efd\u5230classpath
|
||||||
# \u516c\u4f17\u53f7\u4fe1\u606f
|
# \u516c\u4f17\u53f7\u4fe1\u606f
|
||||||
account={"id":"wx4ab8f8de58159a57","secret":"1d4eb0f4bf556aaed539f30ed05ca795",\
|
account={"id":"wx4ab8f8de58159a57","secret":"1d4eb0f4bf556aaed539f30ed05ca795",\
|
||||||
"token":"\u5f00\u653e\u8005\u7684token \u975e\u5fc5\u987b","openId":"\u516c\u4f17\u53f7\u7684openid \u975e\u5fc5\u987b",\
|
"token":"\u5f00\u653e\u8005\u7684token \u5fc5\u987b","openId":"\u516c\u4f17\u53f7\u7684openid \u975e\u5fc5\u987b",\
|
||||||
"encodingAesKey":"\u516c\u4f17\u53f7\u8bbe\u7f6e\u4e86\u52a0\u5bc6\u65b9\u5f0f\u4e14\u4e3a\u300c\u5b89\u5168\u6a21\u5f0f\u300d\u65f6\u9700\u8981\u586b\u5165",\
|
"encodingAesKey":"\u516c\u4f17\u53f7\u8bbe\u7f6e\u4e86\u52a0\u5bc6\u65b9\u5f0f\u4e14\u4e3a\u300c\u5b89\u5168\u6a21\u5f0f\u300d\u65f6\u9700\u8981\u586b\u5165",\
|
||||||
"mchId":"V3.x\u7248\u672c\u4e0b\u7684\u5fae\u4fe1\u5546\u6237\u53f7",\
|
"mchId":"V3.x\u7248\u672c\u4e0b\u7684\u5fae\u4fe1\u5546\u6237\u53f7 \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||||
"version":3,\
|
"version":2,\
|
||||||
"partnerId":"\u8d22\u4ed8\u901a\u7684\u5546\u6237\u53f7","partnerKey":"\u8d22\u4ed8\u901a\u5546\u6237\u6743\u9650\u5bc6\u94a5Key",\
|
"partnerId":"\u8d22\u4ed8\u901a\u7684\u5546\u6237\u53f7 \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165","partnerKey":"\u8d22\u4ed8\u901a\u5546\u6237\u6743\u9650\u5bc6\u94a5Key \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||||
"paySignKey":"\u5fae\u4fe1\u652f\u4ed8\u4e2d\u8c03\u7528API\u7684\u5bc6\u94a5"}
|
"paySignKey":"\u5fae\u4fe1\u652f\u4ed8\u4e2d\u8c03\u7528API\u7684\u5bc6\u94a5 \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165"}
|
||||||
|
|
||||||
# \u4f7f\u7528FileTokenHolder\u65f6token\u7684\u5b58\u653e\u8def\u5f84
|
# \u4f7f\u7528FileTokenHolder\u65f6token\u7684\u5b58\u653e\u8def\u5f84
|
||||||
token_path=/tmp/weixin/token
|
token_path=/tmp/weixin/token
|
||||||
@ -17,4 +17,4 @@ media_path=/tmp/weixin/media
|
|||||||
# \u5bf9\u8d26\u5355\u4fdd\u5b58\u8def\u5f84
|
# \u5bf9\u8d26\u5355\u4fdd\u5b58\u8def\u5f84
|
||||||
bill_path=/tmp/weixin/bill
|
bill_path=/tmp/weixin/bill
|
||||||
# ca\u8bc1\u4e66\u5b58\u653e\u7684\u5b8c\u6574\u8def\u5f84
|
# ca\u8bc1\u4e66\u5b58\u653e\u7684\u5b8c\u6574\u8def\u5f84
|
||||||
ca_file=/tmp/weixin/xxxxxx.p12
|
ca_file=/tmp/weixin/xxxxx.p12 | xxxxx.pfx
|
||||||
@ -9,8 +9,8 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
|
import com.foxinmy.weixin4j.model.Button;
|
||||||
import com.foxinmy.weixin4j.mp.api.MenuApi;
|
import com.foxinmy.weixin4j.mp.api.MenuApi;
|
||||||
import com.foxinmy.weixin4j.mp.model.Button;
|
|
||||||
import com.foxinmy.weixin4j.type.ButtonType;
|
import com.foxinmy.weixin4j.type.ButtonType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -13,8 +13,10 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.mp.api.MassApi;
|
import com.foxinmy.weixin4j.mp.api.MassApi;
|
||||||
import com.foxinmy.weixin4j.mp.api.MediaApi;
|
import com.foxinmy.weixin4j.mp.api.MediaApi;
|
||||||
import com.foxinmy.weixin4j.mp.model.MpArticle;
|
|
||||||
import com.foxinmy.weixin4j.mp.test.TokenTest;
|
import com.foxinmy.weixin4j.mp.test.TokenTest;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Image;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.MpArticle;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Video;
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import com.foxinmy.weixin4j.type.MediaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,20 +49,20 @@ public class MassMsgTest extends TokenTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uploadVideo() throws WeixinException {
|
public void uploadVideo() throws WeixinException {
|
||||||
String massId = massApi.uploadVideo("mediaId", "title", "desc");
|
Video video = new Video("mediaId", "title", "desc");
|
||||||
|
String massId = massApi.uploadVideo(video);
|
||||||
Assert.assertTrue(massId != null);
|
Assert.assertTrue(massId != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void massByGroup() throws WeixinException {
|
public void massByGroup() throws WeixinException {
|
||||||
String massId = massApi.massByGroup("123", MediaType.image, "groupId");
|
String massId = massApi.massByGroupId(new Image("mediaId"), 0);
|
||||||
Assert.assertTrue(massId != null);
|
Assert.assertTrue(massId != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void massByOpenIds() throws WeixinException {
|
public void massByOpenIds() throws WeixinException {
|
||||||
String massId = massApi
|
String massId = massApi.massByOpenIds(new Image("mediaId"), "openIds");
|
||||||
.massByOpenIds("123", MediaType.image, "openIds");
|
|
||||||
Assert.assertTrue(massId != null);
|
Assert.assertTrue(massId != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +72,7 @@ public class MassMsgTest extends TokenTest {
|
|||||||
String thumbMediaId = mediaApi.uploadMedia(new File("/tmp/test.jpg"),
|
String thumbMediaId = mediaApi.uploadMedia(new File("/tmp/test.jpg"),
|
||||||
MediaType.image);
|
MediaType.image);
|
||||||
articles.add(new MpArticle(thumbMediaId, "title", "content"));
|
articles.add(new MpArticle(thumbMediaId, "title", "content"));
|
||||||
String massId = massApi.massArticleByGroup(articles, "0");
|
String massId = massApi.massArticleByGroupId(articles, 0);
|
||||||
Assert.assertTrue(massId != null);
|
Assert.assertTrue(massId != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,14 +11,14 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.mp.api.MediaApi;
|
import com.foxinmy.weixin4j.mp.api.MediaApi;
|
||||||
import com.foxinmy.weixin4j.mp.api.NotifyApi;
|
import com.foxinmy.weixin4j.mp.api.NotifyApi;
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify;
|
import com.foxinmy.weixin4j.mp.message.NotifyMessage;
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.BaseNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.ImageNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.MusicNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.TextNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.VideoNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.msg.notify.VoiceNotify;
|
|
||||||
import com.foxinmy.weixin4j.mp.test.TokenTest;
|
import com.foxinmy.weixin4j.mp.test.TokenTest;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Image;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Music;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.News;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Text;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Video;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Voice;
|
||||||
import com.foxinmy.weixin4j.type.MediaType;
|
import com.foxinmy.weixin4j.type.MediaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,50 +43,48 @@ public class NotifyMsgTest extends TokenTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void text() {
|
public void text() {
|
||||||
TextNotify notify = new TextNotify("123", "to");
|
NotifyMessage notify = new NotifyMessage("to", new Text("ttt"));
|
||||||
System.out.println(notify.toJson());
|
System.out.println(notify.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void image() {
|
public void image() {
|
||||||
ImageNotify notify = new ImageNotify("to");
|
NotifyMessage notify = new NotifyMessage("to", new Image("image"));
|
||||||
notify.pushMediaId("123");
|
|
||||||
System.out.println(notify.toJson());
|
System.out.println(notify.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voice() {
|
public void voice() {
|
||||||
VoiceNotify notify = new VoiceNotify("to");
|
NotifyMessage notify = new NotifyMessage("to", new Voice("voice"));
|
||||||
notify.pushMediaId("123");
|
|
||||||
System.out.println(notify.toJson());
|
System.out.println(notify.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void video() {
|
public void video() {
|
||||||
VideoNotify notify = new VideoNotify("to");
|
NotifyMessage notify = new NotifyMessage("to", new Video("video"));
|
||||||
notify.pushVideo("123", "m123");
|
|
||||||
System.out.println(notify.toJson());
|
System.out.println(notify.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void music() {
|
public void music() {
|
||||||
MusicNotify notify = new MusicNotify("to");
|
NotifyMessage notify = new NotifyMessage("to", new Music("music"));
|
||||||
notify.pushMusic("url", "hqUrl", "mediaId");
|
|
||||||
System.out.println(notify.toJson());
|
System.out.println(notify.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void article() {
|
public void news() {
|
||||||
ArticleNotify notify = new ArticleNotify("to");
|
News news = new News();
|
||||||
notify.pushArticle("title1", "desc1", "picUrl1", "url1");
|
NotifyMessage notify = new NotifyMessage("to", news);
|
||||||
notify.pushArticle("title2", "desc2", "picUrl2", "url2");
|
news.pushArticle("title1", "desc1", "picUrl1", "url1");
|
||||||
|
news.pushArticle("title2", "desc2", "picUrl2", "url2");
|
||||||
System.out.println(notify.toJson());
|
System.out.println(notify.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void send1() throws IOException, WeixinException {
|
public void send1() throws IOException, WeixinException {
|
||||||
BaseNotify notify = new TextNotify("this is a notify message!",
|
NotifyMessage notify = new NotifyMessage(
|
||||||
"owGBft_vbBbOaQOmpEUE4xDLeRSU");
|
"owGBft_vbBbOaQOmpEUE4xDLeRSU", new Text(
|
||||||
|
"this is a notify message!"));
|
||||||
JsonResult result = notifyApi.sendNotify(notify);
|
JsonResult result = notifyApi.sendNotify(notify);
|
||||||
Assert.assertEquals(0, result.getCode());
|
Assert.assertEquals(0, result.getCode());
|
||||||
}
|
}
|
||||||
@ -95,9 +93,8 @@ public class NotifyMsgTest extends TokenTest {
|
|||||||
public void send2() throws WeixinException, IOException {
|
public void send2() throws WeixinException, IOException {
|
||||||
String mediaId = mediaApi.uploadMedia(new File("/tmp/test.jpg"),
|
String mediaId = mediaApi.uploadMedia(new File("/tmp/test.jpg"),
|
||||||
MediaType.image);
|
MediaType.image);
|
||||||
ImageNotify imageNotify = new ImageNotify(
|
NotifyMessage imageNotify = new NotifyMessage(
|
||||||
"owGBft_vbBbOaQOmpEUE4xDLeRSU");
|
"owGBft_vbBbOaQOmpEUE4xDLeRSU", new Image(mediaId));
|
||||||
imageNotify.pushMediaId(mediaId);
|
|
||||||
JsonResult result = notifyApi.sendNotify(imageNotify);
|
JsonResult result = notifyApi.sendNotify(imageNotify);
|
||||||
Assert.assertEquals(0, result.getCode());
|
Assert.assertEquals(0, result.getCode());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,14 +4,16 @@ import org.dom4j.DocumentException;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.response.ArticleResponse;
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.mp.response.ImageResponse;
|
import com.foxinmy.weixin4j.mp.message.ResponseMessage;
|
||||||
import com.foxinmy.weixin4j.mp.response.MusicResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.TextResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.VideoResponse;
|
|
||||||
import com.foxinmy.weixin4j.mp.response.VoiceResponse;
|
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
|
||||||
import com.foxinmy.weixin4j.msg.TextMessage;
|
import com.foxinmy.weixin4j.msg.TextMessage;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Image;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Music;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.News;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Text;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Trans;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Video;
|
||||||
|
import com.foxinmy.weixin4j.msg.model.Voice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送消息格式测试
|
* 发送消息格式测试
|
||||||
@ -21,7 +23,7 @@ import com.foxinmy.weixin4j.msg.TextMessage;
|
|||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
*/
|
*/
|
||||||
public class OutMsgTest {
|
public class OutMsgTest {
|
||||||
private BaseMessage inMessage;
|
private BaseMsg inMessage;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
@ -32,43 +34,51 @@ public class OutMsgTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void text() throws DocumentException {
|
public void text() throws DocumentException {
|
||||||
TextResponse message = new TextResponse("text", inMessage);
|
ResponseMessage message = new ResponseMessage(new Text("text"), inMessage);
|
||||||
System.out.println(message.toXml());
|
System.out.println(message.toXml());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void image() {
|
public void image() {
|
||||||
ImageResponse message = new ImageResponse(inMessage);
|
ResponseMessage message = new ResponseMessage(new Image("image"), inMessage);
|
||||||
message.pushMediaId("mediaId");
|
|
||||||
System.out.println(message.toXml());
|
System.out.println(message.toXml());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voice() {
|
public void voice() {
|
||||||
VoiceResponse message = new VoiceResponse(inMessage);
|
ResponseMessage message = new ResponseMessage(new Voice("voice"), inMessage);
|
||||||
message.pushMediaId("mediaId");
|
|
||||||
System.out.println(message.toXml());
|
System.out.println(message.toXml());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void video() {
|
public void video() {
|
||||||
VideoResponse message = new VideoResponse(inMessage);
|
Video video = new Video("video");
|
||||||
message.pushVideo("mediaId");
|
video.setDesc("desc");
|
||||||
|
ResponseMessage message = new ResponseMessage(video, inMessage);
|
||||||
System.out.println(message.toXml());
|
System.out.println(message.toXml());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void music() {
|
public void music() {
|
||||||
MusicResponse message = new MusicResponse(inMessage);
|
Music music = new Music("title", "desc", "musicUrl", "hqMusicUrl",
|
||||||
message.pushMusic("mediaId");
|
"thumbMediaId");
|
||||||
|
ResponseMessage message = new ResponseMessage(music, inMessage);
|
||||||
System.out.println(message.toXml());
|
System.out.println(message.toXml());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void article() {
|
public void article() {
|
||||||
ArticleResponse message = new ArticleResponse(inMessage);
|
News news = new News();
|
||||||
message.pushArticle("title1", "desc1", "picUrl1", "url1");
|
ResponseMessage message = new ResponseMessage(news, inMessage);
|
||||||
message.pushArticle("title2", "desc2", "picUrl2", "url2");
|
news.pushArticle("title1", "desc1", "picUrl1", "url1");
|
||||||
|
news.pushArticle("title2", "desc2", "picUrl2", "url2");
|
||||||
|
System.out.println(message.toXml());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void trans(){
|
||||||
|
ResponseMessage message = new ResponseMessage(new Trans(),inMessage);
|
||||||
|
System.out.println(message.toXml());
|
||||||
|
message = new ResponseMessage(new Trans("accountid"),inMessage);
|
||||||
System.out.println(message.toXml());
|
System.out.println(message.toXml());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import org.junit.Test;
|
|||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.JsonResult;
|
import com.foxinmy.weixin4j.http.JsonResult;
|
||||||
import com.foxinmy.weixin4j.mp.api.TmplApi;
|
import com.foxinmy.weixin4j.mp.api.TmplApi;
|
||||||
import com.foxinmy.weixin4j.mp.response.TemplateMessage;
|
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||||
import com.foxinmy.weixin4j.mp.test.TokenTest;
|
import com.foxinmy.weixin4j.mp.test.TokenTest;
|
||||||
|
|
||||||
public class TemplateMsgTest extends TokenTest {
|
public class TemplateMsgTest extends TokenTest {
|
||||||
|
|||||||
@ -27,21 +27,21 @@ weixin4j-mp-server
|
|||||||
示例(properties中换行用右斜杆\\)
|
示例(properties中换行用右斜杆\\)
|
||||||
|
|
||||||
> account={"id":"appId","secret":"appSecret",
|
> account={"id":"appId","secret":"appSecret",
|
||||||
> "token":"开放者的token 非必须","openId":"公众号的openid 非必须",
|
> "token":"开放者的token 必须","openId":"公众号的openid 非必须",
|
||||||
> "encodingAesKey":"公众号设置了加密方式且为「安全模式」时需要填入",
|
> "encodingAesKey":"公众号设置了加密方式且为「安全模式」时需要填入",
|
||||||
> "mchId":"V3.x版本下的微信商户号",
|
> "mchId":"V3.x版本下的微信商户号",
|
||||||
> "partnerId":"财付通的商户号","partnerKey":"财付通商户权限密钥Key",
|
> "partnerId":"财付通的商户号","partnerKey":"财付通商户权限密钥Key",
|
||||||
> "version":"针对微信支付的版本号(目前可能为2,3),如果不填则按照mchId非空与否来做判断",
|
> "version":"针对微信支付的版本号(目前可能为2,3),如果不填则按照mchId非空与否来做判断",
|
||||||
> "paySignKey":"微信支付中调用API的密钥"} <br/>
|
> "paySignKey":"微信支付中调用API的密钥"} </br>
|
||||||
> token_path=/tmp/weixin/token <br/>
|
> token_path=/tmp/weixin/token </br>
|
||||||
> qr_path=/tmp/weixin/qr <br/>
|
> qr_path=/tmp/weixin/qr </br>
|
||||||
> media_path=/tmp/weixin/media <br/>
|
> media_path=/tmp/weixin/media </br>
|
||||||
> bill_path=/tmp/weixin/bill <br/>
|
> bill_path=/tmp/weixin/bill </br>
|
||||||
> ca_file=/tmp/weixin/xxxxx.p12 | xxxxx.pfx <br/>
|
> ca_file=/tmp/weixin/xxxxx.p12 | xxxxx.pfx </br>
|
||||||
|
|
||||||
2.mvn package,得到一个zip的压缩包,解压到启动目录(见`src/main/startup.sh/APP_HOME`)
|
2.mvn package,得到一个zip的压缩包,解压到启动目录(见`src/main/startup.sh/APP_HOME`)
|
||||||
|
|
||||||
3.启动netty服务(`com.foxinmy.weixin4j.mp.startup.WeixinServerBootstrap`)
|
3.启动netty服务(`com.foxinmy.weixin4j.mp.startup.WeixinMpServerBootstrap`)
|
||||||
|
|
||||||
sh startup.sh start
|
sh startup.sh start
|
||||||
|
|
||||||
@ -55,4 +55,8 @@ weixin4j-mp-server
|
|||||||
|
|
||||||
+ 解决`server工程`打包后不能运行问题(`ClassUtil`无法获取jar包里面的类)
|
+ 解决`server工程`打包后不能运行问题(`ClassUtil`无法获取jar包里面的类)
|
||||||
|
|
||||||
+ 新增被动消息的`加密`以及回复消息的`解密`
|
+ 新增被动消息的`加密`以及回复消息的`解密`
|
||||||
|
|
||||||
|
* 2014-11-23
|
||||||
|
|
||||||
|
+ `WeixinServerBootstrap`重命名为`WeixinMpServerBootstrap`
|
||||||
@ -11,13 +11,15 @@
|
|||||||
<artifactId>weixin4j-mp-server</artifactId>
|
<artifactId>weixin4j-mp-server</artifactId>
|
||||||
<name>weixin4j-mp-server</name>
|
<name>weixin4j-mp-server</name>
|
||||||
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-mp/weixin4j-mp-server</url>
|
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-mp/weixin4j-mp-server</url>
|
||||||
<description>微信公众号服务</description>
|
<description>微信公众平台netty服务</description>
|
||||||
<build>
|
<build>
|
||||||
<finalName>weixin-mp-server</finalName>
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<finalName>weixin-mp-server</finalName>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import java.lang.reflect.Type;
|
|||||||
|
|
||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.mp.response.BaseResponse;
|
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
import com.foxinmy.weixin4j.mp.message.ResponseMessage;
|
||||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||||
import com.foxinmy.weixin4j.xml.XStream;
|
import com.foxinmy.weixin4j.xml.XStream;
|
||||||
|
|
||||||
@ -20,14 +20,14 @@ import com.foxinmy.weixin4j.xml.XStream;
|
|||||||
* @see com.foxinmy.weixin4j.mp.action.WeixinAction
|
* @see com.foxinmy.weixin4j.mp.action.WeixinAction
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public abstract class AbstractAction<M extends BaseMessage> implements
|
public abstract class AbstractAction<M extends BaseMsg> implements
|
||||||
WeixinAction {
|
WeixinAction {
|
||||||
|
|
||||||
public abstract BaseResponse execute(M inMessage);
|
public abstract ResponseMessage execute(M inMessage);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse execute(String msg) throws DocumentException {
|
public ResponseMessage execute(String msg) throws DocumentException {
|
||||||
BaseMessage message = MessageUtil.xml2msg(msg);
|
BaseMsg message = MessageUtil.xml2msg(msg);
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
Class<M> messageClass = getGenericType();
|
Class<M> messageClass = getGenericType();
|
||||||
XStream xstream = XStream.get();
|
XStream xstream = XStream.get();
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user