优化微信配置类
This commit is contained in:
parent
ce843c4f24
commit
f956c66481
@ -6,8 +6,8 @@ import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
/**
|
||||
* Http 参数
|
||||
*
|
||||
* Http请求参数
|
||||
*
|
||||
* @className HttpParams
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年8月13日
|
||||
@ -16,104 +16,204 @@ import javax.net.ssl.SSLContext;
|
||||
*/
|
||||
public final class HttpParams {
|
||||
|
||||
private boolean allowUserInteraction = true;
|
||||
private int connectTimeout = 5000;
|
||||
private int socketTimeout = 5000;
|
||||
private int readTimeout = 5000;
|
||||
private int chunkSize = 4096;
|
||||
private long ifModifiedSince = 0l;
|
||||
private boolean followRedirects = false;
|
||||
|
||||
private final boolean allowUserInteraction;
|
||||
private final int connectTimeout;
|
||||
private final int socketTimeout;
|
||||
private final int readTimeout;
|
||||
private final int chunkSize;
|
||||
private final boolean followRedirects;
|
||||
/**
|
||||
* 代理对象
|
||||
*/
|
||||
private Proxy proxy;
|
||||
private final Proxy proxy;
|
||||
/**
|
||||
* SSL对象
|
||||
*/
|
||||
private SSLContext sslContext;
|
||||
private final SSLContext sslContext;
|
||||
/**
|
||||
* hostname对象
|
||||
*/
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
private final HostnameVerifier hostnameVerifier;
|
||||
|
||||
HttpParams(boolean allowUserInteraction, int connectTimeout,
|
||||
int socketTimeout, int readTimeout, int chunkSize,
|
||||
boolean followRedirects, Proxy proxy, SSLContext sslContext,
|
||||
HostnameVerifier hostnameVerifier) {
|
||||
this.allowUserInteraction = allowUserInteraction;
|
||||
this.connectTimeout = connectTimeout;
|
||||
this.socketTimeout = socketTimeout;
|
||||
this.readTimeout = readTimeout;
|
||||
this.chunkSize = chunkSize;
|
||||
this.followRedirects = followRedirects;
|
||||
this.proxy = proxy;
|
||||
this.sslContext = sslContext;
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
}
|
||||
|
||||
public boolean isAllowUserInteraction() {
|
||||
return allowUserInteraction;
|
||||
}
|
||||
|
||||
public void setAllowUserInteraction(boolean allowUserInteraction) {
|
||||
this.allowUserInteraction = allowUserInteraction;
|
||||
}
|
||||
|
||||
public int getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
|
||||
public void setConnectTimeout(int connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
public int getSocketTimeout() {
|
||||
return socketTimeout;
|
||||
}
|
||||
|
||||
public void setSocketTimeout(int socketTimeout) {
|
||||
this.socketTimeout = socketTimeout;
|
||||
}
|
||||
|
||||
public int getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeout(int readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public int getChunkSize() {
|
||||
return chunkSize;
|
||||
}
|
||||
|
||||
public void setChunkSize(int chunkSize) {
|
||||
this.chunkSize = chunkSize;
|
||||
}
|
||||
|
||||
public long getIfModifiedSince() {
|
||||
return ifModifiedSince;
|
||||
}
|
||||
|
||||
public void setIfModifiedSince(long ifModifiedSince) {
|
||||
this.ifModifiedSince = ifModifiedSince;
|
||||
}
|
||||
|
||||
public boolean isFollowRedirects() {
|
||||
return followRedirects;
|
||||
}
|
||||
|
||||
public void setFollowRedirects(boolean followRedirects) {
|
||||
this.followRedirects = followRedirects;
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public void setProxy(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
public SSLContext getSSLContext() {
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
public void setSSLContext(SSLContext sslContext) {
|
||||
this.sslContext = sslContext;
|
||||
}
|
||||
|
||||
public HostnameVerifier getHostnameVerifier() {
|
||||
return hostnameVerifier;
|
||||
}
|
||||
|
||||
public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
public static HttpParams.Builder custom() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static HttpParams.Builder copy(final HttpParams params) {
|
||||
return new Builder()
|
||||
.setAllowUserInteraction(params.isAllowUserInteraction())
|
||||
.setConnectTimeout(params.getConnectTimeout())
|
||||
.setSocketTimeout(params.getSocketTimeout())
|
||||
.setReadTimeout(params.getReadTimeout())
|
||||
.setChunkSize(params.getChunkSize())
|
||||
.setFollowRedirects(params.isFollowRedirects());
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private boolean allowUserInteraction;
|
||||
private int connectTimeout;
|
||||
private int socketTimeout;
|
||||
private int readTimeout;
|
||||
private int chunkSize;
|
||||
private boolean followRedirects;
|
||||
/**
|
||||
* 代理对象
|
||||
*/
|
||||
private Proxy proxy;
|
||||
/**
|
||||
* SSL对象
|
||||
*/
|
||||
private SSLContext sslContext;
|
||||
/**
|
||||
* hostname对象
|
||||
*/
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
|
||||
Builder() {
|
||||
this.allowUserInteraction = true;
|
||||
this.connectTimeout = 5000;
|
||||
this.socketTimeout = 5000;
|
||||
this.readTimeout = 5000;
|
||||
this.chunkSize = 4096;
|
||||
this.followRedirects = false;
|
||||
}
|
||||
|
||||
public boolean isAllowUserInteraction() {
|
||||
return allowUserInteraction;
|
||||
}
|
||||
|
||||
public Builder setAllowUserInteraction(boolean allowUserInteraction) {
|
||||
this.allowUserInteraction = allowUserInteraction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
|
||||
public Builder setConnectTimeout(int connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getSocketTimeout() {
|
||||
return socketTimeout;
|
||||
}
|
||||
|
||||
public Builder setSocketTimeout(int socketTimeout) {
|
||||
this.socketTimeout = socketTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public Builder setReadTimeout(int readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getChunkSize() {
|
||||
return chunkSize;
|
||||
}
|
||||
|
||||
public Builder setChunkSize(int chunkSize) {
|
||||
this.chunkSize = chunkSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isFollowRedirects() {
|
||||
return followRedirects;
|
||||
}
|
||||
|
||||
public Builder setFollowRedirects(boolean followRedirects) {
|
||||
this.followRedirects = followRedirects;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public Builder setProxy(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SSLContext getSslContext() {
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
public Builder setSslContext(SSLContext sslContext) {
|
||||
this.sslContext = sslContext;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HostnameVerifier getHostnameVerifier() {
|
||||
return hostnameVerifier;
|
||||
}
|
||||
|
||||
public Builder setHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpParams build() {
|
||||
return new HttpParams(allowUserInteraction, connectTimeout,
|
||||
socketTimeout, readTimeout, chunkSize, followRedirects,
|
||||
proxy, sslContext, hostnameVerifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* HTTP 简单实现
|
||||
*
|
||||
*
|
||||
* @className SimpleHttpClient
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年5月29日
|
||||
@ -87,7 +87,6 @@ public class SimpleHttpClient extends AbstractHttpClient implements HttpClient {
|
||||
.isAllowUserInteraction());
|
||||
connection.setConnectTimeout(params.getConnectTimeout());
|
||||
connection.setReadTimeout(params.getReadTimeout());
|
||||
connection.setIfModifiedSince(params.getIfModifiedSince());
|
||||
connection.setInstanceFollowRedirects(params
|
||||
.isFollowRedirects());
|
||||
}
|
||||
|
||||
@ -38,16 +38,16 @@ public class WeixinRequestExecutor {
|
||||
protected final InternalLogger logger = InternalLoggerFactory
|
||||
.getInstance(getClass());
|
||||
|
||||
protected final HttpClient httpClient;
|
||||
protected final HttpParams params;
|
||||
private final HttpClient httpClient;
|
||||
private final HttpParams httpParams;
|
||||
|
||||
public WeixinRequestExecutor() {
|
||||
this(new HttpParams());
|
||||
this(HttpParams.custom().build());
|
||||
}
|
||||
|
||||
public WeixinRequestExecutor(HttpParams params) {
|
||||
public WeixinRequestExecutor(HttpParams httpParams) {
|
||||
this.httpClient = HttpClientFactory.getInstance();
|
||||
this.params = params;
|
||||
this.httpParams = httpParams;
|
||||
}
|
||||
|
||||
public WeixinResponse get(String url) throws WeixinException {
|
||||
@ -95,7 +95,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
protected WeixinResponse doRequest(HttpRequest request)
|
||||
throws WeixinException {
|
||||
request.setParams(params);
|
||||
request.setParams(httpParams);
|
||||
try {
|
||||
logger.info("weixin request >> " + request.getMethod() + " "
|
||||
+ request.getURI().toString());
|
||||
@ -180,6 +180,6 @@ public class WeixinRequestExecutor {
|
||||
}
|
||||
|
||||
public HttpParams getExecuteParams() {
|
||||
return params;
|
||||
return httpParams;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,11 +7,13 @@ import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
|
||||
/**
|
||||
* 微信ssl请求
|
||||
*
|
||||
*
|
||||
* @className WeixinSSLRequestExecutor
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年8月17日
|
||||
@ -36,15 +38,27 @@ public class WeixinSSLRequestExecutor extends WeixinRequestExecutor {
|
||||
} catch (Exception e) {
|
||||
throw new WeixinException("Key load error", e);
|
||||
}
|
||||
params.setSSLContext(sslContext);
|
||||
}
|
||||
|
||||
public WeixinSSLRequestExecutor(SSLContext sslContext) {
|
||||
this.sslContext = sslContext;
|
||||
params.setSSLContext(sslContext);
|
||||
}
|
||||
|
||||
public SSLContext getSSLContext() {
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WeixinResponse doRequest(HttpRequest request)
|
||||
throws WeixinException {
|
||||
HttpParams params = null;
|
||||
if (request.getParams() != null) {
|
||||
params = HttpParams.copy(request.getParams())
|
||||
.setSslContext(sslContext).build();
|
||||
} else {
|
||||
params = HttpParams.custom().setSslContext(sslContext).build();
|
||||
}
|
||||
request.setParams(params);
|
||||
return super.doRequest(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.api.CashApi;
|
||||
import com.foxinmy.weixin4j.api.CouponApi;
|
||||
import com.foxinmy.weixin4j.api.CustomsApi;
|
||||
@ -42,6 +43,7 @@ import com.foxinmy.weixin4j.type.BillType;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.CustomsCity;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* 微信支付接口实现
|
||||
@ -73,13 +75,16 @@ public class WeixinPayProxy {
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
private final Weixin4jSettings settings;
|
||||
private final Weixin4jSettings<WeixinPayAccount> settings;
|
||||
|
||||
/**
|
||||
* 使用weixin4j.properties配置的支付账号信息
|
||||
*/
|
||||
public WeixinPayProxy() {
|
||||
this(new Weixin4jSettings());
|
||||
this(
|
||||
new Weixin4jSettings<WeixinPayAccount>(JSON.parseObject(
|
||||
Weixin4jConfigUtil.getValue("account"),
|
||||
WeixinPayAccount.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,21 +93,21 @@ public class WeixinPayProxy {
|
||||
* 支付相关配置信息
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinPayProxy(Weixin4jSettings settings) {
|
||||
public WeixinPayProxy(Weixin4jSettings<WeixinPayAccount> settings) {
|
||||
this.settings = settings;
|
||||
this.payApi = new PayApi(settings.getPayAccount());
|
||||
this.couponApi = new CouponApi(settings.getPayAccount());
|
||||
this.cashApi = new CashApi(settings.getPayAccount());
|
||||
this.customsApi = new CustomsApi(settings.getPayAccount());
|
||||
this.payApi = new PayApi(settings.getAccount());
|
||||
this.couponApi = new CouponApi(settings.getAccount());
|
||||
this.cashApi = new CashApi(settings.getAccount());
|
||||
this.customsApi = new CustomsApi(settings.getAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信商户支付信息
|
||||
* 获取微信商户账号信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WeixinPayAccount getWeixinPayAccount() {
|
||||
return this.settings.getPayAccount();
|
||||
return settings.getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +116,7 @@ public class WeixinPayProxy {
|
||||
* @return
|
||||
*/
|
||||
public WeixinSignature getWeixinSignature() {
|
||||
return this.payApi.getWeixinSignature();
|
||||
return payApi.getWeixinSignature();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
package com.foxinmy.weixin4j.setting;
|
||||
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
|
||||
/**
|
||||
* 系统配置相关
|
||||
*
|
||||
* @className SystemSettings
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年1月28日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public abstract class SystemSettings<T> {
|
||||
/**
|
||||
* 账号信息
|
||||
*/
|
||||
private T account;
|
||||
/**
|
||||
* Http参数
|
||||
*/
|
||||
private HttpParams httpParams;
|
||||
/**
|
||||
* 系统临时目录
|
||||
*/
|
||||
private String tmpdir;
|
||||
|
||||
/**
|
||||
* @param account
|
||||
*/
|
||||
public SystemSettings(T account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public T getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams() {
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams0() {
|
||||
if (httpParams == null) {
|
||||
return new HttpParams();
|
||||
}
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public String getTmpdir() {
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
public abstract String getTmpdir0();
|
||||
|
||||
public void setHttpParams(HttpParams httpParams) {
|
||||
this.httpParams = httpParams;
|
||||
}
|
||||
|
||||
public void setTmpdir(String tmpdir) {
|
||||
this.tmpdir = tmpdir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "account=" + account + ", httpParams=" + httpParams
|
||||
+ ", tmpdir=" + tmpdir;
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,9 @@
|
||||
package com.foxinmy.weixin4j.setting;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.cache.FileCacheStorager;
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
@ -18,11 +16,19 @@ import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class Weixin4jSettings extends SystemSettings<WeixinAccount> {
|
||||
public class Weixin4jSettings<T> {
|
||||
/**
|
||||
* 微信支付账号信息
|
||||
* 账号信息
|
||||
*/
|
||||
private WeixinPayAccount weixinPayAccount;
|
||||
private final T account;
|
||||
/**
|
||||
* Http参数
|
||||
*/
|
||||
private HttpParams httpParams;
|
||||
/**
|
||||
* 系统临时目录
|
||||
*/
|
||||
private String tmpdir;
|
||||
/**
|
||||
* Token的存储方式 默认为FileCacheStorager
|
||||
*/
|
||||
@ -32,60 +38,36 @@ public class Weixin4jSettings extends SystemSettings<WeixinAccount> {
|
||||
*/
|
||||
private String certificateFile;
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置的信息
|
||||
*/
|
||||
public Weixin4jSettings() {
|
||||
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
|
||||
WeixinPayAccount.class), null);
|
||||
public Weixin4jSettings(T account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付代理接口
|
||||
*
|
||||
* @param weixinPayAccount
|
||||
* 商户信息
|
||||
* @param certificateFile
|
||||
* 支付接口需要的证书文件(*.p12),比如退款接口
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount,
|
||||
String certificateFile) {
|
||||
this(weixinPayAccount);
|
||||
this.certificateFile = certificateFile;
|
||||
public T getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付代理接口
|
||||
*
|
||||
* @param weixinPayAccount
|
||||
* 商户信息
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount) {
|
||||
this(new WeixinAccount(weixinPayAccount.getId(),
|
||||
weixinPayAccount.getSecret()));
|
||||
this.weixinPayAccount = weixinPayAccount;
|
||||
public HttpParams getHttpParams() {
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号信息
|
||||
*
|
||||
* @param account
|
||||
*/
|
||||
public Weixin4jSettings(WeixinAccount account) {
|
||||
super(account);
|
||||
public String getTmpdir() {
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
public WeixinPayAccount getPayAccount() {
|
||||
return weixinPayAccount;
|
||||
public void setHttpParams(HttpParams httpParams) {
|
||||
this.httpParams = httpParams;
|
||||
}
|
||||
|
||||
public void setTmpdir(String tmpdir) {
|
||||
this.tmpdir = tmpdir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTmpdir0() {
|
||||
if (StringUtil.isBlank(getTmpdir())) {
|
||||
return Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
if (StringUtil.isBlank(tmpdir)) {
|
||||
return Weixin4jConfigUtil.getValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
return getTmpdir();
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
public CacheStorager<Token> getCacheStorager() {
|
||||
@ -121,8 +103,8 @@ public class Weixin4jSettings extends SystemSettings<WeixinAccount> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weixin4jSettings [weixinPayAccount=" + weixinPayAccount
|
||||
+ ", certificateFile=" + certificateFile + ", "
|
||||
+ super.toString() + "]";
|
||||
return "Weixin4jSettings [account=" + account + ", httpParams="
|
||||
+ httpParams + ", tmpdir=" + tmpdir + ", cacheStorager="
|
||||
+ cacheStorager + ", certificateFile=" + certificateFile + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,10 +23,12 @@ public class HttpClientTest {
|
||||
static HttpRequest request = new HttpRequest(HttpMethod.GET,
|
||||
"http://www.iteye.com/");
|
||||
static {
|
||||
HttpParams params = new HttpParams();
|
||||
params.setProxy(new Proxy(Type.HTTP, new InetSocketAddress(
|
||||
"117.136.234.9", 80)));
|
||||
//request.setParams(params);
|
||||
HttpParams params = HttpParams
|
||||
.custom()
|
||||
.setProxy(
|
||||
new Proxy(Type.HTTP, new InetSocketAddress(
|
||||
"117.136.234.9", 80))).build();
|
||||
// request.setParams(params);
|
||||
}
|
||||
|
||||
public static void test1() throws HttpClientException {
|
||||
@ -68,6 +70,6 @@ public class HttpClientTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test1();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +58,7 @@ import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||
import com.foxinmy.weixin4j.tuple.Tuple;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.type.TicketType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* 微信公众平台接口实现
|
||||
@ -125,13 +126,14 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
private Weixin4jSettings settings;
|
||||
private Weixin4jSettings<WeixinAccount> settings;
|
||||
|
||||
/**
|
||||
* 默认使用文件方式保存token、使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
public WeixinProxy() {
|
||||
this(new Weixin4jSettings());
|
||||
this(new Weixin4jSettings<WeixinAccount>(
|
||||
Weixin4jConfigUtil.getWeixinAccount()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,7 +142,7 @@ public class WeixinProxy {
|
||||
* 微信配置信息
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinProxy(Weixin4jSettings settings) {
|
||||
public WeixinProxy(Weixin4jSettings<WeixinAccount> settings) {
|
||||
this(new TokenManager(new WeixinTokenCreator(settings.getAccount()
|
||||
.getId(), settings.getAccount().getSecret()),
|
||||
settings.getCacheStorager0()));
|
||||
@ -152,6 +154,7 @@ public class WeixinProxy {
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.token.WeixinTokenCreator
|
||||
* @param tokenManager
|
||||
* token管理
|
||||
*/
|
||||
private WeixinProxy(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
|
||||
@ -17,7 +17,6 @@ import com.foxinmy.weixin4j.http.ContentType;
|
||||
import com.foxinmy.weixin4j.http.HttpClientException;
|
||||
import com.foxinmy.weixin4j.http.HttpHeaders;
|
||||
import com.foxinmy.weixin4j.http.HttpMethod;
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
import com.foxinmy.weixin4j.http.HttpResponse;
|
||||
import com.foxinmy.weixin4j.http.apache.ByteArrayBody;
|
||||
@ -252,8 +251,7 @@ public class MediaApi extends MpApi {
|
||||
request = new HttpRequest(HttpMethod.GET, String.format(
|
||||
meida_download_uri, token.getAccessToken(), mediaId));
|
||||
}
|
||||
HttpParams params = weixinExecutor.getExecuteParams();
|
||||
request.setParams(params);
|
||||
request.setParams(weixinExecutor.getExecuteParams());
|
||||
logger.info("weixin request >> " + request.getMethod() + " "
|
||||
+ request.getURI().toString());
|
||||
HttpResponse response = weixinExecutor.getExecuteClient().execute(
|
||||
|
||||
@ -5,9 +5,11 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* token测试
|
||||
@ -20,11 +22,12 @@ import com.foxinmy.weixin4j.token.TokenManager;
|
||||
public class TokenTest {
|
||||
|
||||
protected TokenManager tokenManager;
|
||||
protected Weixin4jSettings settings;
|
||||
protected Weixin4jSettings<WeixinAccount> settings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.settings = new Weixin4jSettings();
|
||||
this.settings = new Weixin4jSettings<WeixinAccount>(
|
||||
Weixin4jConfigUtil.getWeixinAccount());
|
||||
tokenManager = new TokenManager(new WeixinTokenCreator(settings
|
||||
.getAccount().getId(), settings.getAccount().getSecret()),
|
||||
settings.getCacheStorager0());
|
||||
|
||||
@ -51,6 +51,7 @@ import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.type.TicketType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* 微信企业号接口实现
|
||||
@ -110,13 +111,14 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
private Weixin4jSettings settings;
|
||||
private Weixin4jSettings<WeixinAccount> settings;
|
||||
|
||||
/**
|
||||
* 默认使用文件方式保存token、使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
public WeixinProxy() {
|
||||
this(new Weixin4jSettings());
|
||||
this(new Weixin4jSettings<WeixinAccount>(
|
||||
Weixin4jConfigUtil.getWeixinAccount()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +127,7 @@ public class WeixinProxy {
|
||||
* 微信配置信息
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinProxy(Weixin4jSettings settings) {
|
||||
public WeixinProxy(Weixin4jSettings<WeixinAccount> settings) {
|
||||
this(new TokenManager(new WeixinTokenCreator(settings.getAccount()
|
||||
.getId(), settings.getAccount().getSecret()),
|
||||
settings.getCacheStorager0()));
|
||||
@ -148,7 +150,7 @@ public class WeixinProxy {
|
||||
TokenManager suiteTokenManager) {
|
||||
this(new TokenManager(new WeixinTokenSuiteCreator(perCodeManager,
|
||||
suiteTokenManager), perCodeManager.getCacheStorager()));
|
||||
this.settings = new Weixin4jSettings(new WeixinAccount(
|
||||
this.settings = new Weixin4jSettings<WeixinAccount>(new WeixinAccount(
|
||||
perCodeManager.getAuthCorpId(), null));
|
||||
}
|
||||
|
||||
|
||||
@ -3,8 +3,10 @@ package com.foxinmy.weixin4j.qy;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
@ -13,10 +15,10 @@ import com.foxinmy.weixin4j.qy.api.SuiteApi;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.WeixinQyAccount;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteTicketManager;
|
||||
import com.foxinmy.weixin4j.qy.suite.Weixin4jSuiteSettings;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinProviderTokenCreator;
|
||||
import com.foxinmy.weixin4j.qy.type.LoginTargetType;
|
||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
@ -46,41 +48,44 @@ public class WeixinSuiteProxy {
|
||||
/**
|
||||
* 配置相关
|
||||
*/
|
||||
private final Weixin4jSuiteSettings suiteSettings;
|
||||
private final Weixin4jSettings<WeixinQyAccount> settings;
|
||||
|
||||
/**
|
||||
* 默认使用文件方式保存token、使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
public WeixinSuiteProxy() {
|
||||
this(new Weixin4jSuiteSettings());
|
||||
this(new Weixin4jSettings<WeixinQyAccount>(JSON.parseObject(
|
||||
Weixin4jConfigUtil.getValue("account"), WeixinQyAccount.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param suiteSettings
|
||||
* 套件信息配置
|
||||
* @param settings
|
||||
* 配置信息
|
||||
*/
|
||||
public WeixinSuiteProxy(Weixin4jSuiteSettings suiteSettings) {
|
||||
this.suiteSettings = suiteSettings;
|
||||
if (suiteSettings.getAccount().getSuiteAccounts() != null) {
|
||||
this.suiteMap = new HashMap<String, SuiteApi>();
|
||||
for (WeixinAccount suite : suiteSettings.getAccount()
|
||||
.getSuiteAccounts()) {
|
||||
this.suiteMap.put(suite.getId(), new SuiteApi(
|
||||
new SuiteTicketManager(suite.getId(), suite.getSecret(),
|
||||
suiteSettings.getCacheStorager0())));
|
||||
public WeixinSuiteProxy(Weixin4jSettings<WeixinQyAccount> settings) {
|
||||
this.settings = settings;
|
||||
List<WeixinAccount> suites = settings.getAccount().getSuites();
|
||||
if (suites != null && !suites.isEmpty()) {
|
||||
this.suiteMap = new HashMap<String, SuiteApi>(suites.size());
|
||||
for (WeixinAccount suite : suites) {
|
||||
this.suiteMap.put(
|
||||
null,
|
||||
suiteMap.get(suiteSettings.getAccount()
|
||||
.getSuiteAccounts().get(0).getId()));
|
||||
suite.getId(),
|
||||
new SuiteApi(
|
||||
new SuiteTicketManager(suite.getId(), suite
|
||||
.getSecret(), settings
|
||||
.getCacheStorager0())));
|
||||
}
|
||||
this.suiteMap.put(null, suiteMap.get(suites.get(0).getId()));
|
||||
}
|
||||
if (StringUtil.isNotBlank(suiteSettings.getAccount().getId())
|
||||
&& StringUtil.isNotBlank(suiteSettings.getAccount()
|
||||
if (StringUtil.isNotBlank(settings.getAccount().getId())
|
||||
&& StringUtil.isNotBlank(settings.getAccount()
|
||||
.getProviderSecret())) {
|
||||
this.providerApi = new ProviderApi(new TokenManager(
|
||||
new WeixinProviderTokenCreator(suiteSettings
|
||||
.getAccount().getId(), suiteSettings
|
||||
.getAccount().getProviderSecret()),
|
||||
suiteSettings.getCacheStorager0()),
|
||||
suiteSettings.getCacheStorager0());
|
||||
this.providerApi = new ProviderApi(
|
||||
new TokenManager(new WeixinProviderTokenCreator(settings
|
||||
.getAccount().getId(), settings.getAccount()
|
||||
.getProviderSecret()), settings.getCacheStorager0()),
|
||||
settings.getCacheStorager0());
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +95,7 @@ public class WeixinSuiteProxy {
|
||||
* @return
|
||||
*/
|
||||
public WeixinQyAccount getWeixinAccount() {
|
||||
return this.suiteSettings.getAccount();
|
||||
return this.settings.getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -20,7 +20,6 @@ import com.foxinmy.weixin4j.http.ContentType;
|
||||
import com.foxinmy.weixin4j.http.HttpClientException;
|
||||
import com.foxinmy.weixin4j.http.HttpHeaders;
|
||||
import com.foxinmy.weixin4j.http.HttpMethod;
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
import com.foxinmy.weixin4j.http.HttpResponse;
|
||||
import com.foxinmy.weixin4j.http.apache.ByteArrayBody;
|
||||
@ -50,7 +49,7 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 媒体相关API
|
||||
*
|
||||
*
|
||||
* @className MediaApi
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年9月25日
|
||||
@ -70,7 +69,7 @@ public class MediaApi extends QyApi {
|
||||
/**
|
||||
* 上传图文消息内的图片:用于上传图片到企业号服务端,接口返回图片url,请注意,该url仅可用于图文消息的发送,
|
||||
* 且每个企业每天最多只能上传100张图片。
|
||||
*
|
||||
*
|
||||
* @param is
|
||||
* 图片数据
|
||||
* @param fileName
|
||||
@ -103,7 +102,7 @@ public class MediaApi extends QyApi {
|
||||
* 正常情况下返回{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789},
|
||||
* 否则抛出异常.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用ID(<font color="red">大于0时视为上传永久媒体文件</font>)
|
||||
* @param is
|
||||
@ -185,7 +184,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 下载媒体文件
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用Id(<font color="red">大于0时视为获取永久媒体文件</font>)
|
||||
* @param mediaId
|
||||
@ -213,8 +212,7 @@ public class MediaApi extends QyApi {
|
||||
request = new HttpRequest(HttpMethod.GET, String.format(
|
||||
media_download_uri, token.getAccessToken(), mediaId));
|
||||
}
|
||||
HttpParams params = weixinExecutor.getExecuteParams();
|
||||
request.setParams(params);
|
||||
request.setParams(weixinExecutor.getExecuteParams());
|
||||
logger.info("weixin request >> " + request.getMethod() + " "
|
||||
+ request.getURI().toString());
|
||||
HttpResponse response = weixinExecutor.getExecuteClient().execute(
|
||||
@ -260,7 +258,7 @@ public class MediaApi extends QyApi {
|
||||
* 、新增的永久素材也可以在公众平台官网素材管理模块中看到,永久素材的数量是有上限的,请谨慎新增。图文消息素材和图片素材的上限为5000,
|
||||
* 其他类型为1000
|
||||
* </P>
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用的id
|
||||
* @param articles
|
||||
@ -289,7 +287,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 删除永久媒体素材
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用ID
|
||||
* @param mediaId
|
||||
@ -311,7 +309,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 下载永久图文素材
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用ID
|
||||
* @param mediaId
|
||||
@ -333,7 +331,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 修改永久图文素材
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用的id
|
||||
* @param mediaId
|
||||
@ -365,7 +363,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 获取永久媒体素材的总数
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用id
|
||||
* @return 总数对象
|
||||
@ -387,7 +385,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 获取媒体素材记录列表
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用ID
|
||||
* @param mediaType
|
||||
@ -427,7 +425,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 获取全部的媒体素材
|
||||
*
|
||||
*
|
||||
* @param agentid
|
||||
* 企业应用id
|
||||
* @param mediaType
|
||||
@ -458,7 +456,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 批量上传成员
|
||||
*
|
||||
*
|
||||
* @param users
|
||||
* 成员列表
|
||||
* @see {@link BatchApi#syncUser(String,Callback)}
|
||||
@ -474,7 +472,7 @@ public class MediaApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 批量上传部门
|
||||
*
|
||||
*
|
||||
* @param parties
|
||||
* 部门列表
|
||||
* @see {@link BatchApi#replaceParty(String,Callback)}
|
||||
|
||||
@ -8,7 +8,7 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
|
||||
/**
|
||||
* 微信企业号信息
|
||||
*
|
||||
*
|
||||
* @className WeixinQyAccount
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年11月18日
|
||||
@ -23,7 +23,7 @@ public class WeixinQyAccount extends WeixinAccount {
|
||||
/**
|
||||
* 多个应用套件信息
|
||||
*/
|
||||
private List<WeixinAccount> suiteAccounts;
|
||||
private List<WeixinAccount> suites;
|
||||
/**
|
||||
* 第三方提供商secret(企业号登陆)
|
||||
*/
|
||||
@ -34,7 +34,7 @@ public class WeixinQyAccount extends WeixinAccount {
|
||||
private String chatSecret;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param corpid
|
||||
* 企业ID 必填
|
||||
* @param corpsecret
|
||||
@ -49,17 +49,17 @@ public class WeixinQyAccount extends WeixinAccount {
|
||||
@JSONCreator
|
||||
public WeixinQyAccount(@JSONField(name = "id") String corpid,
|
||||
@JSONField(name = "secret") String corpsecret,
|
||||
@JSONField(name = "suiteAccounts") List<WeixinAccount> suiteAccounts,
|
||||
@JSONField(name = "suites") List<WeixinAccount> suites,
|
||||
@JSONField(name = "providerSecret") String providerSecret,
|
||||
@JSONField(name = "chatSecret") String chatSecret) {
|
||||
super(corpid, corpsecret);
|
||||
this.suiteAccounts = suiteAccounts;
|
||||
this.suites = suites;
|
||||
this.providerSecret = providerSecret;
|
||||
this.chatSecret = chatSecret;
|
||||
}
|
||||
|
||||
public List<WeixinAccount> getSuiteAccounts() {
|
||||
return suiteAccounts;
|
||||
public List<WeixinAccount> getSuites() {
|
||||
return suites;
|
||||
}
|
||||
|
||||
public String getProviderSecret() {
|
||||
@ -70,15 +70,15 @@ public class WeixinQyAccount extends WeixinAccount {
|
||||
return chatSecret;
|
||||
}
|
||||
|
||||
public WeixinAccount[] suiteAccountsToArray() {
|
||||
return suiteAccounts != null ? suiteAccounts
|
||||
.toArray(new WeixinAccount[suiteAccounts.size()]) : null;
|
||||
public WeixinAccount[] suitesToArray() {
|
||||
return suites != null ? suites
|
||||
.toArray(new WeixinAccount[suites.size()]) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WeixinQyAccount [" + super.toString() + ", suiteAccounts="
|
||||
+ suiteAccounts + ", providerSecret=" + providerSecret
|
||||
+ suites + ", providerSecret=" + providerSecret
|
||||
+ ", chatSecret=" + chatSecret + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,86 +0,0 @@
|
||||
package com.foxinmy.weixin4j.qy.suite;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.cache.FileCacheStorager;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.qy.model.WeixinQyAccount;
|
||||
import com.foxinmy.weixin4j.setting.SystemSettings;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* 微信第三方套件配置相关
|
||||
*
|
||||
* @className Weixin4jSuiteSettings
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年1月28日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class Weixin4jSuiteSettings extends SystemSettings<WeixinQyAccount> {
|
||||
/**
|
||||
* Token的存储方式 默认为FileCacheStorager
|
||||
*/
|
||||
private CacheStorager<Token> cacheStorager;
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置的信息
|
||||
*/
|
||||
public Weixin4jSuiteSettings() {
|
||||
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
|
||||
WeixinQyAccount.class));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param providerCorpId
|
||||
* 服务商的企业号ID <font color="red">使用服务商API时必填项</font>
|
||||
* @param providerSecret
|
||||
* 服务商secret <font color="red">使用服务商API时必填项</font>
|
||||
* @param suites
|
||||
* 套件信息 <font color="red">使用套件API时必填项</font>
|
||||
*/
|
||||
public Weixin4jSuiteSettings(String providerCorpId, String providerSecret,
|
||||
WeixinAccount... suites) {
|
||||
this(new WeixinQyAccount(providerCorpId, null, Arrays.asList(suites),
|
||||
providerSecret, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号信息
|
||||
*
|
||||
* @param account
|
||||
*/
|
||||
private Weixin4jSuiteSettings(WeixinQyAccount account) {
|
||||
super(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTmpdir0() {
|
||||
if (StringUtil.isBlank(getTmpdir())) {
|
||||
return Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
return getTmpdir();
|
||||
}
|
||||
|
||||
public CacheStorager<Token> getCacheStorager() {
|
||||
return cacheStorager;
|
||||
}
|
||||
|
||||
public CacheStorager<Token> getCacheStorager0() {
|
||||
if (cacheStorager == null) {
|
||||
return new FileCacheStorager<Token>(getTmpdir0());
|
||||
}
|
||||
return cacheStorager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weixin4jSuiteSettings [" + super.toString() + "]";
|
||||
}
|
||||
}
|
||||
@ -5,9 +5,11 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* token测试
|
||||
@ -20,14 +22,15 @@ import com.foxinmy.weixin4j.token.TokenManager;
|
||||
public class TokenTest {
|
||||
|
||||
protected TokenManager tokenManager;
|
||||
protected Weixin4jSettings settings;
|
||||
protected Weixin4jSettings<WeixinAccount> settings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.settings = new Weixin4jSettings();
|
||||
this.settings = new Weixin4jSettings<WeixinAccount>(
|
||||
Weixin4jConfigUtil.getWeixinAccount());
|
||||
tokenManager = new TokenManager(new WeixinTokenCreator(settings
|
||||
.getAccount().getId(), settings.getAccount()
|
||||
.getSecret()), settings.getCacheStorager0());
|
||||
.getAccount().getId(), settings.getAccount().getSecret()),
|
||||
settings.getCacheStorager0());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user