mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
# 368 增加 微信第三方平台 模块
* 增加 微信第三方平台 接口 * WxOpenXmlMessage 消息处理
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package me.chanjar.weixin.open.bean;
|
||||
|
||||
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxOpenAuthorizerAccessToken implements Serializable{
|
||||
|
||||
private String authorizerAccessToken;
|
||||
|
||||
private int expiresIn = -1;
|
||||
|
||||
public static WxOpenAuthorizerAccessToken fromJson(String json) {
|
||||
return WxOpenGsonBuilder.create().fromJson(json, WxOpenAuthorizerAccessToken.class);
|
||||
}
|
||||
|
||||
public String getAuthorizerAccessToken() {
|
||||
return authorizerAccessToken;
|
||||
}
|
||||
|
||||
public void setAuthorizerAccessToken(String authorizerAccessToken) {
|
||||
this.authorizerAccessToken = authorizerAccessToken;
|
||||
}
|
||||
|
||||
public int getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(int expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.chanjar.weixin.open.bean;
|
||||
|
||||
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxOpenComponentAccessToken implements Serializable{
|
||||
|
||||
private String componentAccessToken;
|
||||
|
||||
private int expiresIn = -1;
|
||||
|
||||
public static WxOpenComponentAccessToken fromJson(String json) {
|
||||
return WxOpenGsonBuilder.create().fromJson(json, WxOpenComponentAccessToken.class);
|
||||
}
|
||||
|
||||
public String getComponentAccessToken() {
|
||||
return componentAccessToken;
|
||||
}
|
||||
|
||||
public void setComponentAccessToken(String componentAccessToken) {
|
||||
this.componentAccessToken = componentAccessToken;
|
||||
}
|
||||
|
||||
public int getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(int expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.chanjar.weixin.open.bean.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxOpenAuthorizationInfo implements Serializable{
|
||||
private String authorizerAppid;
|
||||
private String authorizerAccessToken;
|
||||
private int expiresIn;
|
||||
private String authorizerRefreshToken;
|
||||
private List<Integer> funcInfo;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.chanjar.weixin.open.bean.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxOpenAuthorizerInfo implements Serializable{
|
||||
private String nickName;
|
||||
private String headImg;
|
||||
private Integer serviceTypeInfo;
|
||||
private Integer verifyTypeInfo;
|
||||
private String userName;
|
||||
private String principalName;
|
||||
private Map<String, Integer> businessInfo;
|
||||
private String alias;
|
||||
private String qrcodeUrl;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package me.chanjar.weixin.open.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
|
||||
import me.chanjar.weixin.open.util.WxOpenCryptUtil;
|
||||
import me.chanjar.weixin.open.util.xml.XStreamTransformer;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
@Data
|
||||
public class WxOpenXmlMessage implements Serializable{
|
||||
@XStreamAlias("AppId")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String appId;
|
||||
|
||||
@XStreamAlias("CreateTime")
|
||||
private Long createTime;
|
||||
|
||||
@XStreamAlias("InfoType")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String infoType;
|
||||
|
||||
@XStreamAlias("ComponentVerifyTicket")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String componentVerifyTicket;
|
||||
|
||||
@XStreamAlias("AuthorizerAppid")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String authorizerAppid;
|
||||
|
||||
@XStreamAlias("AuthorizationCode")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String authorizationCode;
|
||||
|
||||
@XStreamAlias("AuthorizationCodeExpiredTime")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private Long authorizationCodeExpiredTime;
|
||||
|
||||
@XStreamAlias("PreAuthCode")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String preAuthCode;
|
||||
|
||||
public static WxOpenXmlMessage fromXml(String xml) {
|
||||
//修改微信变态的消息内容格式,方便解析
|
||||
xml = xml.replace("</PicList><PicList>", "");
|
||||
return XStreamTransformer.fromXml(WxOpenXmlMessage.class, xml);
|
||||
}
|
||||
|
||||
public static WxOpenXmlMessage fromXml(InputStream is) {
|
||||
return XStreamTransformer.fromXml(WxOpenXmlMessage.class, is);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从加密字符串转换
|
||||
*
|
||||
* @param encryptedXml 密文
|
||||
* @param wxOpenConfigStorage 配置存储器对象
|
||||
* @param timestamp 时间戳
|
||||
* @param nonce 随机串
|
||||
* @param msgSignature 签名串
|
||||
*/
|
||||
public static WxOpenXmlMessage fromEncryptedXml(String encryptedXml,
|
||||
WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce,
|
||||
String msgSignature) {
|
||||
WxOpenCryptUtil cryptUtil = new WxOpenCryptUtil(wxOpenConfigStorage);
|
||||
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce,
|
||||
encryptedXml);
|
||||
return fromXml(plainText);
|
||||
}
|
||||
public static WxMpXmlMessage fromEncryptedMpXml(String encryptedXml,
|
||||
WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce,
|
||||
String msgSignature) {
|
||||
WxOpenCryptUtil cryptUtil = new WxOpenCryptUtil(wxOpenConfigStorage);
|
||||
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce,
|
||||
encryptedXml);
|
||||
return WxMpXmlMessage.fromXml(plainText);
|
||||
}
|
||||
|
||||
public static WxOpenXmlMessage fromEncryptedXml(InputStream is,
|
||||
WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce,
|
||||
String msgSignature) {
|
||||
try {
|
||||
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxOpenConfigStorage,
|
||||
timestamp, nonce, msgSignature);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package me.chanjar.weixin.open.bean.result;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo;
|
||||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxOpenAuthorizerInfoResult implements Serializable{
|
||||
private WxOpenAuthorizationInfo authorizationInfo;
|
||||
private WxOpenAuthorizerInfo authorizerInfo;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package me.chanjar.weixin.open.bean.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxOpenAuthorizerOptionResult implements Serializable{
|
||||
String authorizerAppid;
|
||||
String optionName;
|
||||
String optionValue;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package me.chanjar.weixin.open.bean.result;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxOpenQueryAuthResult implements Serializable{
|
||||
private WxOpenAuthorizationInfo authorizationInfo;
|
||||
}
|
||||
Reference in New Issue
Block a user