...
|
...
|
@@ -43,41 +43,43 @@ public class MiniAppAccessTokenServiceImpl implements IMiniAppAccessTokenService |
|
|
*/
|
|
|
public AccessToken getTokenCache(String miniappType){
|
|
|
|
|
|
// 1 代表新与力的 小程序
|
|
|
// 0 有货的小程序
|
|
|
if (!"1".equals(miniappType)){
|
|
|
miniappType = "0";
|
|
|
}
|
|
|
|
|
|
String redisValue = pushRedisService.getValue(KeyBuilder.getMiniAppAccesTokenKey(miniappType));
|
|
|
if (StringUtils.isNotBlank(redisValue)) {
|
|
|
logger.info("getTokenCache redisValue is {}", redisValue);
|
|
|
return toAccessToken(redisValue);
|
|
|
} else {
|
|
|
return getAccessTokenFromUrl(miniappType);
|
|
|
|
|
|
AccessToken accessToken = getAccessToken(redisValue);
|
|
|
|
|
|
if (accessToken != null){
|
|
|
return accessToken;
|
|
|
}
|
|
|
|
|
|
return getAccessTokenFromUrl(miniappType);
|
|
|
}
|
|
|
|
|
|
private static AccessToken toAccessToken(String tokenValue) {
|
|
|
if (StringUtils.isNotBlank(tokenValue)) {
|
|
|
String[] data = tokenValue.split(",");
|
|
|
AccessToken accessToken = new AccessToken();
|
|
|
accessToken.setToken(data[0]);
|
|
|
accessToken.setExpiresIn(Integer.valueOf(data[1]));
|
|
|
return accessToken;
|
|
|
|
|
|
public AccessToken getAccessToken(String redisValue){
|
|
|
|
|
|
if (StringUtils.isEmpty(redisValue)){
|
|
|
return null;
|
|
|
}
|
|
|
return null;
|
|
|
|
|
|
try{
|
|
|
logger.info("getTokenCache redisValue is {}", redisValue);
|
|
|
return JSONObject.parseObject(redisValue, AccessToken.class);
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public AccessToken getAccessTokenFromUrl(String miniappType) {
|
|
|
String url = MINI_ACCESSTOKEN_GET+"&miniappType="+miniappType;
|
|
|
JSONObject res = HttpClientUtil.doGet(url, "UTF-8");
|
|
|
logger.info("getAccessTokenFromUrl is {}, result is {}", url, JSONObject.toJSONString(res));
|
|
|
if (null != res && res.getIntValue("code") == 200) {
|
|
|
AccessToken accessToken = new AccessToken(res.getString("data"), 1800);
|
|
|
|
|
|
pushRedisService.setValue(KeyBuilder.getMiniAppAccesTokenKey(miniappType),
|
|
|
accessToken.getToken() + "," + 1800, 1800, TimeUnit.SECONDS);
|
|
|
JSONObject.toJSONString(accessToken), 1800, TimeUnit.SECONDS);
|
|
|
return accessToken;
|
|
|
}
|
|
|
return null;
|
...
|
...
|
|