up
This commit is contained in:
parent
291e19c17f
commit
45b9c75e1a
@ -37,7 +37,7 @@
|
|||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-all</artifactId>
|
<artifactId>netty-all</artifactId>
|
||||||
<version>4.0.30.Final</version>
|
<version>4.0.30.Final</version>
|
||||||
<optional>true</optional>
|
<optional>false</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
|||||||
@ -110,7 +110,8 @@ public class WeixinRequestExecutor {
|
|||||||
// always contain the question mark
|
// always contain the question mark
|
||||||
StringBuilder buf = new StringBuilder(url);
|
StringBuilder buf = new StringBuilder(url);
|
||||||
if (parameters != null && parameters.length > 0) {
|
if (parameters != null && parameters.length > 0) {
|
||||||
buf.append("&").append(FormUrlEntity.formatParameters(Arrays.asList(parameters)));
|
buf.append("&").append(
|
||||||
|
FormUrlEntity.formatParameters(Arrays.asList(parameters)));
|
||||||
}
|
}
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.GET, buf.toString());
|
HttpRequest request = new HttpRequest(HttpMethod.GET, buf.toString());
|
||||||
return doRequest(request);
|
return doRequest(request);
|
||||||
@ -127,13 +128,17 @@ public class WeixinRequestExecutor {
|
|||||||
public WeixinResponse doRequest(HttpRequest request) throws WeixinException {
|
public WeixinResponse doRequest(HttpRequest request) throws WeixinException {
|
||||||
try {
|
try {
|
||||||
if (logger.isEnabled(InternalLogLevel.DEBUG)) {
|
if (logger.isEnabled(InternalLogLevel.DEBUG)) {
|
||||||
logger.debug("weixin request >> " + request.getMethod() + " "
|
logger.debug("weixin request >> "
|
||||||
+ request.getURI().toString());
|
+ request.getMethod()
|
||||||
printHttpRequest(request,InternalLogLevel.DEBUG);
|
+ " "
|
||||||
|
+ request.getURI().toString()
|
||||||
|
+ (request.getEntity() instanceof StringEntity ? " >> "
|
||||||
|
+ ((StringEntity) request.getEntity())
|
||||||
|
.getContentString() : ""));
|
||||||
}
|
}
|
||||||
HttpResponse httpResponse = httpClient.execute(request);
|
HttpResponse httpResponse = httpClient.execute(request);
|
||||||
WeixinResponse response = new WeixinResponse(httpResponse);
|
WeixinResponse response = new WeixinResponse(httpResponse);
|
||||||
handleResponse(request,response);
|
handleResponse(response);
|
||||||
return response;
|
return response;
|
||||||
} catch (HttpClientException e) {
|
} catch (HttpClientException e) {
|
||||||
throw new WeixinException(e);
|
throw new WeixinException(e);
|
||||||
@ -165,14 +170,14 @@ public class WeixinRequestExecutor {
|
|||||||
* 微信请求响应
|
* 微信请求响应
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
protected void handleResponse(HttpRequest request,WeixinResponse response)
|
protected void handleResponse(WeixinResponse response)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
boolean hasStreamMimeType = hasStreamMimeType(response);
|
boolean hasStreamMimeType = hasStreamMimeType(response);
|
||||||
if (logger.isEnabled(InternalLogLevel.DEBUG)) {
|
if (logger.isEnabled(InternalLogLevel.DEBUG)) {
|
||||||
logger.debug("weixin response << "
|
logger.debug("weixin response << "
|
||||||
+ response.getProtocol()
|
+ response.getProtocol()
|
||||||
+ response.getStatus()
|
+ response.getStatus()
|
||||||
+ ":"
|
+ " << "
|
||||||
+ (hasStreamMimeType ? response.getHeaders()
|
+ (hasStreamMimeType ? response.getHeaders()
|
||||||
.getContentType() : response.getAsString()));
|
.getContentType() : response.getAsString()));
|
||||||
}
|
}
|
||||||
@ -182,7 +187,6 @@ public class WeixinRequestExecutor {
|
|||||||
ApiResult result = response.getAsResult();
|
ApiResult result = response.getAsResult();
|
||||||
if (!SUCCESS_CODE.contains(String.format(",%s,", result.getReturnCode()
|
if (!SUCCESS_CODE.contains(String.format(",%s,", result.getReturnCode()
|
||||||
.toLowerCase()))) {
|
.toLowerCase()))) {
|
||||||
printHttpRequest(request,InternalLogLevel.WARN);
|
|
||||||
throw new WeixinException(result.getReturnCode(),
|
throw new WeixinException(result.getReturnCode(),
|
||||||
result.getReturnMsg());
|
result.getReturnMsg());
|
||||||
}
|
}
|
||||||
@ -192,7 +196,6 @@ public class WeixinRequestExecutor {
|
|||||||
XmlResult.class, response);
|
XmlResult.class, response);
|
||||||
if (!SUCCESS_CODE.contains(String.format(",%s,", xmlResult
|
if (!SUCCESS_CODE.contains(String.format(",%s,", xmlResult
|
||||||
.getResultCode().toLowerCase()))) {
|
.getResultCode().toLowerCase()))) {
|
||||||
printHttpRequest(request,InternalLogLevel.WARN);
|
|
||||||
throw new WeixinException(xmlResult.getErrCode(),
|
throw new WeixinException(xmlResult.getErrCode(),
|
||||||
xmlResult.getErrCodeDes());
|
xmlResult.getErrCodeDes());
|
||||||
}
|
}
|
||||||
@ -202,18 +205,6 @@ public class WeixinRequestExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printHttpRequest(HttpRequest request,InternalLogLevel level){
|
|
||||||
if(request.getEntity() instanceof StringEntity){
|
|
||||||
if(level.equals(InternalLogLevel.DEBUG)) {
|
|
||||||
logger.debug("weixin request body >> " + ((StringEntity) request.getEntity()).getContentString());
|
|
||||||
}else if(level.equals(InternalLogLevel.INFO)){
|
|
||||||
logger.info("weixin request body >> " + ((StringEntity) request.getEntity()).getContentString());
|
|
||||||
}else if(level.equals(InternalLogLevel.WARN)){
|
|
||||||
logger.warn("weixin request body >> " + ((StringEntity) request.getEntity()).getContentString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpClient getExecuteClient() {
|
public HttpClient getExecuteClient() {
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.7.0</version>
|
<version>1.7.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>weixin4j-server</artifactId>
|
<artifactId>weixin4j-server</artifactId>
|
||||||
<version>1.1.8</version>
|
<version>1.1.8</version>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user