|
|
@@ -1,10 +1,13 @@ |
|
|
|
package me.chanjar.weixin.cp.api; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
|
|
|
import org.apache.commons.lang3.builder.ToStringStyle; |
|
|
|
|
|
|
|
import me.chanjar.weixin.common.bean.WxAccessToken; |
|
|
|
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
/** |
|
|
|
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化 |
|
|
|
* |
|
|
@@ -35,6 +38,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
|
|
|
|
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder; |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getAccessToken() { |
|
|
|
return this.accessToken; |
|
|
|
} |
|
|
@@ -43,18 +47,22 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
this.accessToken = accessToken; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isAccessTokenExpired() { |
|
|
|
return System.currentTimeMillis() > this.expiresTime; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void expireAccessToken() { |
|
|
|
this.expiresTime = 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public synchronized void updateAccessToken(WxAccessToken accessToken) { |
|
|
|
updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) { |
|
|
|
this.accessToken = accessToken; |
|
|
|
this.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000l; |
|
|
@@ -62,7 +70,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getJsapiTicket() { |
|
|
|
return jsapiTicket; |
|
|
|
return this.jsapiTicket; |
|
|
|
} |
|
|
|
|
|
|
|
public void setJsapiTicket(String jsapiTicket) { |
|
|
@@ -70,27 +78,31 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
} |
|
|
|
|
|
|
|
public long getJsapiTicketExpiresTime() { |
|
|
|
return jsapiTicketExpiresTime; |
|
|
|
return this.jsapiTicketExpiresTime; |
|
|
|
} |
|
|
|
|
|
|
|
public void setJsapiTicketExpiresTime(long jsapiTicketExpiresTime) { |
|
|
|
this.jsapiTicketExpiresTime = jsapiTicketExpiresTime; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isJsapiTicketExpired() { |
|
|
|
return System.currentTimeMillis() > this.jsapiTicketExpiresTime; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) { |
|
|
|
this.jsapiTicket = jsapiTicket; |
|
|
|
// 预留200秒的时间 |
|
|
|
this.jsapiTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000l; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void expireJsapiTicket() { |
|
|
|
this.jsapiTicketExpiresTime = 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getCorpId() { |
|
|
|
return this.corpId; |
|
|
|
} |
|
|
@@ -99,6 +111,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
this.corpId = corpId; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getCorpSecret() { |
|
|
|
return this.corpSecret; |
|
|
|
} |
|
|
@@ -107,6 +120,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
this.corpSecret = corpSecret; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getToken() { |
|
|
|
return this.token; |
|
|
|
} |
|
|
@@ -115,6 +129,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
this.token = token; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public long getExpiresTime() { |
|
|
|
return this.expiresTime; |
|
|
|
} |
|
|
@@ -123,16 +138,18 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
this.expiresTime = expiresTime; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getAesKey() { |
|
|
|
return aesKey; |
|
|
|
return this.aesKey; |
|
|
|
} |
|
|
|
|
|
|
|
public void setAesKey(String aesKey) { |
|
|
|
this.aesKey = aesKey; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getAgentId() { |
|
|
|
return agentId; |
|
|
|
return this.agentId; |
|
|
|
} |
|
|
|
|
|
|
|
public void setAgentId(String agentId) { |
|
|
@@ -148,32 +165,36 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
this.oauth2redirectUri = oauth2redirectUri; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getHttp_proxy_host() { |
|
|
|
return http_proxy_host; |
|
|
|
return this.http_proxy_host; |
|
|
|
} |
|
|
|
|
|
|
|
public void setHttp_proxy_host(String http_proxy_host) { |
|
|
|
this.http_proxy_host = http_proxy_host; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int getHttp_proxy_port() { |
|
|
|
return http_proxy_port; |
|
|
|
return this.http_proxy_port; |
|
|
|
} |
|
|
|
|
|
|
|
public void setHttp_proxy_port(int http_proxy_port) { |
|
|
|
this.http_proxy_port = http_proxy_port; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getHttp_proxy_username() { |
|
|
|
return http_proxy_username; |
|
|
|
return this.http_proxy_username; |
|
|
|
} |
|
|
|
|
|
|
|
public void setHttp_proxy_username(String http_proxy_username) { |
|
|
|
this.http_proxy_username = http_proxy_username; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getHttp_proxy_password() { |
|
|
|
return http_proxy_password; |
|
|
|
return this.http_proxy_password; |
|
|
|
} |
|
|
|
|
|
|
|
public void setHttp_proxy_password(String http_proxy_password) { |
|
|
@@ -182,26 +203,12 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
return "WxCpInMemoryConfigStorage{" + |
|
|
|
"corpId='" + corpId + '\'' + |
|
|
|
", corpSecret='" + corpSecret + '\'' + |
|
|
|
", token='" + token + '\'' + |
|
|
|
", accessToken='" + accessToken + '\'' + |
|
|
|
", aesKey='" + aesKey + '\'' + |
|
|
|
", agentId='" + agentId + '\'' + |
|
|
|
", expiresTime=" + expiresTime + |
|
|
|
", http_proxy_host='" + http_proxy_host + '\'' + |
|
|
|
", http_proxy_port=" + http_proxy_port + |
|
|
|
", http_proxy_username='" + http_proxy_username + '\'' + |
|
|
|
", http_proxy_password='" + http_proxy_password + '\'' + |
|
|
|
", jsapiTicket='" + jsapiTicket + '\'' + |
|
|
|
", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' + |
|
|
|
", tmpDirFile='" + tmpDirFile + '\'' + |
|
|
|
'}'; |
|
|
|
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public File getTmpDirFile() { |
|
|
|
return tmpDirFile; |
|
|
|
return this.tmpDirFile; |
|
|
|
} |
|
|
|
|
|
|
|
public void setTmpDirFile(File tmpDirFile) { |
|
|
|