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