Skip to content

Commit 44cbf65

Browse files
authored
Merge branch 'develop' into develop
2 parents ffa3544 + 2029cd0 commit 44cbf65

File tree

28 files changed

+111
-24
lines changed

28 files changed

+111
-24
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.github.binarywang</groupId>
77
<artifactId>weixin-java-parent</artifactId>
8-
<version>2.6.0</version>
8+
<version>2.7.0-SNAPSHOT</version>
99
<packaging>pom</packaging>
1010
<name>WeiXin Java Tools - Parent</name>
1111
<description>微信公众号、企业号上级POM</description>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
---------------------------------
5353
## Maven & Gradle 最新正式版本
5454

55-
* 微信支付(暂时为测试版本)
55+
* 微信支付:
5656

5757
maven:
5858
```xml

weixin-java-common/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.github.binarywang</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>2.6.0</version>
9+
<version>2.7.0-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-common</artifactId>
@@ -39,6 +39,11 @@
3939
<artifactId>jetty-servlet</artifactId>
4040
<scope>test</scope>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.jodd</groupId>
44+
<artifactId>jodd-http</artifactId>
45+
<version>3.7</version>
46+
</dependency>
4247
</dependencies>
4348

4449
<build>

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import me.chanjar.weixin.common.util.fs.FileUtils;
1111
import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler;
1212
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
13+
1314
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
1415
import okhttp3.*;
1516

@@ -111,7 +112,7 @@ public File executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, St
111112
}
112113
}
113114

114-
String fileName = getFileName(response);
115+
String fileName = getFileNameApache(response);
115116
if (StringUtils.isBlank(fileName)) {
116117
return null;
117118
}
@@ -128,7 +129,6 @@ public File executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, St
128129

129130
/**
130131
* jodd-http实现方式
131-
*
132132
* @param provider
133133
* @param proxyInfo
134134
* @param uri
@@ -237,7 +237,23 @@ private String getFileName(Response response) throws WxErrorException {
237237
if (m.matches()) {
238238
return m.group(1);
239239
}
240-
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build());
240+
request.withConnectionProvider(provider);
241+
HttpResponse response = request.send();
242+
String contentType = response.header("Content-Type");
243+
if (contentType != null && contentType.startsWith("application/json")) {
244+
// application/json; encoding=utf-8 下载媒体文件出错
245+
throw new WxErrorException(WxError.fromJson(response.bodyText()));
246+
}
247+
248+
String fileName = getFileNameJodd(response);
249+
if (StringUtils.isBlank(fileName)) {
250+
return null;
251+
}
252+
253+
InputStream inputStream = new ByteArrayInputStream(response.bodyBytes());
254+
String[] nameAndExt = fileName.split("\\.");
255+
return FileUtils.createTmpFile(inputStream, nameAndExt[0], nameAndExt[1], this.tmpDirFile);
241256
}
242257

258+
243259
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
99
import me.chanjar.weixin.common.exception.WxErrorException;
1010
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
11+
1112
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
1213
import okhttp3.*;
1314

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import jodd.http.HttpConnectionProvider;
44
import jodd.http.ProxyInfo;
55
import me.chanjar.weixin.common.exception.WxErrorException;
6+
67
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
78
import okhttp3.ConnectionPool;
89

@@ -63,5 +64,4 @@ public interface RequestExecutor<T, E> {
6364
*/
6465
T executeOkhttp(ConnectionPool pool, final OkhttpProxyInfo proxyInfo, String uri, E data) throws WxErrorException, IOException;
6566

66-
6767
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import me.chanjar.weixin.common.bean.result.WxError;
88
import me.chanjar.weixin.common.exception.WxErrorException;
99
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
10+
1011
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
1112
import okhttp3.*;
1213

@@ -28,6 +29,7 @@
2829
*/
2930
public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, String> {
3031

32+
3133
/**
3234
* apache-http实现方式
3335
*
@@ -98,6 +100,7 @@ public String executeJodd(HttpConnectionProvider provider, ProxyInfo proxyInfo,
98100
return responseContent;
99101
}
100102

103+
101104
/**
102105
* okHttp实现方式
103106
*
@@ -146,5 +149,4 @@ public Request authenticate(Route route, Response response) throws IOException {
146149
return responseContent;
147150
}
148151

149-
150152
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import me.chanjar.weixin.common.bean.result.WxError;
88
import me.chanjar.weixin.common.exception.WxErrorException;
99
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
10+
1011
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
1112
import okhttp3.*;
1213

@@ -40,6 +41,7 @@ public class SimplePostRequestExecutor extends AbstractRequestExecutor<String, S
4041
* @throws IOException
4142
*/
4243
public String executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String postEntity) throws WxErrorException, IOException {
44+
4345
HttpPost httpPost = new HttpPost(uri);
4446
if (httpProxy != null) {
4547
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();

weixin-java-cp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.github.binarywang</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>2.6.0</version>
9+
<version>2.7.0-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-cp</artifactId>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/apache/WxCpServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package me.chanjar.weixin.cp.api.impl.apache;
22

3-
43
import me.chanjar.weixin.common.bean.WxAccessToken;
54
import me.chanjar.weixin.common.bean.result.WxError;
65
import me.chanjar.weixin.common.exception.WxErrorException;
76
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
87
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
98
import me.chanjar.weixin.cp.api.impl.AbstractWxCpService;
109

10+
1111
import org.apache.http.HttpHost;
1212
import org.apache.http.client.config.RequestConfig;
1313
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -73,6 +73,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
7373
}
7474

7575
@Override
76+
7677
public void initHttp() {
7778
ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
7879
.getApacheHttpClientBuilder();
@@ -91,4 +92,5 @@ public void initHttp() {
9192

9293
this.httpClient = apacheHttpClientBuilder.build();
9394
}
95+
9496
}

0 commit comments

Comments
 (0)