Ver código fonte

#307 微信支付模块中增加http proxy设置的支持

master
Binary Wang 7 anos atrás
committed by Binary Wang
pai
commit
ad58730478
2 arquivos alterados com 18 adições e 2 exclusões
  1. +1
    -1
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java
  2. +17
    -1
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java

+ 1
- 1
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java Ver arquivo

@@ -54,7 +54,7 @@ public class WxPayServiceApacheHttpImpl extends WxPayServiceAbstractImpl {
.build());

if (StringUtils.isNotBlank(this.config.getHttpProxyHost())
&& StringUtils.isNotBlank(this.config.getHttpProxyUsername())) {
&& this.config.getHttpProxyPort() > 0) {
// 使用代理服务器 需要用户认证的代理服务器
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(


+ 17
- 1
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java Ver arquivo

@@ -1,9 +1,13 @@
package com.github.binarywang.wxpay.service.impl;

import com.github.binarywang.wxpay.exception.WxPayException;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.http.ProxyInfo.ProxyType;
import jodd.http.net.SSLSocketHttpConnectionProvider;
import jodd.http.net.SocketHttpConnectionProvider;
import org.apache.commons.lang3.StringUtils;

import javax.net.ssl.SSLContext;
@@ -31,7 +35,19 @@ public class WxPayServiceJoddHttpImpl extends WxPayServiceAbstractImpl {
if (null == sslContext) {
sslContext = this.getConfig().initSSLContext();
}
request.withConnectionProvider(new SSLSocketHttpConnectionProvider(sslContext));
final SSLSocketHttpConnectionProvider provider = new SSLSocketHttpConnectionProvider(sslContext);
request.withConnectionProvider(provider);
}

if (StringUtils.isNotBlank(this.config.getHttpProxyHost()) && this.config.getHttpProxyPort() > 0) {
ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.config.getHttpProxyHost(), this.config.getHttpProxyPort(),
this.config.getHttpProxyUsername(), this.config.getHttpProxyPassword());
HttpConnectionProvider provider = request.connectionProvider();
if (null == provider) {
provider = new SocketHttpConnectionProvider();
}
provider.useProxy(httpProxy);
request.withConnectionProvider(provider);
}

String responseString = this.getResponseString(request.send());


Carregando…
Cancelar
Salvar