|
@@ -22,7 +22,12 @@ import java.util.concurrent.locks.ReentrantLock;
|
|
|
*/
|
|
|
public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializable {
|
|
|
private static final long serialVersionUID = 6678780920621872824L;
|
|
|
-
|
|
|
+
|
|
|
+ private final transient Map<String, Lock> providerAccessTokenLocker = new ConcurrentHashMap<>();
|
|
|
+ private final transient Map<String, Lock> suiteAccessTokenLocker = new ConcurrentHashMap<>();
|
|
|
+ private final transient Map<String, Lock> accessTokenLocker = new ConcurrentHashMap<>();
|
|
|
+ private final transient Map<String, Lock> authCorpJsapiTicketLocker = new ConcurrentHashMap<>();
|
|
|
+ private final transient Map<String, Lock> authSuiteJsapiTicketLocker = new ConcurrentHashMap<>();
|
|
|
private volatile String corpId;
|
|
|
private volatile String corpSecret;
|
|
|
|
|
@@ -31,46 +36,29 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
private volatile String providerSecret;
|
|
|
private volatile String providerToken;
|
|
|
private volatile long providerTokenExpiresTime;
|
|
|
-
|
|
|
private volatile String suiteId;
|
|
|
private volatile String suiteSecret;
|
|
|
-
|
|
|
private volatile String token;
|
|
|
private volatile String suiteAccessToken;
|
|
|
private volatile long suiteAccessTokenExpiresTime;
|
|
|
private volatile String aesKey;
|
|
|
-
|
|
|
private volatile String suiteTicket;
|
|
|
private volatile long suiteTicketExpiresTime;
|
|
|
private volatile String oauth2redirectUri;
|
|
|
-
|
|
|
private volatile Map<String, String> authCorpAccessTokenMap = new HashMap<>();
|
|
|
private volatile Map<String, Long> authCorpAccessTokenExpireTimeMap = new HashMap<>();
|
|
|
-
|
|
|
private volatile Map<String, String> authCorpJsApiTicketMap = new HashMap<>();
|
|
|
private volatile Map<String, Long> authCorpJsApiTicketExpireTimeMap = new HashMap<>();
|
|
|
-
|
|
|
private volatile Map<String, String> authSuiteJsApiTicketMap = new HashMap<>();
|
|
|
private volatile Map<String, Long> authSuiteJsApiTicketExpireTimeMap = new HashMap<>();
|
|
|
-
|
|
|
private volatile String httpProxyHost;
|
|
|
private volatile int httpProxyPort;
|
|
|
private volatile String httpProxyUsername;
|
|
|
private volatile String httpProxyPassword;
|
|
|
-
|
|
|
private volatile File tmpDirFile;
|
|
|
-
|
|
|
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
|
|
|
-
|
|
|
private volatile String baseApiUrl;
|
|
|
|
|
|
-
|
|
|
- private final transient Map<String, Lock> providerAccessTokenLocker = new ConcurrentHashMap<>();
|
|
|
- private final transient Map<String, Lock> suiteAccessTokenLocker = new ConcurrentHashMap<>();
|
|
|
- private final transient Map<String, Lock> accessTokenLocker = new ConcurrentHashMap<>();
|
|
|
- private final transient Map<String, Lock> authCorpJsapiTicketLocker = new ConcurrentHashMap<>();
|
|
|
- private final transient Map<String, Lock> authSuiteJsapiTicketLocker = new ConcurrentHashMap<>();
|
|
|
-
|
|
|
@Override
|
|
|
public void setBaseApiUrl(String baseUrl) {
|
|
|
this.baseApiUrl = baseUrl;
|
|
@@ -89,6 +77,15 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.suiteAccessToken;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets suite access token.
|
|
|
+ *
|
|
|
+ * @param suiteAccessToken the suite access token
|
|
|
+ */
|
|
|
+ public void setSuiteAccessToken(String suiteAccessToken) {
|
|
|
+ this.suiteAccessToken = suiteAccessToken;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public WxAccessToken getSuiteAccessTokenEntity() {
|
|
|
WxAccessToken accessToken = new WxAccessToken();
|
|
@@ -98,10 +95,6 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return accessToken;
|
|
|
}
|
|
|
|
|
|
- public void setSuiteAccessToken(String suiteAccessToken) {
|
|
|
- this.suiteAccessToken = suiteAccessToken;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public boolean isSuiteAccessTokenExpired() {
|
|
|
return System.currentTimeMillis() > this.suiteAccessTokenExpiresTime;
|
|
@@ -123,6 +116,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
this.suiteAccessTokenExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets suite access token expires time.
|
|
|
+ *
|
|
|
+ * @param suiteAccessTokenExpiresTime the suite access token expires time
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setSuiteAccessTokenExpiresTime(long suiteAccessTokenExpiresTime) {
|
|
|
this.suiteAccessTokenExpiresTime = suiteAccessTokenExpiresTime;
|
|
@@ -133,6 +131,16 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.suiteTicket;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets suite ticket.
|
|
|
+ *
|
|
|
+ * @param suiteTicket the suite ticket
|
|
|
+ */
|
|
|
+ @Deprecated
|
|
|
+ public void setSuiteTicket(String suiteTicket) {
|
|
|
+ this.suiteTicket = suiteTicket;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean isSuiteTicketExpired() {
|
|
|
return System.currentTimeMillis() > this.suiteTicketExpiresTime;
|
|
@@ -150,17 +158,21 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
this.suiteTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Deprecated
|
|
|
- public void setSuiteTicket(String suiteTicket) {
|
|
|
- this.suiteTicket = suiteTicket;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ * Gets suite ticket expires time.
|
|
|
+ *
|
|
|
+ * @return the suite ticket expires time
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public long getSuiteTicketExpiresTime() {
|
|
|
return this.suiteTicketExpiresTime;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets suite ticket expires time.
|
|
|
+ *
|
|
|
+ * @param suiteTicketExpiresTime the suite ticket expires time
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setSuiteTicketExpiresTime(long suiteTicketExpiresTime) {
|
|
|
this.suiteTicketExpiresTime = suiteTicketExpiresTime;
|
|
@@ -171,6 +183,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.suiteId;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets suite id.
|
|
|
+ *
|
|
|
+ * @param corpId the corp id
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setSuiteId(String corpId) {
|
|
|
this.suiteId = corpId;
|
|
@@ -181,6 +198,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.suiteSecret;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets suite secret.
|
|
|
+ *
|
|
|
+ * @param corpSecret the corp secret
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setSuiteSecret(String corpSecret) {
|
|
|
this.suiteSecret = corpSecret;
|
|
@@ -191,6 +213,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.token;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets token.
|
|
|
+ *
|
|
|
+ * @param token the token
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setToken(String token) {
|
|
|
this.token = token;
|
|
@@ -201,6 +228,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.aesKey;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets aes key.
|
|
|
+ *
|
|
|
+ * @param aesKey the aes key
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setAesKey(String aesKey) {
|
|
|
this.aesKey = aesKey;
|
|
@@ -212,6 +244,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.corpId;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets corp id.
|
|
|
+ *
|
|
|
+ * @param corpId the corp id
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setCorpId(String corpId) {
|
|
|
this.corpId = corpId;
|
|
@@ -222,16 +259,20 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.corpSecret;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public String getProviderSecret() {
|
|
|
- return providerSecret;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ * Sets corp secret.
|
|
|
+ *
|
|
|
+ * @param corpSecret the corp secret
|
|
|
+ */
|
|
|
@Deprecated
|
|
|
public void setCorpSecret(String corpSecret) {
|
|
|
this.corpSecret = corpSecret;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getProviderSecret() {
|
|
|
+ return providerSecret;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public String getAccessToken(String authCorpId) {
|
|
@@ -244,7 +285,7 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
Long expire = authCorpAccessTokenExpireTimeMap.getOrDefault(authCorpId, 0L);
|
|
|
WxAccessToken accessTokenEntity = new WxAccessToken();
|
|
|
accessTokenEntity.setAccessToken(accessToken);
|
|
|
- accessTokenEntity.setExpiresIn((int)((expire - System.currentTimeMillis()) / 1000 + 200));
|
|
|
+ accessTokenEntity.setExpiresIn((int) ((expire - System.currentTimeMillis()) / 1000 + 200));
|
|
|
return accessTokenEntity;
|
|
|
}
|
|
|
|
|
@@ -252,16 +293,16 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
public boolean isAccessTokenExpired(String authCorpId) {
|
|
|
|
|
|
return authCorpAccessTokenExpireTimeMap.get(authCorpId) == null
|
|
|
- || System.currentTimeMillis() > authCorpAccessTokenExpireTimeMap.get(authCorpId);
|
|
|
+ || System.currentTimeMillis() > authCorpAccessTokenExpireTimeMap.get(authCorpId);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void expireAccessToken(String authCorpId) {
|
|
|
+ @Override
|
|
|
+ public void expireAccessToken(String authCorpId) {
|
|
|
authCorpAccessTokenMap.remove(authCorpId);
|
|
|
authCorpAccessTokenExpireTimeMap.remove(authCorpId);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
public void updateAccessToken(String authCorpId, String accessToken, int expiredInSeconds) {
|
|
|
authCorpAccessTokenMap.put(authCorpId, accessToken);
|
|
|
|
|
@@ -353,6 +394,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
this.providerTokenExpiresTime = 0L;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets oauth 2 redirect uri.
|
|
|
+ *
|
|
|
+ * @param oauth2redirectUri the oauth 2 redirect uri
|
|
|
+ */
|
|
|
public void setOauth2redirectUri(String oauth2redirectUri) {
|
|
|
this.oauth2redirectUri = oauth2redirectUri;
|
|
|
}
|
|
@@ -362,6 +408,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.httpProxyHost;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets http proxy host.
|
|
|
+ *
|
|
|
+ * @param httpProxyHost the http proxy host
|
|
|
+ */
|
|
|
public void setHttpProxyHost(String httpProxyHost) {
|
|
|
this.httpProxyHost = httpProxyHost;
|
|
|
}
|
|
@@ -371,6 +422,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.httpProxyPort;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets http proxy port.
|
|
|
+ *
|
|
|
+ * @param httpProxyPort the http proxy port
|
|
|
+ */
|
|
|
public void setHttpProxyPort(int httpProxyPort) {
|
|
|
this.httpProxyPort = httpProxyPort;
|
|
|
}
|
|
@@ -380,6 +436,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.httpProxyUsername;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets http proxy username.
|
|
|
+ *
|
|
|
+ * @param httpProxyUsername the http proxy username
|
|
|
+ */
|
|
|
public void setHttpProxyUsername(String httpProxyUsername) {
|
|
|
this.httpProxyUsername = httpProxyUsername;
|
|
|
}
|
|
@@ -389,6 +450,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.httpProxyPassword;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets http proxy password.
|
|
|
+ *
|
|
|
+ * @param httpProxyPassword the http proxy password
|
|
|
+ */
|
|
|
public void setHttpProxyPassword(String httpProxyPassword) {
|
|
|
this.httpProxyPassword = httpProxyPassword;
|
|
|
}
|
|
@@ -403,6 +469,15 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
return this.tmpDirFile;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets tmp dir file.
|
|
|
+ *
|
|
|
+ * @param tmpDirFile the tmp dir file
|
|
|
+ */
|
|
|
+ public void setTmpDirFile(File tmpDirFile) {
|
|
|
+ this.tmpDirFile = tmpDirFile;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Lock getProviderAccessTokenLock() {
|
|
|
return this.providerAccessTokenLocker
|
|
@@ -432,21 +507,22 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
|
|
|
.computeIfAbsent(String.join(":", this.suiteId, authCorpId), key -> new ReentrantLock());
|
|
|
}
|
|
|
|
|
|
- public void setTmpDirFile(File tmpDirFile) {
|
|
|
- this.tmpDirFile = tmpDirFile;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
|
|
|
return this.apacheHttpClientBuilder;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Sets apache http client builder.
|
|
|
+ *
|
|
|
+ * @param apacheHttpClientBuilder the apache http client builder
|
|
|
+ */
|
|
|
+ public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
|
|
|
+ this.apacheHttpClientBuilder = apacheHttpClientBuilder;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean autoRefreshToken() {
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
- public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
|
|
|
- this.apacheHttpClientBuilder = apacheHttpClientBuilder;
|
|
|
- }
|
|
|
}
|