Browse Source

修改了冲突和错误

master
ecoolper 7 years ago
parent
commit
d01d372b65
7 changed files with 7 additions and 33 deletions
  1. +3
    -19
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java
  2. +1
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/apache/WxCpServiceImpl.java
  3. +0
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/jodd/WxCpServiceImpl.java
  4. +0
    -4
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/apache/WxMpServiceImpl.java
  5. +1
    -1
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java
  6. +1
    -1
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java
  7. +1
    -2
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java

+ 3
- 19
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java 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.fs.FileUtils;
import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler; 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.apache.Utf8ResponseHandler;

import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
import okhttp3.*; import okhttp3.*;


@@ -112,7 +111,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
} }
} }


String fileName = getFileNameApache(response);
String fileName = getFileName(response);
if (StringUtils.isBlank(fileName)) { if (StringUtils.isBlank(fileName)) {
return null; return null;
} }
@@ -129,6 +128,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,


/** /**
* jodd-http实现方式 * jodd-http实现方式
*
* @param provider * @param provider
* @param proxyInfo * @param proxyInfo
* @param uri * @param uri
@@ -237,23 +237,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
if (m.matches()) { if (m.matches()) {
return m.group(1); 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());
} }



} }

+ 1
- 3
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/apache/WxCpServiceImpl.java View File

@@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.api.impl.apache; package me.chanjar.weixin.cp.api.impl.apache;



import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException; 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.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.cp.api.impl.AbstractWxCpService; import me.chanjar.weixin.cp.api.impl.AbstractWxCpService;



import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@@ -73,7 +73,6 @@ public class WxCpServiceImpl extends AbstractWxCpService<CloseableHttpClient, Ht
} }


@Override @Override

public void initHttp() { public void initHttp() {
ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
.getApacheHttpClientBuilder(); .getApacheHttpClientBuilder();
@@ -92,5 +91,4 @@ public class WxCpServiceImpl extends AbstractWxCpService<CloseableHttpClient, Ht


this.httpClient = apacheHttpClientBuilder.build(); this.httpClient = apacheHttpClientBuilder.build();
} }

} }

+ 0
- 3
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/jodd/WxCpServiceImpl.java View File

@@ -19,7 +19,6 @@ public class WxCpServiceImpl extends AbstractWxCpService<HttpConnectionProvider,
@Override @Override
public ProxyInfo getRequestHttpProxy() { public ProxyInfo getRequestHttpProxy() {
return httpProxy; return httpProxy;

} }


@Override @Override
@@ -57,12 +56,10 @@ public class WxCpServiceImpl extends AbstractWxCpService<HttpConnectionProvider,


@Override @Override
public void initHttp() { public void initHttp() {

if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword()); httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword());
} }


httpClient = JoddHttp.httpConnectionProvider; httpClient = JoddHttp.httpConnectionProvider;
} }

} }

+ 0
- 4
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/apache/WxMpServiceImpl.java View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.mp.api.impl.apache; package me.chanjar.weixin.mp.api.impl.apache;



import java.io.IOException; import java.io.IOException;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;


@@ -72,13 +71,11 @@ public class WxMpServiceImpl extends AbstractWxMpService<CloseableHttpClient,Htt
+ this.getWxMpConfigStorage().getSecret(); + this.getWxMpConfigStorage().getSecret();
try { try {
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);

if (this.getRequestHttpProxy() != null) { if (this.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build(); RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpGet.setConfig(config); httpGet.setConfig(config);
} }
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) { try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) {

String resultContent = new BasicResponseHandler().handleResponse(response); String resultContent = new BasicResponseHandler().handleResponse(response);
WxError error = WxError.fromJson(resultContent); WxError error = WxError.fromJson(resultContent);
if (error.getErrorCode() != 0) { if (error.getErrorCode() != 0) {
@@ -99,5 +96,4 @@ public class WxMpServiceImpl extends AbstractWxMpService<CloseableHttpClient,Htt
} }
return this.getWxMpConfigStorage().getAccessToken(); return this.getWxMpConfigStorage().getAccessToken();
} }

} }

+ 1
- 1
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java View File

@@ -19,7 +19,7 @@ public class WxMpBusyRetryTest {


@DataProvider(name = "getService") @DataProvider(name = "getService")
public Object[][] getService() { public Object[][] getService() {
WxMpService service = new WxMpServiceImpl0() {
WxMpService service = new WxMpServiceImpl() {


@Override @Override
public synchronized <T, E> T executeInternal( public synchronized <T, E> T executeInternal(


+ 1
- 1
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java View File

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


binder.bind(WxMpService.class).toInstance(wxService); binder.bind(WxMpService.class).toInstance(wxService);


+ 1
- 2
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java 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.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpMessageRouter; import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;

import me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl; import me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl;


import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
@@ -49,7 +48,7 @@ public class WxMpDemoServer {
.fromXml(is1); .fromXml(is1);


wxMpConfigStorage = config; wxMpConfigStorage = config;
wxMpService = new WxMpServiceImpl0();
wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(config); wxMpService.setWxMpConfigStorage(config);


WxMpMessageHandler logHandler = new DemoLogHandler(); WxMpMessageHandler logHandler = new DemoLogHandler();


Loading…
Cancel
Save