diff --git a/weixin4j-base/CHANGE.md b/weixin4j-base/CHANGE.md
index 48f32b3e..4759d5c1 100644
--- a/weixin4j-base/CHANGE.md
+++ b/weixin4j-base/CHANGE.md
@@ -48,4 +48,8 @@
* 2015-04-19
- + 删除ActionMapping相关类
\ No newline at end of file
+ + 删除ActionMapping相关类
+
+* 2015-05-07
+
+ + 删除ResponseTuple接口
\ No newline at end of file
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Image.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Image.java
index 798388dc..c010ab74 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Image.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Image.java
@@ -6,7 +6,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 图片对象
*
- * 可用于「被动消息」「客服消息」「群发消息」
+ * 可用于「客服消息」「群发消息」
*
*
* @className Image
@@ -15,7 +15,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @since JDK 1.7
* @see
*/
-public class Image implements ResponseTuple, MassTuple, NotifyTuple {
+public class Image implements MassTuple, NotifyTuple {
private static final long serialVersionUID = 6928681900960656161L;
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Music.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Music.java
index 004a9bf7..1332ad6c 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Music.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Music.java
@@ -6,7 +6,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 音乐对象
*
- * 可用于「被动消息」「客服消息」
+ * 可用于「客服消息」
*
*
* @className Music
@@ -15,7 +15,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @since JDK 1.7
* @see
*/
-public class Music implements ResponseTuple, NotifyTuple {
+public class Music implements NotifyTuple {
private static final long serialVersionUID = -5952134916367253297L;
@@ -23,7 +23,7 @@ public class Music implements ResponseTuple, NotifyTuple {
public String getMessageType() {
return "music";
}
-
+
/**
* 音乐标题
*/
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/News.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/News.java
index a2314a0b..7c5d06b9 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/News.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/News.java
@@ -9,7 +9,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 图文对象
*
- * 可用于「被动消息」「客服消息」
+ * 可用于「客服消息」
*
*
* @className News
@@ -19,7 +19,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @see
*/
@XStreamAlias("Articles")
-public class News implements ResponseTuple, NotifyTuple {
+public class News implements NotifyTuple {
private static final long serialVersionUID = 3348756809039388415L;
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/ResponseTuple.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/ResponseTuple.java
deleted file mode 100644
index b7a7d906..00000000
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/ResponseTuple.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.foxinmy.weixin4j.tuple;
-
-/**
- * 被动消息元件
- *
- * @className ResponseTuple
- * @author jy
- * @date 2014年11月22日
- * @since JDK 1.7
- * @see com.foxinmy.weixin4j.tuple.Text
- * @see com.foxinmy.weixin4j.tuple.Image
- * @see com.foxinmy.weixin4j.tuple.Voice
- * @see com.foxinmy.weixin4j.tuple.Video
- * @see com.foxinmy.weixin4j.tuple.Music
- * @see com.foxinmy.weixin4j.tuple.News
- * @see com.foxinmy.weixin4j.tuple.Trans
- */
-public interface ResponseTuple extends Tuple {
-
-}
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Text.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Text.java
index c7d705a0..f86d4a1d 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Text.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Text.java
@@ -5,7 +5,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 文本对象
*
- * 可用于「被动消息」「客服消息」「群发消息」
+ * 可用于「客服消息」「群发消息」
*
*
* @className Text
@@ -15,7 +15,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @see
*/
@XStreamAlias("Content")
-public class Text implements ResponseTuple, MassTuple, NotifyTuple {
+public class Text implements MassTuple, NotifyTuple {
private static final long serialVersionUID = 520050144519064503L;
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Trans.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Trans.java
deleted file mode 100644
index 88eb115f..00000000
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Trans.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.foxinmy.weixin4j.tuple;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-/**
- * 转移到客服
- *
- * 可用于「被动消息」
- *
- *
- * @className Trans
- * @author jy
- * @date 2014年11月21日
- * @since JDK 1.7
- * @see
- */
-@XStreamAlias("TransInfo")
-public class Trans implements ResponseTuple {
-
- private static final long serialVersionUID = -214711609286629729L;
-
- @Override
- public String getMessageType() {
- return "transfer_customer_service";
- }
-
- /**
- * 指定会话接入的客服账号
- */
- @XStreamAlias("KfAccount")
- private String kfAccount;
-
- public Trans() {
- this(null);
- }
-
- public Trans(String kfAccount) {
- this.kfAccount = kfAccount;
- }
-
- public String getKfAccount() {
- return kfAccount;
- }
-
- @Override
- public String toString() {
- return "Trans [kfAccount=" + kfAccount + "]";
- }
-
-}
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Video.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Video.java
index a59cfe51..479acb08 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Video.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Video.java
@@ -7,7 +7,7 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
/**
* 视频对象
*
- * 可用于「被动消息」「客服消息」
+ * 可用于「客服消息」
*
*
* @className Video
@@ -16,7 +16,7 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
* @since JDK 1.7
* @see
*/
-public class Video implements ResponseTuple, NotifyTuple {
+public class Video implements NotifyTuple {
private static final long serialVersionUID = 2167437425244069128L;
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Voice.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Voice.java
index 578ad929..bdcb4e09 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Voice.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/tuple/Voice.java
@@ -1,10 +1,9 @@
package com.foxinmy.weixin4j.tuple;
-
/**
* 语音对象
*
- * 可用于「被动消息」「客服消息」「群发消息」
+ * 可用于「客服消息」「群发消息」
*
*
* @className Voice
@@ -13,7 +12,7 @@ package com.foxinmy.weixin4j.tuple;
* @since JDK 1.7
* @see
*/
-public class Voice extends Image implements ResponseTuple, NotifyTuple {
+public class Voice extends Image implements NotifyTuple {
private static final long serialVersionUID = 8853054484809101524L;
diff --git a/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/MenuTest.java b/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/MenuTest.java
index 557d7184..f3caeab8 100644
--- a/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/MenuTest.java
+++ b/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/MenuTest.java
@@ -59,7 +59,7 @@ public class MenuTest extends TokenTest {
Button b1 = new Button("我要订餐", "ORDERING", ButtonType.click);
btnList.add(b1);
- Button b2 = new Button("查询订单", "http://802.canyi.net/order/list", ButtonType.view);
+ Button b2 = new Button("查询订单", "http://182.254.188.133:8082/order/list", ButtonType.view);
btnList.add(b2);
Button b3 = new Button("最新资讯", "NEWS", ButtonType.click);
btnList.add(b3);
diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/TagApi.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/TagApi.java
index 0736c440..31891702 100644
--- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/TagApi.java
+++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/api/TagApi.java
@@ -30,7 +30,7 @@ public class TagApi extends QyApi {
}
/**
- * 创建标签(创建的标签属于管理组;默认为未加锁状态)
+ * 创建标签(创建的标签属于管理组;默认为加锁状态。)
*
* @param tagName
* 标签名称
@@ -69,7 +69,7 @@ public class TagApi extends QyApi {
}
/**
- * 删除标签(管理组必须是指定标签的创建者 并且标签的成员列表为空)
+ * 删除标签(管理组必须是指定标签的创建者,并且标签的成员列表为空。)
*
* @param tagId
* 标签ID
@@ -105,7 +105,7 @@ public class TagApi extends QyApi {
}
/**
- * 获取标签成员(管理组须拥有“获取标签成员”的接口权限,标签须对管理组可见;返回列表仅包含管理组管辖范围的成员)
+ * 获取标签成员(管理组须拥有“获取标签成员”的接口权限,返回列表仅包含管理组管辖范围的成员。)
*
* @param tagId
* 标签ID
@@ -125,7 +125,7 @@ public class TagApi extends QyApi {
}
/**
- * 新增标签成员(标签对管理组可见且未加锁,成员属于管理组管辖范围)
+ * 新增标签成员(标签对管理组可见且未加锁,成员属于管理组管辖范围。)
* 若部分userid非法,则在text中体现
*
* @param tagId
@@ -144,7 +144,7 @@ public class TagApi extends QyApi {
}
/**
- * 删除标签成员(标签对管理组可见且未加锁,成员属于管理组管辖范围)
+ * 删除标签成员(标签对管理组未加锁,成员属于管理组管辖范围)
* 若部分userid非法,则在text中体现
*
* @param tagId
diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java
index 70cfe3b2..f2205028 100644
--- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java
+++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Callback.java
@@ -49,4 +49,9 @@ public class Callback implements Serializable {
return aesKey;
}
+ @Override
+ public String toString() {
+ return "Callback [url=" + url + ", token=" + token + ", aesKey="
+ + aesKey + "]";
+ }
}
diff --git a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Party.java b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Party.java
index a83622a7..43ea9807 100644
--- a/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Party.java
+++ b/weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/model/Party.java
@@ -16,7 +16,7 @@ public class Party implements Serializable {
private static final long serialVersionUID = -2567893218591084288L;
/**
- * 部门ID
+ * 部门ID,指定时必须大于1,不指定时则自动生成.
*/
private int id;
/**
diff --git a/weixin4j-server/CHANGE.md b/weixin4j-server/CHANGE.md
index f9950329..f7744eef 100644
--- a/weixin4j-server/CHANGE.md
+++ b/weixin4j-server/CHANGE.md
@@ -16,4 +16,8 @@
+ 新增客服创建、关闭、转接会话事件
- + 新增deploy.xml远程部署ant脚本
\ No newline at end of file
+ + 新增deploy.xml远程部署ant脚本
+
+* 2015-05-07
+
+ + 完成基本骨架
\ No newline at end of file
diff --git a/weixin4j-server/pom.xml b/weixin4j-server/pom.xml
index 4395f07a..85ff80a9 100644
--- a/weixin4j-server/pom.xml
+++ b/weixin4j-server/pom.xml
@@ -44,5 +44,27 @@
junit
junit
+
+ org.apache.httpcomponents
+ httpcore
+ ${httpclient.version}
+ test
+
+
+ org.apache.httpcomponents
+ httpclient
+ ${httpclient.version}
+
+
+ commons-codec
+ commons-codec
+
+
+ org.apache.httpcomponents
+ httpcore
+
+
+ test
+
\ No newline at end of file
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/HttpWeixinMessage.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/HttpWeixinMessage.java
index d1a9b504..c35dcd38 100644
--- a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/HttpWeixinMessage.java
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/HttpWeixinMessage.java
@@ -5,7 +5,7 @@ import java.io.Serializable;
import com.foxinmy.weixin4j.type.EncryptType;
/**
- * 微信的被动消息
+ * 请求消息
*
* @className HttpWeixinMessage
* @author jy
@@ -14,14 +14,10 @@ import com.foxinmy.weixin4j.type.EncryptType;
* @see
*/
public class HttpWeixinMessage implements Serializable {
-
+
private static final long serialVersionUID = -9157395300510879866L;
// 以下字段是加密方式为「安全模式」时的参数
- /**
- * 公众号的唯一ID
- */
- private String toUserName;
/**
* 加密后的内容
*/
@@ -51,9 +47,9 @@ public class HttpWeixinMessage implements Serializable {
*/
private String signature;
/**
- * 设置的token
+ * AES模式下消息签名
*/
- private String token;
+ private String msgSignature;
/**
* xml消息明文主体
*/
@@ -63,14 +59,6 @@ public class HttpWeixinMessage implements Serializable {
*/
private String method;
- public String getToUserName() {
- return toUserName;
- }
-
- public void setToUserName(String toUserName) {
- this.toUserName = toUserName;
- }
-
public String getEncryptContent() {
return encryptContent;
}
@@ -119,12 +107,12 @@ public class HttpWeixinMessage implements Serializable {
this.signature = signature;
}
- public String getToken() {
- return token;
+ public String getMsgSignature() {
+ return msgSignature;
}
- public void setToken(String token) {
- this.token = token;
+ public void setMsgSignature(String msgSignature) {
+ this.msgSignature = msgSignature;
}
public String getOriginalContent() {
@@ -145,11 +133,10 @@ public class HttpWeixinMessage implements Serializable {
@Override
public String toString() {
- return "HttpWeixinMessage [toUserName=" + toUserName
- + ", encryptContent=" + encryptContent + ", encryptType="
- + encryptType + ", echoStr=" + echoStr + ", timeStamp="
- + timeStamp + ", nonce=" + nonce + ", signature=" + signature
- + ", token=" + token + ", originalContent=" + originalContent
- + ", method=" + method + "]";
+ return "HttpWeixinMessage [encryptContent=" + encryptContent
+ + ", encryptType=" + encryptType + ", echoStr=" + echoStr
+ + ", timeStamp=" + timeStamp + ", nonce=" + nonce
+ + ", signature=" + signature + ", originalContent="
+ + originalContent + ", method=" + method + "]";
}
}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/ResponseMessage.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/ResponseMessage.java
new file mode 100644
index 00000000..1d674927
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/ResponseMessage.java
@@ -0,0 +1,51 @@
+package com.foxinmy.weixin4j.message;
+
+import java.io.Serializable;
+
+import com.foxinmy.weixin4j.response.WeixinResponse;
+
+public class ResponseMessage implements Serializable {
+
+ private static final long serialVersionUID = -2822272237544040042L;
+
+ private WeixinMessage message;
+ private WeixinResponse response;
+
+ public ResponseMessage(WeixinMessage message, WeixinResponse response) {
+ this.message = message;
+ this.response = response;
+ }
+
+ public WeixinMessage getMessage() {
+ return message;
+ }
+
+ public WeixinResponse getResponse() {
+ return response;
+ }
+
+ public String toXml() {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("");
+ xmlContent.append(String.format(
+ "",
+ message.getFromUserName()));
+ xmlContent.append(String.format(
+ "",
+ message.getToUserName()));
+ xmlContent.append(String.format(
+ "",
+ System.currentTimeMillis() / 1000l));
+ xmlContent.append(String.format("",
+ response.getMsgType()));
+ xmlContent.append(response.toContent());
+ xmlContent.append("");
+ return xmlContent.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "ResponseMessage [message=" + message + ", response=" + response
+ + "]";
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/WeixinMessage.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/WeixinMessage.java
new file mode 100644
index 00000000..6071a6be
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/message/WeixinMessage.java
@@ -0,0 +1,104 @@
+package com.foxinmy.weixin4j.message;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * 被动消息
+ *
+ * @className WeixinMessage
+ * @author jy
+ * @date 2015年5月6日
+ * @since JDK 1.7
+ * @see
+ */
+@XmlRootElement(name = "xml")
+public class WeixinMessage implements Serializable {
+
+ private static final long serialVersionUID = 7761192742840031607L;
+
+ /**
+ * 开发者微信号
+ */
+ private String toUserName;
+ /**
+ * 发送方账号 即用户的openid
+ */
+ private String fromUserName;
+ /**
+ * 消息创建时间 系统毫秒数
+ */
+ private long createTime;
+ /**
+ * 消息类型
+ *
+ */
+ private String msgType;
+ /**
+ * 消息ID 可用于排重
+ */
+ private long msgId;
+
+ public String getToUserName() {
+ return toUserName;
+ }
+
+ @XmlElement(name = "ToUserName")
+ public void setToUserName(String toUserName) {
+ this.toUserName = toUserName;
+ }
+
+ public String getFromUserName() {
+ return fromUserName;
+ }
+
+ @XmlElement(name = "FromUserName")
+ public void setFromUserName(String fromUserName) {
+ this.fromUserName = fromUserName;
+ }
+
+ public long getCreateTime() {
+ return createTime;
+ }
+
+ @XmlElement(name = "CreateTime")
+ public void setCreateTime(long createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getMsgType() {
+ return msgType;
+ }
+
+ @XmlElement(name = "MsgType")
+ public void setMsgType(String msgType) {
+ this.msgType = msgType;
+ }
+
+ public long getMsgId() {
+ return msgId;
+ }
+
+ @XmlElement(name = "MsgId")
+ public void setMsgId(long msgId) {
+ this.msgId = msgId;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof WeixinMessage) {
+ return ((WeixinMessage) obj).getMsgId() == msgId
+ && ((WeixinMessage) obj).getCreateTime() == createTime;
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return " toUserName=" + toUserName + ", fromUserName=" + fromUserName
+ + ", createTime=" + createTime + ", msgType=" + msgType
+ + ", msgId=" + msgId;
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/model/AesToken.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/model/AesToken.java
new file mode 100644
index 00000000..262dd3fe
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/model/AesToken.java
@@ -0,0 +1,52 @@
+package com.foxinmy.weixin4j.model;
+
+import java.io.Serializable;
+
+/**
+ * aes & token
+ *
+ * @className AesToken
+ * @author jy
+ * @date 2015年5月6日
+ * @since JDK 1.7
+ * @see
+ */
+public class AesToken implements Serializable {
+
+ private static final long serialVersionUID = -6001008896414323534L;
+
+ /**
+ * 账号ID
+ */
+ private String appid;
+ /**
+ * 开发者的token
+ */
+ private String token;
+ /**
+ * 安全模式下的加密密钥
+ */
+ private String aesKey;
+
+ public AesToken(String token) {
+ this.token = token;
+ }
+
+ public AesToken(String appid, String token, String aesKey) {
+ this.appid = appid;
+ this.token = token;
+ this.aesKey = aesKey;
+ }
+
+ public String getAppid() {
+ return appid;
+ }
+
+ public String getToken() {
+ return token;
+ }
+
+ public String getAesKey() {
+ return aesKey;
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/model/WeixinAccount.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/model/WeixinAccount.java
deleted file mode 100644
index 19a5f75e..00000000
--- a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/model/WeixinAccount.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.foxinmy.weixin4j.model;
-
-import java.io.Serializable;
-
-/**
- * 微信账号信息
- *
- * @className WeixinAccount
- * @author jy
- * @date 2014年11月18日
- * @since JDK 1.7
- * @see
- */
-public class WeixinAccount implements Serializable {
- private static final long serialVersionUID = -6001008896414323534L;
-
- /**
- * 唯一的身份标识
- */
- private String id;
- /**
- * 调用接口的密钥
- */
- private String secret;
- private String token;
- /**
- * 安全模式下的加密密钥
- */
- private String encodingAesKey;
-
- public WeixinAccount() {
- }
-
- public WeixinAccount(String id, String secret) {
- this.id = id;
- this.secret = secret;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getSecret() {
- return secret;
- }
-
- public void setSecret(String secret) {
- this.secret = secret;
- }
-
- public String getToken() {
- return token;
- }
-
- public void setToken(String token) {
- this.token = token;
- }
-
- public String getEncodingAesKey() {
- return encodingAesKey;
- }
-
- public void setEncodingAesKey(String encodingAesKey) {
- this.encodingAesKey = encodingAesKey;
- }
-
- @Override
- public String toString() {
- return "id=" + id + ", secret=" + secret + ", token=" + token
- + ", encodingAesKey=" + encodingAesKey;
- }
-}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/BlankResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/BlankResponse.java
new file mode 100644
index 00000000..f172bacc
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/BlankResponse.java
@@ -0,0 +1,17 @@
+package com.foxinmy.weixin4j.response;
+
+public class BlankResponse implements WeixinResponse {
+
+ @Override
+ public String getMsgType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String toContent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/DebugResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/DebugResponse.java
new file mode 100644
index 00000000..3cc3d89f
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/DebugResponse.java
@@ -0,0 +1,16 @@
+package com.foxinmy.weixin4j.response;
+
+public class DebugResponse implements WeixinResponse {
+
+ @Override
+ public String getMsgType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String toContent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/ImageResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/ImageResponse.java
new file mode 100644
index 00000000..b0023c58
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/ImageResponse.java
@@ -0,0 +1,37 @@
+package com.foxinmy.weixin4j.response;
+
+/**
+ * 回复图片消息
+ *
+ * @className ImageResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see
+ */
+public class ImageResponse implements WeixinResponse {
+
+ /**
+ * 通过上传多媒体文件,得到的id。
+ */
+ private String mediaId;
+
+ public ImageResponse(String mediaId) {
+ this.mediaId = mediaId;
+ }
+
+ @Override
+ public String toContent() {
+ return String.format(
+ "", mediaId);
+ }
+
+ public String getMediaId() {
+ return mediaId;
+ }
+
+ @Override
+ public String getMsgType() {
+ return "image";
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/MusicResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/MusicResponse.java
new file mode 100644
index 00000000..f5088674
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/MusicResponse.java
@@ -0,0 +1,98 @@
+package com.foxinmy.weixin4j.response;
+
+/**
+ * 回复音乐消息
+ *
+ * @className MusicResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see
+ */
+public class MusicResponse implements WeixinResponse {
+
+ /**
+ * 缩略图的媒体id,通过上传多媒体文件,得到的id
+ */
+ private String thumbMediaId;
+ /**
+ * 音乐标题
+ */
+ private String title;
+ /**
+ * 音乐描述
+ */
+ private String desc;
+ /**
+ * 音乐链接
+ */
+ private String musicUrl;
+ /**
+ * 高质量音乐链接,WIFI环境优先使用该链接播放音乐
+ */
+ private String hqMusicUrl;
+
+ public MusicResponse(String thumbMediaId) {
+ this.thumbMediaId = thumbMediaId;
+ }
+
+ @Override
+ public String toContent() {
+ StringBuilder content = new StringBuilder();
+ content.append("");
+ content.append(String.format(
+ "", thumbMediaId));
+ content.append(String.format("",
+ title != null ? title : ""));
+ content.append(String.format(
+ "",
+ desc != null ? desc : ""));
+ content.append(String.format("",
+ musicUrl != null ? musicUrl : ""));
+ content.append(String.format("",
+ hqMusicUrl != null ? hqMusicUrl : ""));
+ content.append("");
+ return content.toString();
+ }
+
+ public String getThumbMediaId() {
+ return thumbMediaId;
+ }
+
+ public String getMusicUrl() {
+ return musicUrl;
+ }
+
+ public void setMusicUrl(String musicUrl) {
+ this.musicUrl = musicUrl;
+ }
+
+ public String getHqMusicUrl() {
+ return hqMusicUrl;
+ }
+
+ public void setHqMusicUrl(String hqMusicUrl) {
+ this.hqMusicUrl = hqMusicUrl;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+
+ @Override
+ public String getMsgType() {
+ return "music";
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/NewsResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/NewsResponse.java
new file mode 100644
index 00000000..0dc71d24
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/NewsResponse.java
@@ -0,0 +1,159 @@
+package com.foxinmy.weixin4j.response;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 回复图文消息
+ *
+ * @className NewsResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see
+ */
+public class NewsResponse implements WeixinResponse {
+
+ /**
+ * 图文集合
+ */
+ private List articleList;
+
+ public NewsResponse(List articleList) {
+ this.articleList = articleList;
+ }
+
+ public NewsResponse(Article article) {
+ this.articleList = new ArrayList();
+ this.articleList.add(article);
+ }
+
+ public void pushArticle(Article article) {
+ articleList.add(article);
+ }
+
+ public void pushFirstArticle(Article article) {
+ articleList.add(0, article);
+ }
+
+ public void pushLastArticle(Article article) {
+ articleList.add(articleList.size(), article);
+ }
+
+ public Article removeLastArticle() {
+ return articleList.remove(articleList.size() - 1);
+ }
+
+ public Article removeFirstArticle() {
+ return articleList.remove(0);
+ }
+
+ public List getArticleList() {
+ return articleList;
+ }
+
+ @Override
+ public String toContent() {
+ StringBuilder content = new StringBuilder();
+ content.append(String.format("%d",
+ articleList.size()));
+ content.append("");
+ for (Article article : articleList) {
+ content.append("- ");
+ content.append(String.format("",
+ article.getTitle() != null ? article.getTitle() : ""));
+ content.append(String.format(
+ "",
+ article.getDesc() != null ? article.getDesc() : ""));
+ content.append(String.format("",
+ article.getUrl() != null ? article.getUrl() : ""));
+ content.append(String.format("",
+ article.getPicUrl() != null ? article.getPicUrl() : ""));
+ content.append("
");
+ }
+ content.append("");
+ return content.toString();
+ }
+
+ @Override
+ public String getMsgType() {
+ return "news";
+ }
+
+ /**
+ * 图文消息对象
+ *
+ * @className Article
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see
+ */
+ public class Article {
+ /**
+ * 图文消息标题
+ */
+ private String title;
+ /**
+ * 图文消息描述
+ */
+ private String desc;
+ /**
+ * 点击图文消息跳转链接
+ */
+ private String url;
+ /**
+ * 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
+ */
+ private String picUrl;
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getPicUrl() {
+ return picUrl;
+ }
+
+ public void setPicUrl(String picUrl) {
+ this.picUrl = picUrl;
+ }
+
+ public Article() {
+
+ }
+
+ public Article(String title, String desc, String url, String picUrl) {
+ this.title = title;
+ this.desc = desc;
+ this.url = url;
+ this.picUrl = picUrl;
+ }
+
+ @Override
+ public String toString() {
+ return "Article [title=" + title + ", desc=" + desc + ", url="
+ + url + ", picUrl=" + picUrl + "]";
+ }
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/TextResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/TextResponse.java
new file mode 100644
index 00000000..a9a4c9c1
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/TextResponse.java
@@ -0,0 +1,36 @@
+package com.foxinmy.weixin4j.response;
+
+/**
+ * 回复文本消息
+ *
+ * @className TextResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see
+ */
+public class TextResponse implements WeixinResponse {
+
+ /**
+ * 回复的消息内容(换行:在content中能够换行,微信客户端就支持换行显示)
+ */
+ private String content;
+
+ public TextResponse(String content) {
+ this.content = content;
+ }
+
+ @Override
+ public String toContent() {
+ return String.format("", content);
+ }
+
+ @Override
+ public String getMsgType() {
+ return "text";
+ }
+
+ public String getContent() {
+ return content;
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/TransferCustomerResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/TransferCustomerResponse.java
new file mode 100644
index 00000000..39971847
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/TransferCustomerResponse.java
@@ -0,0 +1,43 @@
+package com.foxinmy.weixin4j.response;
+
+/**
+ * 消息转移到客服
+ *
+ * @className TransferCustomerResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see 转移消息到多客服
+ */
+public class TransferCustomerResponse implements WeixinResponse {
+
+ /**
+ * 指定会话接入的客服账号
+ */
+ private String kfAccount;
+
+ public String getKfAccount() {
+ return kfAccount;
+ }
+
+ public void setKfAccount(String kfAccount) {
+ this.kfAccount = kfAccount;
+ }
+
+ @Override
+ public String toContent() {
+ StringBuilder content = new StringBuilder();
+ if (kfAccount != null) {
+ content.append(String
+ .format("",
+ kfAccount));
+ }
+ return content.toString();
+ }
+
+ @Override
+ public String getMsgType() {
+ return "transfer_customer_service";
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/VideoResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/VideoResponse.java
new file mode 100644
index 00000000..20f3ee1e
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/VideoResponse.java
@@ -0,0 +1,76 @@
+package com.foxinmy.weixin4j.response;
+
+/**
+ * 回复视频消息
+ *
+ * @className VideoResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see
+ */
+public class VideoResponse implements WeixinResponse {
+
+ /**
+ * 通过上传多媒体文件,得到的id
+ */
+ private String mediaId;
+ /**
+ * 视频消息标题
+ */
+ private String title;
+ /**
+ * 视频消息描述
+ */
+ private String desc;
+
+ public VideoResponse(String mediaId) {
+ this.mediaId = mediaId;
+ }
+
+ public VideoResponse(String mediaId, String title, String desc) {
+ this.mediaId = mediaId;
+ this.title = title;
+ this.desc = desc;
+ }
+
+ @Override
+ public String toContent() {
+ StringBuilder content = new StringBuilder();
+ content.append("");
+ return content.toString();
+ }
+
+ public String getMediaId() {
+ return mediaId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+
+ @Override
+ public String getMsgType() {
+ return "video";
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/VoiceResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/VoiceResponse.java
new file mode 100644
index 00000000..a09aa1b1
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/VoiceResponse.java
@@ -0,0 +1,37 @@
+package com.foxinmy.weixin4j.response;
+
+/**
+ * 回复语音消息
+ *
+ * @className VoiceResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see
+ */
+public class VoiceResponse implements WeixinResponse {
+
+ /**
+ * 通过上传多媒体文件,得到的id
+ */
+ private String mediaId;
+
+ public VoiceResponse(String mediaId) {
+ this.mediaId = mediaId;
+ }
+
+ @Override
+ public String toContent() {
+ return String.format(
+ "", mediaId);
+ }
+
+ public String getMediaId() {
+ return mediaId;
+ }
+
+ @Override
+ public String getMsgType() {
+ return "voice";
+ }
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/WeixinResponse.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/WeixinResponse.java
new file mode 100644
index 00000000..20b72c53
--- /dev/null
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/response/WeixinResponse.java
@@ -0,0 +1,38 @@
+package com.foxinmy.weixin4j.response;
+
+/**
+ * 微信被动消息回复
+ *
+ * @className WeixinResponse
+ * @author jy
+ * @date 2015年5月5日
+ * @since JDK 1.7
+ * @see TextResponse
+ * @see ImageResponse
+ * @see MusicResponse
+ * @see VoiceResponse
+ * @see VideoResponse
+ * @see NewsResponse
+ * @see TransferCustomerResponse
+ * @see BlankResponse
+ * @see DebugResponse
+ * @see 订阅号、服务号的被动响应消息
+ * @see 企业号的被动响应消息
+ */
+public interface WeixinResponse {
+ /**
+ * 消息类型
+ *
+ * @return
+ */
+ public String getMsgType();
+
+ /**
+ * 消息内容
+ *
+ * @return
+ */
+ public String toContent();
+}
diff --git a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/server/WeixinMessageDecoder.java b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/server/WeixinMessageDecoder.java
index 59eff522..9366faf1 100644
--- a/weixin4j-server/src/main/java/com/foxinmy/weixin4j/server/WeixinMessageDecoder.java
+++ b/weixin4j-server/src/main/java/com/foxinmy/weixin4j/server/WeixinMessageDecoder.java
@@ -12,8 +12,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.foxinmy.weixin4j.message.HttpWeixinMessage;
+import com.foxinmy.weixin4j.model.AesToken;
import com.foxinmy.weixin4j.type.EncryptType;
import com.foxinmy.weixin4j.util.Consts;
+import com.foxinmy.weixin4j.util.MessageUtil;
+import com.foxinmy.weixin4j.xml.EncryptMessageHandler;
/**
* 微信消息解码类
@@ -29,14 +32,17 @@ public class WeixinMessageDecoder extends
MessageToMessageDecoder {
private final Logger log = LoggerFactory.getLogger(getClass());
+ private AesToken aesToken;
+
+ public WeixinMessageDecoder(AesToken aesToken) {
+ this.aesToken = aesToken;
+ }
+
@Override
protected void decode(ChannelHandlerContext ctx, FullHttpRequest req,
- List