weixin4j-server:新增企业号消息服务相关类

This commit is contained in:
jinyu
2015-08-02 00:03:47 +08:00
parent 97dc88d7c7
commit 8ed7ba3f49
17 changed files with 487 additions and 44 deletions
@@ -0,0 +1,33 @@
package com.foxinmy.weixin4j.qy.chat;
/**
* 会话事件
*
* @className ChatEventType
* @author jy
* @date 2015年8月1日
* @since JDK 1.7
* @see
*/
public enum ChatEventType {
/**
* 创建会话
*/
create_chat,
/**
* 修改会话
*/
update_chat,
/**
* 退出会话
*/
quit_chat,
/**
* 订阅事件
*/
subscribe,
/**
* 取消订阅事件
*/
unsubscribe;
}
@@ -0,0 +1,216 @@
package com.foxinmy.weixin4j.qy.chat;
import java.beans.Transient;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 会话事件或消息
*
* @className ChatItem
* @author jy
* @date 2015年8月1日
* @since JDK 1.7
* @see
*/
public class ChatItem implements Serializable {
private static final long serialVersionUID = -5921235260175596270L;
public final String LIST_SEPARATOR = "|";
/**
* 操作成员UserID
*/
@XmlElement(name = "FromUserName")
private String operatorId;
/**
* 消息创建时间(整型)
*/
@XmlElement(name = "CreateTime")
private long createTime;
/**
* 消息类型
*
*/
@XmlElement(name = "MsgType")
private String msgType;
/**
* 事件类型
*/
@XmlElement(name = "Event")
private String eventType;
/**
* 会话id
*/
@XmlElement(name = "ChatId")
private String chatId;
/**
* 会话标题
*/
@XmlElement(name = "Name")
private String chatName;
/**
* 管理员userid
*/
@XmlElement(name = "Owner")
private String ownerId;
/**
* 会话成员列表
*/
@XmlElement(name = "UserList")
private String members;
/**
* 会话新增成员列表
*/
@XmlElement(name = "AddUserList")
private String addMembers;
/**
* 会话删除成员列表
*/
@XmlElement(name = "DelUserList")
private String deleteMembers;
/**
* 消息ID 64位整型
*/
@XmlElement(name = "MsgId")
private long msgId;
/**
* 接收人
*/
@XmlElement(name = "Receiver")
private ChatReceiver receiver;
/**
* 文本消息内容
*/
@XmlElement(name = "Content")
private String content;
/**
* 图片链接
*/
@XmlElement(name = "PicUrl")
private String picUrl;
/**
* 图片媒体文件id,可以调用获取媒体文件接口拉取数据
*/
@XmlElement(name = "MediaId")
private String mediaId;
public String getOperatorId() {
return operatorId;
}
public long getCreateTime() {
return createTime;
}
@Transient
@XmlTransient
public Date getFormatCreateTime() {
return createTime > 0l ? new Date(createTime * 1000l) : null;
}
public String getMsgType() {
return msgType;
}
@Transient
@XmlTransient
public MessageType getFormatMsgType() {
return msgType != null ? MessageType.valueOf(msgType) : null;
}
public String getEventType() {
return eventType;
}
@Transient
@XmlTransient
public ChatEventType getFormatEventType() {
return eventType != null ? ChatEventType.valueOf(eventType) : null;
}
public String getChatId() {
return chatId;
}
public String getChatName() {
return chatName;
}
public String getOwnerId() {
return ownerId;
}
public String getMembers() {
return members;
}
@Transient
@XmlTransient
public List<String> getFormatMembers() {
return members != null ? Arrays.asList(members.split(LIST_SEPARATOR))
: null;
}
public String getAddMembers() {
return addMembers;
}
@Transient
@XmlTransient
public List<String> getFormatAddMembers() {
return addMembers != null ? Arrays.asList(addMembers
.split(LIST_SEPARATOR)) : null;
}
public String getDeleteMembers() {
return deleteMembers;
}
@Transient
@XmlTransient
public List<String> getFormatDeleteMembers() {
return deleteMembers != null ? Arrays.asList(deleteMembers
.split(LIST_SEPARATOR)) : null;
}
public long getMsgId() {
return msgId;
}
public ChatReceiver getReceiver() {
return receiver;
}
public String getContent() {
return content;
}
public String getPicUrl() {
return picUrl;
}
public String getMediaId() {
return mediaId;
}
@Override
public String toString() {
return "ChatItem [operatorId=" + operatorId + ", createTime="
+ createTime + ", msgType=" + msgType + ", eventType="
+ eventType + ", chatId=" + chatId + ", chatName=" + chatName
+ ", ownerId=" + ownerId + ", members=" + members
+ ", addMembers=" + addMembers + ", deleteMembers="
+ deleteMembers + ", msgId=" + msgId + ", receiver=" + receiver
+ ", content=" + content + ", picUrl=" + picUrl + ", mediaId="
+ mediaId + "]";
}
}
@@ -0,0 +1,52 @@
package com.foxinmy.weixin4j.qy.chat;
import java.beans.Transient;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
/**
* 接收人
*
* @className ChatReceiver
* @author jy
* @date 2015年8月1日
* @since JDK 1.7
* @see
*/
public class ChatReceiver implements Serializable {
private static final long serialVersionUID = -3870813624685620828L;
/**
* 成员id|会话id
*/
@XmlElement(name = "id")
private String targetId;
/**
* 群聊|单聊
*/
@XmlElement(name = "type")
private String chatType;
public String getTargetId() {
return targetId;
}
public String getChatType() {
return chatType;
}
@Transient
@XmlTransient
public ChatType getFormatChatType() {
return ChatType.valueOf(chatType);
}
@Override
public String toString() {
return "ChatReceiver [targetId=" + targetId + ", chatType=" + chatType
+ "]";
}
}
@@ -0,0 +1,21 @@
package com.foxinmy.weixin4j.qy.chat;
/**
* 会话类型
*
* @className ChatType
* @author jy
* @date 2015年7月31日
* @since JDK 1.7
* @see
*/
public enum ChatType {
/**
* 单聊
*/
single,
/**
* 群聊
*/
group
}
@@ -0,0 +1,88 @@
package com.foxinmy.weixin4j.qy.chat;
import java.beans.Transient;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.foxinmy.weixin4j.type.AgentType;
/**
* 企业号聊天服务回调消息
*
* @className WeixinChatMessage
* @author jy
* @date 2015年8月1日
* @since JDK 1.7
* @see
*/
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class WeixinChatMessage implements Serializable {
private static final long serialVersionUID = 6788124387186831643L;
/**
* 企业号CorpID
*/
@XmlElement(name = "ToUserName")
private String corpId;
/**
* 应用类型
*/
@XmlElement(name = "AgentType")
private String agentType;
/**
* 消息数量
*/
@XmlElement(name = "ItemCount")
private int itemCount;
/**
* 会话事件或消息
*/
@XmlElement(name = "Item")
public List<ChatItem> items;
/**
* 回调包ID,uint64类型,企业内唯一
*/
@XmlElement(name = "PackageId")
private String packageId;
public String getCorpId() {
return corpId;
}
public String getAgentType() {
return agentType;
}
@Transient
@XmlTransient
public AgentType getFormatAgentType() {
return AgentType.valueOf(agentType);
}
public int getItemCount() {
return itemCount;
}
public List<ChatItem> getItems() {
return items;
}
public String getPackageId() {
return packageId;
}
@Override
public String toString() {
return "WeixinChatMessage [corpId=" + corpId + ", agentType="
+ agentType + ", itemCount=" + itemCount + ", items=" + items
+ ", packageId=" + packageId + "]";
}
}
@@ -0,0 +1,26 @@
package com.foxinmy.weixin4j.qy.suite;
/**
* 应用套件回调事件
*
* @className SuiteEventType
* @author jy
* @date 2015年6月21日
* @since JDK 1.7
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%9B%9E%E8%B0%83%E5%8D%8F%E8%AE%AE">第三方回调协议</a>
*/
public enum SuiteEventType {
/**
* 推送ticket
*/
suite_ticket,
/**
* 变更授权
*/
change_auth,
/**
* 取消授权
*/
cancel_auth;
}
@@ -0,0 +1,91 @@
package com.foxinmy.weixin4j.qy.suite;
import java.beans.Transient;
import java.io.Serializable;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
* 套件消息
*
* @className WeixinSuiteMessage
* @author jy
* @date 2015年6月23日
* @since JDK 1.7
* @see
*/
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class WeixinSuiteMessage implements Serializable {
private static final long serialVersionUID = 6457919241019021514L;
/**
* 应用套件的SuiteId
*/
@XmlElement(name = "SuiteId")
private String suiteId;
/**
* 事件类型
*/
@XmlElement(name = "InfoType")
private String eventType;
/**
* 时间戳
*/
@XmlElement(name = "TimeStamp")
private long timeStamp;
/**
* Ticket内容
*/
@XmlElement(name = "SuiteTicket")
private String SuiteTicket;
/**
* 授权方企业号的corpid
*/
@XmlElement(name = "AuthCorpId")
private String authCorpId;
public String getSuiteId() {
return suiteId;
}
public String getEventType() {
return eventType;
}
@Transient
@XmlTransient
public SuiteEventType getFormatEventType() {
return SuiteEventType.valueOf(eventType);
}
public long getTimeStamp() {
return timeStamp;
}
@Transient
@XmlTransient
public Date getFormatTimeStamp() {
return timeStamp > 0l ? new Date(timeStamp * 1000l) : null;
}
public String getSuiteTicket() {
return SuiteTicket;
}
public String getAuthCorpId() {
return authCorpId;
}
@Override
public String toString() {
return "WeixinSuiteMessage [suiteId=" + suiteId + ", eventType="
+ eventType + ", timeStamp=" + timeStamp + ", SuiteTicket="
+ SuiteTicket + ", authCorpId=" + authCorpId + "]";
}
}
@@ -7,6 +7,8 @@ import java.util.Date;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 微信消息基类
*
@@ -103,6 +105,12 @@ public class WeixinMessage implements Serializable {
return msgType;
}
@Transient
@XmlTransient
public MessageType getFormatMsgType() {
return MessageType.valueOf(msgType);
}
public long getMsgId() {
return msgId;
}
@@ -130,11 +130,17 @@ public final class WeixinServerBootstrap {
* @param messageMatcher
* 消息匹配器
* @param aesTokens
* 多个公众号
* 公众号信息
* @return
*/
public WeixinServerBootstrap(WeixinMessageMatcher messageMatcher,
AesToken... aesTokens) {
if (messageMatcher == null) {
throw new IllegalArgumentException("MessageMatcher not be null");
}
if (aesTokens == null) {
throw new IllegalArgumentException("AesToken not be null");
}
this.aesTokenMap = new HashMap<String, AesToken>();
for (AesToken aesToken : aesTokens) {
this.aesTokenMap.put(aesToken.getWeixinId(), aesToken);
@@ -0,0 +1,17 @@
package com.foxinmy.weixin4j.type;
/**
* 应用类型
*
* @className AgentType
* @author jy
* @date 2015年8月1日
* @since JDK 1.7
* @see
*/
public enum AgentType {
/**
* 聊天应用
*/
chat
}