瀏覽代碼

#356 修复QrCodeRequestExecutor类MimeType比较的bug

master
Binary Wang 7 年之前
父節點
當前提交
0f007d970b
共有 3 個檔案被更改,包括 8 行新增5 行删除
  1. +2
    -1
      weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java
  2. +4
    -3
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java
  3. +2
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheQrCodeRequestExecutor.java

+ 2
- 1
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java 查看文件

@@ -48,7 +48,8 @@ public class QrCodeRequestExecutor implements RequestExecutor<File, AbstractWxMa
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0
&& ContentType.APPLICATION_JSON.getMimeType().equals(contentTypeHeader[0].getValue())) {
&& ContentType.APPLICATION_JSON.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent));
}


+ 4
- 3
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java 查看文件

@@ -1,5 +1,7 @@
package me.chanjar.weixin.mp.util.http;

import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
@@ -21,7 +23,7 @@ public abstract class QrCodeRequestExecutor<H, P> implements RequestExecutor<Fil
this.requestHttp = requestHttp;
}

public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp requestHttp) {
public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp requestHttp) throws WxErrorException {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheQrCodeRequestExecutor(requestHttp);
@@ -30,8 +32,7 @@ public abstract class QrCodeRequestExecutor<H, P> implements RequestExecutor<Fil
case OK_HTTP:
return new OkhttpQrCodeRequestExecutor(requestHttp);
default:
//TODO 需要优化,最好抛出异常
return null;
throw new WxErrorException(WxError.newBuilder().setErrorMsg("不支持的http框架").build());
}
}



+ 2
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheQrCodeRequestExecutor.java 查看文件

@@ -52,7 +52,8 @@ public class ApacheQrCodeRequestExecutor extends QrCodeRequestExecutor<Closeable
Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
// 出错
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
if (ContentType.TEXT_PLAIN.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent));
}


Loading…
取消
儲存