初始化开放平台第三方组件
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
package com.foxinmy.weixin4j.mp.component;
|
||||
|
||||
/**
|
||||
* 应用组件回调事件
|
||||
*
|
||||
* @className ComponentEventType
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年7月5日
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public enum ComponentEventType {
|
||||
/**
|
||||
* 推送ticket
|
||||
*/
|
||||
component_verify_ticket,
|
||||
/**
|
||||
* 取消授权
|
||||
*/
|
||||
unauthorized,
|
||||
/**
|
||||
* 授权成功
|
||||
*/
|
||||
authorized,
|
||||
/**
|
||||
* 授权更新
|
||||
*/
|
||||
updateauthorized
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package com.foxinmy.weixin4j.mp.component;
|
||||
|
||||
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 ComponentMessage
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年7月5日
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
@XmlRootElement(name = "xml")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ComponentMessage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7243616276403632118L;
|
||||
/**
|
||||
* 第三方平台appid
|
||||
*/
|
||||
@XmlElement(name = "AppId")
|
||||
private String appId;
|
||||
/**
|
||||
* 事件类型
|
||||
*/
|
||||
@XmlElement(name = "InfoType")
|
||||
private String eventType;
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
@XmlElement(name = "CreateTime")
|
||||
private long createTime;
|
||||
/**
|
||||
* Ticket内容
|
||||
*/
|
||||
@XmlElement(name = "ComponentVerifyTicket")
|
||||
private String verifyTicket;
|
||||
/**
|
||||
* 授权方的Appid
|
||||
*/
|
||||
@XmlElement(name = "AuthorizerAppid")
|
||||
private String authAppId;
|
||||
/**
|
||||
* 授权码,可用于换取公众号的接口调用凭据
|
||||
*/
|
||||
@XmlElement(name = "AuthorizationCode")
|
||||
private String authCode;
|
||||
/**
|
||||
* 授权码过期时间
|
||||
*/
|
||||
@XmlElement(name = "AuthorizationCodeExpiredTime")
|
||||
private long authCodeExpiredTime;
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public String getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public ComponentEventType getFormatEventType() {
|
||||
return ComponentEventType.valueOf(eventType);
|
||||
}
|
||||
|
||||
public long getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public Date getFormatCreateTime() {
|
||||
return createTime > 0l ? new Date(createTime * 1000l) : null;
|
||||
}
|
||||
|
||||
public String getVerifyTicket() {
|
||||
return verifyTicket;
|
||||
}
|
||||
|
||||
public String getAuthAppId() {
|
||||
return authAppId;
|
||||
}
|
||||
|
||||
public String getAuthCode() {
|
||||
return authCode;
|
||||
}
|
||||
|
||||
public long getAuthCodeExpiredTime() {
|
||||
return authCodeExpiredTime;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public Date getFormatAuthCodeExpiredTime() {
|
||||
return authCodeExpiredTime > 0l ? new Date(authCodeExpiredTime * 1000l) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ComponentMessage [appId=" + appId + ", eventType=" + eventType + ", createTime=" + createTime
|
||||
+ ", verifyTicket=" + verifyTicket + ", authAppId=" + authAppId + ", authCode=" + authCode
|
||||
+ ", authCodeExpiredTime=" + authCodeExpiredTime + "]";
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.foxinmy.weixin4j.server.ext;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.handler.WeixinMessageHandler;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteEventType;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteMessage;
|
||||
import com.foxinmy.weixin4j.request.WeixinMessage;
|
||||
import com.foxinmy.weixin4j.request.WeixinRequest;
|
||||
import com.foxinmy.weixin4j.response.BlankResponse;
|
||||
import com.foxinmy.weixin4j.response.WeixinResponse;
|
||||
|
||||
/**
|
||||
* 企业号套件消息处理
|
||||
*
|
||||
* @className SuiteMessageHandler
|
||||
* @author jy
|
||||
* @date 2015年6月25日
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public class SuiteMessageHandler implements WeixinMessageHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(WeixinRequest request, WeixinMessage message, Set<String> nodeNames)
|
||||
throws WeixinException {
|
||||
return nodeNames.contains("suiteid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeixinResponse doHandle(WeixinRequest request, WeixinMessage message, Set<String> nodeNames)
|
||||
throws WeixinException {
|
||||
SuiteMessage suiteMessage = null; // 转换为 SuiteMessage
|
||||
SuiteEventType eventType = suiteMessage.getFormatEventType();
|
||||
if (eventType == SuiteEventType.suite_ticket) {
|
||||
// do something
|
||||
} else if (eventType == SuiteEventType.change_auth) {
|
||||
// do something
|
||||
} else if (eventType == SuiteEventType.cancel_auth) {
|
||||
// do something
|
||||
}
|
||||
return BlankResponse.global;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int weight() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user