修改两个文件

This commit is contained in:
ecoolper
2017-05-19 23:48:47 +08:00
parent 3757606589
commit 16dea387f2
2 changed files with 26 additions and 17 deletions

View File

@ -1,11 +1,14 @@
package me.chanjar.weixin.mp.util.http; package me.chanjar.weixin.mp.util.http;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp; import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialVideoInfoRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialVideoInfoRequestExecutor; import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialVideoInfoRequestExecutor; import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialVideoInfoRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialVideoInfoRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialVideoInfoRequestExecutor;
public abstract class MaterialVideoInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialVideoInfoResult, String> { public abstract class MaterialVideoInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialVideoInfoResult, String> {
protected RequestHttp<H, P> requestHttp; protected RequestHttp<H, P> requestHttp;
@ -14,12 +17,17 @@ public abstract class MaterialVideoInfoRequestExecutor<H, P> implements RequestE
this.requestHttp = requestHttp; this.requestHttp = requestHttp;
} }
@Override public static RequestExecutor<WxMpMaterialVideoInfoResult, String> create(RequestHttp requestHttp) {
public WxMpMaterialVideoInfoResult executeJodd(HttpConnectionProvider provider, ProxyInfo proxyInfo, String uri, String materialId) throws WxErrorException, IOException { switch (requestHttp.getRequestType()) {
HttpRequest request = HttpRequest.post(uri); case apacheHttp:
if (proxyInfo != null) { return new ApacheMaterialVideoInfoRequestExecutor(requestHttp);
provider.useProxy(proxyInfo); case joddHttp:
return new JoddMaterialVideoInfoRequestExecutor(requestHttp);
case okHttp:
return new OkhttpMaterialVideoInfoRequestExecutor(requestHttp);
default:
return null;
} }
} }
} }

View File

@ -7,6 +7,7 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
import okhttp3.*; import okhttp3.*;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -46,7 +47,7 @@ public class OkhttpQrCodeRequestExecutor extends QrCodeRequestExecutor<Connectio
Request request = new Request.Builder().url(uri).get().build(); Request request = new Request.Builder().url(uri).get().build();
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
String contentTypeHeader = response.header("Content-Type"); String contentTypeHeader = response.header("Content-Type");
if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) { if ("text/plain".equals(contentTypeHeader)) {
String responseContent = response.body().string(); String responseContent = response.body().string();
throw new WxErrorException(WxError.fromJson(responseContent)); throw new WxErrorException(WxError.fromJson(responseContent));
} }