修改了冲突和错误

This commit is contained in:
ecoolper 2017-04-27 20:14:52 +08:00
parent 44cbf65f81
commit d01d372b65
7 changed files with 7 additions and 33 deletions

View File

@ -10,7 +10,6 @@ import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
import okhttp3.*;
@ -112,7 +111,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
}
}
String fileName = getFileNameApache(response);
String fileName = getFileName(response);
if (StringUtils.isBlank(fileName)) {
return null;
}
@ -129,6 +128,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
/**
* jodd-http实现方式
*
* @param provider
* @param proxyInfo
* @param uri
@ -237,23 +237,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
if (m.matches()) {
return m.group(1);
}
request.withConnectionProvider(provider);
HttpResponse response = request.send();
String contentType = response.header("Content-Type");
if (contentType != null && contentType.startsWith("application/json")) {
// application/json; encoding=utf-8 下载媒体文件出错
throw new WxErrorException(WxError.fromJson(response.bodyText()));
}
String fileName = getFileNameJodd(response);
if (StringUtils.isBlank(fileName)) {
return null;
}
InputStream inputStream = new ByteArrayInputStream(response.bodyBytes());
String[] nameAndExt = fileName.split("\\.");
return FileUtils.createTmpFile(inputStream, nameAndExt[0], nameAndExt[1], this.tmpDirFile);
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build());
}
}

View File

@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.api.impl.apache;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
@ -7,7 +8,6 @@ import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.cp.api.impl.AbstractWxCpService;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@ -73,7 +73,6 @@ public class WxCpServiceImpl extends AbstractWxCpService<CloseableHttpClient, Ht
}
@Override
public void initHttp() {
ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
.getApacheHttpClientBuilder();
@ -92,5 +91,4 @@ public class WxCpServiceImpl extends AbstractWxCpService<CloseableHttpClient, Ht
this.httpClient = apacheHttpClientBuilder.build();
}
}

View File

@ -19,7 +19,6 @@ public class WxCpServiceImpl extends AbstractWxCpService<HttpConnectionProvider,
@Override
public ProxyInfo getRequestHttpProxy() {
return httpProxy;
}
@Override
@ -57,12 +56,10 @@ public class WxCpServiceImpl extends AbstractWxCpService<HttpConnectionProvider,
@Override
public void initHttp() {
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword());
}
httpClient = JoddHttp.httpConnectionProvider;
}
}

View File

@ -1,6 +1,5 @@
package me.chanjar.weixin.mp.api.impl.apache;
import java.io.IOException;
import java.util.concurrent.locks.Lock;
@ -72,13 +71,11 @@ public class WxMpServiceImpl extends AbstractWxMpService<CloseableHttpClient,Htt
+ this.getWxMpConfigStorage().getSecret();
try {
HttpGet httpGet = new HttpGet(url);
if (this.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpGet.setConfig(config);
}
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) {
String resultContent = new BasicResponseHandler().handleResponse(response);
WxError error = WxError.fromJson(resultContent);
if (error.getErrorCode() != 0) {
@ -99,5 +96,4 @@ public class WxMpServiceImpl extends AbstractWxMpService<CloseableHttpClient,Htt
}
return this.getWxMpConfigStorage().getAccessToken();
}
}

View File

@ -19,7 +19,7 @@ public class WxMpBusyRetryTest {
@DataProvider(name = "getService")
public Object[][] getService() {
WxMpService service = new WxMpServiceImpl0() {
WxMpService service = new WxMpServiceImpl() {
@Override
public synchronized <T, E> T executeInternal(

View File

@ -20,7 +20,7 @@ public class ApiTestModule implements Module {
try (InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml")) {
TestConfigStorage config = this.fromXml(TestConfigStorage.class, is1);
config.setAccessTokenLock(new ReentrantLock());
WxMpService wxService = new WxMpServiceImpl0();
WxMpService wxService = new WxMpServiceImpl();
wxService.setWxMpConfigStorage(config);
binder.bind(WxMpService.class).toInstance(wxService);

View File

@ -5,7 +5,6 @@ import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl;
import org.eclipse.jetty.server.Server;
@ -49,7 +48,7 @@ public class WxMpDemoServer {
.fromXml(is1);
wxMpConfigStorage = config;
wxMpService = new WxMpServiceImpl0();
wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(config);
WxMpMessageHandler logHandler = new DemoLogHandler();