Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fa4cc5a

Browse files
binarywang#380 修复okhttp和jodd-http实现的获取永久素材接口的问题
1 parent 6180577 commit fa4cc5a

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialNewsInfoRequestExecutor.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.chanjar.weixin.mp.util.http.apache;
22

3+
import com.google.common.collect.ImmutableMap;
34
import me.chanjar.weixin.common.bean.result.WxError;
45
import me.chanjar.weixin.common.exception.WxErrorException;
56
import me.chanjar.weixin.common.util.http.RequestHttp;
@@ -43,9 +44,7 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc
4344
httpPost.setConfig(config);
4445
}
4546

46-
Map<String, String> params = new HashMap<>();
47-
params.put("media_id", materialId);
48-
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
47+
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId))));
4948
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
5049
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
5150
this.logger.debug("响应原始数据:{}", responseContent);

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialNewsInfoRequestExecutor.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.chanjar.weixin.mp.util.http.jodd;
22

3+
import com.google.common.collect.ImmutableMap;
34
import jodd.http.HttpConnectionProvider;
45
import jodd.http.HttpRequest;
56
import jodd.http.HttpResponse;
@@ -9,6 +10,7 @@
910
import me.chanjar.weixin.common.bean.result.WxError;
1011
import me.chanjar.weixin.common.exception.WxErrorException;
1112
import me.chanjar.weixin.common.util.http.RequestHttp;
13+
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
1214
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
1315
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
1416
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -28,13 +30,13 @@ public JoddMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
2830

2931
@Override
3032
public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorException, IOException {
31-
HttpRequest request = HttpRequest.post(uri);
3233
if (requestHttp.getRequestHttpProxy() != null) {
3334
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
3435
}
35-
request.withConnectionProvider(requestHttp.getRequestHttpClient());
3636

37-
request.query("media_id", materialId);
37+
HttpRequest request = HttpRequest.post(uri)
38+
.withConnectionProvider(requestHttp.getRequestHttpClient())
39+
.body(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)));
3840
HttpResponse response = request.send();
3941
response.charset(StringPool.UTF_8);
4042

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package me.chanjar.weixin.mp.util.http.okhttp;
22

3+
import com.google.common.collect.ImmutableMap;
34
import me.chanjar.weixin.common.bean.result.WxError;
45
import me.chanjar.weixin.common.exception.WxErrorException;
56
import me.chanjar.weixin.common.util.http.RequestHttp;
67
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
8+
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
79
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
810
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
911
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -28,7 +30,8 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc
2830
//得到httpClient
2931
OkHttpClient client = requestHttp.getRequestHttpClient();
3032

31-
RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build();
33+
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),
34+
WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)));
3235
Request request = new Request.Builder().url(uri).post(requestBody).build();
3336

3437
Response response = client.newCall(request).execute();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /