优化代码,增加日志

This commit is contained in:
Binary Wang
2018-08-27 21:03:32 +08:00
parent 3bc2bbc208
commit 5f1290720e
21 changed files with 149 additions and 87 deletions

View File

@@ -1,25 +1,28 @@
package me.chanjar.weixin.open.bean.message;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import org.apache.commons.io.IOUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
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
@Slf4j
@XStreamAlias("xml")
public class WxOpenXmlMessage implements Serializable {
private static final long serialVersionUID = -5641769554709507771L;
@@ -78,30 +81,26 @@ public class WxOpenXmlMessage implements Serializable {
* @param nonce 随机串
* @param msgSignature 签名串
*/
public static WxOpenXmlMessage fromEncryptedXml(String encryptedXml,
WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce,
String 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);
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml);
log.debug("解密后的原始xml消息内容{}", plainText);
return fromXml(plainText);
}
public static WxMpXmlMessage fromEncryptedMpXml(String encryptedXml,
WxOpenConfigStorage wxOpenConfigStorage, String timestamp, String nonce,
String msgSignature) {
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);
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) {
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);
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"),
wxOpenConfigStorage, timestamp, nonce, msgSignature);
} catch (IOException e) {
throw new RuntimeException(e);
}