From 03c158448c137851a9fc200e86fd6f2bd71264dc Mon Sep 17 00:00:00 2001 From: am-wangjin Date: Wed, 22 Nov 2017 10:54:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9okhttp=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E5=9B=BE=E6=96=87=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../okhttp/OkhttpMaterialNewsInfoRequestExecutor.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java index 3f46ab7880..c204f73620 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java @@ -4,6 +4,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; @@ -12,11 +13,15 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; /** * Created by ecoolper on 2017/5/5. */ public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor { + private static final MediaType JSON = MediaType.parse("application/json"); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); public OkhttpMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) { super(requestHttp); @@ -28,9 +33,10 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc //得到httpClient OkHttpClient client = requestHttp.getRequestHttpClient(); - RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build(); + Map params = new HashMap<>(); + params.put("media_id", materialId); + RequestBody requestBody = RequestBody.create(JSON, WxGsonBuilder.create().toJson(params)); Request request = new Request.Builder().url(uri).post(requestBody).build(); - Response response = client.newCall(request).execute(); String responseContent = response.body().string(); this.logger.debug("响应原始数据:{}", responseContent); From 06cbce181558cc7b5bd16c820b9f4749f8ea1276 Mon Sep 17 00:00:00 2001 From: am-wangjin Date: Wed, 22 Nov 2017 10:57:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=AF=B7=E6=B1=82=E6=97=B6,=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E6=9C=89=E6=95=88?= =?UTF-8?q?=E7=9A=84outMessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java index 5acf0040aa..adc3866d04 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java @@ -163,7 +163,10 @@ public void run() { }) ); } else { - res = rule.service(wxMessage, context, this.wxMpService, this.sessionManager, this.exceptionHandler); + WxMpXmlOutMessage temp = rule.service(wxMessage, context, this.wxMpService, this.sessionManager, this.exceptionHandler); + if(temp != null){ + res = temp; + } // 在同步操作结束,session访问结束 this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUser()); sessionEndAccess(wxMessage);