Merge branch 'develop' into develop
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-parent</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<version>2.7.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-common</artifactId>
|
||||
@@ -39,6 +39,11 @@
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jodd</groupId>
|
||||
<artifactId>jodd-http</artifactId>
|
||||
<version>3.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -10,6 +10,7 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.fs.FileUtils;
|
||||
import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler;
|
||||
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
|
||||
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
|
||||
import okhttp3.*;
|
||||
|
||||
@@ -111,7 +112,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = getFileName(response);
|
||||
String fileName = getFileNameApache(response);
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
return null;
|
||||
}
|
||||
@@ -128,7 +129,6 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
|
||||
|
||||
/**
|
||||
* jodd-http实现方式
|
||||
*
|
||||
* @param provider
|
||||
* @param proxyInfo
|
||||
* @param uri
|
||||
@@ -237,7 +237,23 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
|
||||
if (m.matches()) {
|
||||
return m.group(1);
|
||||
}
|
||||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build());
|
||||
request.withConnectionProvider(provider);
|
||||
HttpResponse response = request.send();
|
||||
String contentType = response.header("Content-Type");
|
||||
if (contentType != null && contentType.startsWith("application/json")) {
|
||||
// application/json; encoding=utf-8 下载媒体文件出错
|
||||
throw new WxErrorException(WxError.fromJson(response.bodyText()));
|
||||
}
|
||||
|
||||
String fileName = getFileNameJodd(response);
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(response.bodyBytes());
|
||||
String[] nameAndExt = fileName.split("\\.");
|
||||
return FileUtils.createTmpFile(inputStream, nameAndExt[0], nameAndExt[1], this.tmpDirFile);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
|
||||
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
|
||||
import okhttp3.*;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.chanjar.weixin.common.util.http;
|
||||
import jodd.http.HttpConnectionProvider;
|
||||
import jodd.http.ProxyInfo;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
|
||||
import okhttp3.ConnectionPool;
|
||||
|
||||
@@ -63,5 +64,4 @@ public interface RequestExecutor<T, E> {
|
||||
*/
|
||||
T executeOkhttp(ConnectionPool pool, final OkhttpProxyInfo proxyInfo, String uri, E data) throws WxErrorException, IOException;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import jodd.http.ProxyInfo;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
|
||||
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
|
||||
import okhttp3.*;
|
||||
|
||||
@@ -28,6 +29,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, String> {
|
||||
|
||||
|
||||
/**
|
||||
* apache-http实现方式
|
||||
*
|
||||
@@ -98,6 +100,7 @@ public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, St
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* okHttp实现方式
|
||||
*
|
||||
@@ -146,5 +149,4 @@ public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, St
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import jodd.http.ProxyInfo;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
|
||||
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
|
||||
import okhttp3.*;
|
||||
|
||||
@@ -40,6 +41,7 @@ public class SimplePostRequestExecutor extends AbstractRequestExecutor<String, S
|
||||
* @throws IOException
|
||||
*/
|
||||
public String executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String postEntity) throws WxErrorException, IOException {
|
||||
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
if (httpProxy != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||
|
||||
Reference in New Issue
Block a user