Browse Source

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

master
Binary Wang 7 years ago
parent
commit
0714cbe8e2
2 changed files with 8 additions and 6 deletions
  1. +4
    -2
      weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/AbstractWxMaQrcodeWrapper.java
  2. +4
    -4
      weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java

+ 4
- 2
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/AbstractWxMaQrcodeWrapper.java 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() {
return WxMaGsonBuilder.create().toJson(this);
}


@Override @Override
public String toString() { public String toString() {
return WxMaGsonBuilder.create().toJson(this);
return this.toJson();
} }

} }

+ 4
- 4
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java 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()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
&& ContentType.APPLICATION_JSON.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));
} }


Loading…
Cancel
Save