mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-15 18:55:13 +08:00
打印微信请求日志时地址中附带access_token #200
This commit is contained in:
@@ -1,16 +1,9 @@
|
|||||||
package me.chanjar.weixin.mp.api.impl;
|
package me.chanjar.weixin.mp.api.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||||
import me.chanjar.weixin.common.bean.result.WxError;
|
import me.chanjar.weixin.common.bean.result.WxError;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
@@ -22,8 +15,13 @@ import me.chanjar.weixin.common.util.http.*;
|
|||||||
import me.chanjar.weixin.mp.api.*;
|
import me.chanjar.weixin.mp.api.*;
|
||||||
import me.chanjar.weixin.mp.bean.*;
|
import me.chanjar.weixin.mp.bean.*;
|
||||||
import me.chanjar.weixin.mp.bean.result.*;
|
import me.chanjar.weixin.mp.bean.result.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public abstract class AbstractWxMpService<H,P> implements WxMpService,RequestHttp<H,P> {
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
|
||||||
|
public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, RequestHttp<H, P> {
|
||||||
|
|
||||||
private static final JsonParser JSON_PARSER = new JsonParser();
|
private static final JsonParser JSON_PARSER = new JsonParser();
|
||||||
|
|
||||||
@@ -46,7 +44,6 @@ public abstract class AbstractWxMpService<H,P> implements WxMpService,RequestHtt
|
|||||||
private int retrySleepMillis = 1000;
|
private int retrySleepMillis = 1000;
|
||||||
private int maxRetryTimes = 5;
|
private int maxRetryTimes = 5;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkSignature(String timestamp, String nonce, String signature) {
|
public boolean checkSignature(String timestamp, String nonce, String signature) {
|
||||||
try {
|
try {
|
||||||
@@ -296,7 +293,6 @@ public abstract class AbstractWxMpService<H,P> implements WxMpService,RequestHtt
|
|||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
T result = executeInternal(executor, uri, data);
|
T result = executeInternal(executor, uri, data);
|
||||||
this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, result);
|
|
||||||
return result;
|
return result;
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
if (retryTimes + 1 > this.maxRetryTimes) {
|
if (retryTimes + 1 > this.maxRetryTimes) {
|
||||||
@@ -326,16 +322,22 @@ public abstract class AbstractWxMpService<H,P> implements WxMpService,RequestHtt
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
public synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||||
if (uri.indexOf("access_token=") != -1) {
|
if (uri.contains("access_token=")) {
|
||||||
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
|
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
|
||||||
}
|
}
|
||||||
String accessToken = getAccessToken(false);
|
String accessToken = getAccessToken(false);
|
||||||
|
|
||||||
String uriWithAccessToken = uri;
|
String uriWithAccessToken;
|
||||||
uriWithAccessToken += uri.indexOf('?') == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken;
|
if (uri.contains("?")) {
|
||||||
|
uriWithAccessToken = uri + "&access_token=" + accessToken;
|
||||||
|
} else {
|
||||||
|
uriWithAccessToken = uri + "?access_token=" + accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return executor.execute(this, uriWithAccessToken, data);
|
T result = executor.execute(this, uriWithAccessToken, data);
|
||||||
|
this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uriWithAccessToken, data, result);
|
||||||
|
return result;
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
WxError error = e.getError();
|
WxError error = e.getError();
|
||||||
/*
|
/*
|
||||||
@@ -352,12 +354,12 @@ public abstract class AbstractWxMpService<H,P> implements WxMpService,RequestHtt
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, error);
|
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uriWithAccessToken, data, error);
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", uri, data, e.getMessage());
|
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", uriWithAccessToken, data, e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,12 +16,12 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
|||||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||||
import me.chanjar.weixin.mp.api.impl.AbstractWxMpService;
|
import me.chanjar.weixin.mp.api.impl.AbstractWxMpServiceImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* apache-http方式实现
|
* apache-http方式实现
|
||||||
*/
|
*/
|
||||||
public class WxMpServiceImpl extends AbstractWxMpService<CloseableHttpClient,HttpHost> {
|
public class WxMpServiceImpl extends AbstractWxMpServiceImpl<CloseableHttpClient,HttpHost> {
|
||||||
private CloseableHttpClient httpClient;
|
private CloseableHttpClient httpClient;
|
||||||
private HttpHost httpProxy;
|
private HttpHost httpProxy;
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ import java.util.concurrent.locks.Lock;
|
|||||||
/**
|
/**
|
||||||
* jodd-http方式实现
|
* jodd-http方式实现
|
||||||
*/
|
*/
|
||||||
public class WxMpServiceImpl extends AbstractWxMpService<HttpConnectionProvider,ProxyInfo> {
|
public class WxMpServiceImpl extends AbstractWxMpServiceImpl<HttpConnectionProvider,ProxyInfo> {
|
||||||
private HttpConnectionProvider httpClient;
|
private HttpConnectionProvider httpClient;
|
||||||
private ProxyInfo httpProxy;
|
private ProxyInfo httpProxy;
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ import me.chanjar.weixin.mp.api.*;
|
|||||||
import me.chanjar.weixin.mp.api.impl.*;
|
import me.chanjar.weixin.mp.api.impl.*;
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
|
|
||||||
public class WxMpServiceImpl extends AbstractWxMpService<ConnectionPool, OkhttpProxyInfo> {
|
public class WxMpServiceImpl extends AbstractWxMpServiceImpl<ConnectionPool, OkhttpProxyInfo> {
|
||||||
|
|
||||||
|
|
||||||
private ConnectionPool httpClient;
|
private ConnectionPool httpClient;
|
||||||
|
Reference in New Issue
Block a user