Skip to content

Commit 0f007d9

Browse files
committed
binarywang#356 修复QrCodeRequestExecutor类MimeType比较的bug
1 parent 64f0e7c commit 0f007d9

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public File execute(String uri, AbstractWxMaQrcodeWrapper ticket) throws WxError
4848
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
4949
Header[] contentTypeHeader = response.getHeaders("Content-Type");
5050
if (contentTypeHeader != null && contentTypeHeader.length > 0
51-
&& ContentType.APPLICATION_JSON.getMimeType().equals(contentTypeHeader[0].getValue())) {
51+
&& ContentType.APPLICATION_JSON.getMimeType()
52+
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
5253
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
5354
throw new WxErrorException(WxError.fromJson(responseContent));
5455
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java

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

3+
import me.chanjar.weixin.common.bean.result.WxError;
4+
import me.chanjar.weixin.common.exception.WxErrorException;
35
import me.chanjar.weixin.common.util.http.RequestExecutor;
46
import me.chanjar.weixin.common.util.http.RequestHttp;
57
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
@@ -21,7 +23,7 @@ public QrCodeRequestExecutor(RequestHttp requestHttp) {
2123
this.requestHttp = requestHttp;
2224
}
2325

24-
public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp requestHttp) {
26+
public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp requestHttp) throws WxErrorException {
2527
switch (requestHttp.getRequestType()) {
2628
case APACHE_HTTP:
2729
return new ApacheQrCodeRequestExecutor(requestHttp);
@@ -30,8 +32,7 @@ public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp request
3032
case OK_HTTP:
3133
return new OkhttpQrCodeRequestExecutor(requestHttp);
3234
default:
33-
//TODO 需要优化,最好抛出异常
34-
return null;
35+
throw new WxErrorException(WxError.newBuilder().setErrorMsg("不支持的http框架").build());
3536
}
3637
}
3738

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException
5252
Header[] contentTypeHeader = response.getHeaders("Content-Type");
5353
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
5454
// 出错
55-
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
55+
if (ContentType.TEXT_PLAIN.getMimeType()
56+
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
5657
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
5758
throw new WxErrorException(WxError.fromJson(responseContent));
5859
}

0 commit comments

Comments
 (0)