#395 修复获取小程序二维码data format error的问题

This commit is contained in:
Binary Wang 2017-12-07 11:54:17 +08:00
parent 7b64b6b4a0
commit 0714cbe8e2
2 changed files with 9 additions and 7 deletions

View File

@ -8,10 +8,12 @@ import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
* @author Element * @author Element
*/ */
public abstract class AbstractWxMaQrcodeWrapper { public abstract class AbstractWxMaQrcodeWrapper {
public String toJson() {
@Override
public String toString() {
return WxMaGsonBuilder.create().toJson(this); return WxMaGsonBuilder.create().toJson(this);
} }
@Override
public String toString() {
return this.toJson();
}
} }

View File

@ -37,17 +37,17 @@ public class QrCodeRequestExecutor implements RequestExecutor<File, AbstractWxMa
HttpPost httpPost = new HttpPost(uri); HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) { if (requestHttp.getRequestHttpProxy() != null) {
httpPost.setConfig( httpPost.setConfig(
RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build() RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build()
); );
} }
httpPost.setEntity(new StringEntity(ticket.toString())); httpPost.setEntity(new StringEntity(ticket.toJson()));
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost); try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) { InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
Header[] contentTypeHeader = response.getHeaders("Content-Type"); Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0 if (contentTypeHeader != null && contentTypeHeader.length > 0
&& ContentType.APPLICATION_JSON.getMimeType() && ContentType.APPLICATION_JSON.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) { .equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent)); throw new WxErrorException(WxError.fromJson(responseContent));
} }