@@ -21,7 +21,6 @@ subprojects { | |||||
dependencies { | dependencies { | ||||
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.10' | compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.10' | ||||
compile group: 'org.apache.httpcomponents', name: 'httpmime', version:'4.5' | compile group: 'org.apache.httpcomponents', name: 'httpmime', version:'4.5' | ||||
compile group: 'org.jodd', name: 'jodd-http', version:'3.6.7' | |||||
compile group: 'com.google.code.gson', name: 'gson', version:'2.7' | compile group: 'com.google.code.gson', name: 'gson', version:'2.7' | ||||
compile group: 'com.google.guava', name: 'guava', version:'19.0' | compile group: 'com.google.guava', name: 'guava', version:'19.0' | ||||
compile group: 'commons-codec', name: 'commons-codec', version:'1.10' | compile group: 'commons-codec', name: 'commons-codec', version:'1.10' | ||||
@@ -76,7 +76,6 @@ | |||||
<httpclient.version>4.5</httpclient.version> | <httpclient.version>4.5</httpclient.version> | ||||
<slf4j.version>1.7.10</slf4j.version> | <slf4j.version>1.7.10</slf4j.version> | ||||
<logback.version>1.1.2</logback.version> | <logback.version>1.1.2</logback.version> | ||||
<jodd-http.version>3.6.7</jodd-http.version> | |||||
<jedis.version>2.9.0</jedis.version> | <jedis.version>2.9.0</jedis.version> | ||||
<gson.version>2.7</gson.version> | <gson.version>2.7</gson.version> | ||||
<guava.version>19.0</guava.version> | <guava.version>19.0</guava.version> | ||||
@@ -104,11 +103,6 @@ | |||||
<artifactId>httpmime</artifactId> | <artifactId>httpmime</artifactId> | ||||
<version>${httpclient.version}</version> | <version>${httpclient.version}</version> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>org.jodd</groupId> | |||||
<artifactId>jodd-http</artifactId> | |||||
<version>${jodd-http.version}</version> | |||||
</dependency> | |||||
<dependency> | <dependency> | ||||
<groupId>com.google.code.gson</groupId> | <groupId>com.google.code.gson</groupId> | ||||
<artifactId>gson</artifactId> | <artifactId>gson</artifactId> | ||||
@@ -1,55 +0,0 @@ | |||||
package me.chanjar.weixin.common.util.http; | |||||
import org.apache.http.HttpHost; | |||||
import org.apache.http.impl.client.CloseableHttpClient; | |||||
import jodd.http.HttpRequest; | |||||
import jodd.http.HttpResponse; | |||||
import jodd.http.ProxyInfo; | |||||
import jodd.http.net.SocketHttpConnectionProvider; | |||||
import me.chanjar.weixin.common.bean.result.WxError; | |||||
import me.chanjar.weixin.common.exception.WxErrorException; | |||||
/** | |||||
* 简单的GET请求执行器,请求的参数是String, 返回的结果也是String | |||||
* | |||||
* @author Daniel Qian | |||||
*/ | |||||
public class JoddGetRequestExecutor implements RequestExecutor<String, String> { | |||||
@Override | |||||
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, | |||||
String queryParam) throws WxErrorException { | |||||
if (queryParam != null) { | |||||
if (uri.indexOf('?') == -1) { | |||||
uri += '?'; | |||||
} | |||||
uri += uri.endsWith("?") ? queryParam : '&' + queryParam; | |||||
} | |||||
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider(); | |||||
if (httpProxy != null) { | |||||
ProxyInfo proxyInfoObj = new ProxyInfo( | |||||
ProxyInfo.ProxyType.HTTP, | |||||
httpProxy.getHostName(), | |||||
httpProxy.getPort(), "", ""); | |||||
provider.useProxy(proxyInfoObj); | |||||
} | |||||
HttpRequest request = HttpRequest.get(uri); | |||||
request.method("GET"); | |||||
request.charset("UTF-8"); | |||||
HttpResponse response = request.open(provider).send(); | |||||
response.charset("UTF-8"); | |||||
String result = response.bodyText(); | |||||
WxError error = WxError.fromJson(result); | |||||
if (error.getErrorCode() != 0) { | |||||
throw new WxErrorException(error); | |||||
} | |||||
return result; | |||||
} | |||||
} |
@@ -1,49 +0,0 @@ | |||||
package me.chanjar.weixin.common.util.http; | |||||
import org.apache.http.HttpHost; | |||||
import org.apache.http.impl.client.CloseableHttpClient; | |||||
import jodd.http.HttpRequest; | |||||
import jodd.http.HttpResponse; | |||||
import jodd.http.ProxyInfo; | |||||
import jodd.http.net.SocketHttpConnectionProvider; | |||||
import me.chanjar.weixin.common.bean.result.WxError; | |||||
import me.chanjar.weixin.common.exception.WxErrorException; | |||||
/** | |||||
* 简单的POST请求执行器,请求的参数是String, 返回的结果也是String | |||||
* | |||||
* @author Edison Guo | |||||
*/ | |||||
public class JoddPostRequestExecutor implements RequestExecutor<String, String> { | |||||
@Override | |||||
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, | |||||
String postEntity) throws WxErrorException { | |||||
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider(); | |||||
if (httpProxy != null) { | |||||
ProxyInfo proxyInfoObj = new ProxyInfo( | |||||
ProxyInfo.ProxyType.HTTP, | |||||
httpProxy.getAddress().getHostAddress(), | |||||
httpProxy.getPort(), "", ""); | |||||
provider.useProxy(proxyInfoObj); | |||||
} | |||||
HttpRequest request = HttpRequest.get(uri); | |||||
request.method("POST"); | |||||
request.charset("UTF-8"); | |||||
request.bodyText(postEntity); | |||||
HttpResponse response = request.open(provider).send(); | |||||
response.charset("UTF-8"); | |||||
String result = response.bodyText(); | |||||
WxError error = WxError.fromJson(result); | |||||
if (error.getErrorCode() != 0) { | |||||
throw new WxErrorException(error); | |||||
} | |||||
return result; | |||||
} | |||||
} |
@@ -30,7 +30,7 @@ public class DemoImageHandler implements WxMpMessageHandler { | |||||
} catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
} | } |