|
|
@ -18,6 +18,7 @@ import com.jianshui.common.exception.jianshui.JianshuiParamErrorException; |
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiServiceConfigErrorException; |
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiServiceConfigErrorException; |
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiServiceException; |
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiServiceException; |
|
|
|
import com.jianshui.common.utils.StringUtils; |
|
|
|
import com.jianshui.common.utils.StringUtils; |
|
|
|
|
|
|
|
import com.jianshui.common.utils.TimeUtil; |
|
|
|
import com.jianshui.common.utils.http.HttpUtils; |
|
|
|
import com.jianshui.common.utils.http.HttpUtils; |
|
|
|
import com.jianshui.common.utils.jianshui.CommonUtils; |
|
|
|
import com.jianshui.common.utils.jianshui.CommonUtils; |
|
|
|
import com.jianshui.common.utils.spring.SpringUtils; |
|
|
|
import com.jianshui.common.utils.spring.SpringUtils; |
|
|
@ -46,6 +47,7 @@ import java.security.InvalidKeyException; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @Description 大象销项工具类 |
|
|
|
* @Description 大象销项工具类 |
|
|
@ -264,11 +266,9 @@ public class ElephantUtils { |
|
|
|
|
|
|
|
|
|
|
|
// 如果不为空,且没有过期
|
|
|
|
// 如果不为空,且没有过期
|
|
|
|
if (temp != null) { |
|
|
|
if (temp != null) { |
|
|
|
Long exprieTimeTemp = (Long) temp.get("exprieTime"); |
|
|
|
|
|
|
|
if (System.currentTimeMillis() < exprieTimeTemp) { |
|
|
|
|
|
|
|
return (String) temp.get("access_token"); |
|
|
|
return (String) temp.get("access_token"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
companyserviceProp = configService.selectPropByKey(companyservice.getCompanyid(), "elephant_secret"); |
|
|
|
companyserviceProp = configService.selectPropByKey(companyservice.getCompanyid(), "elephant_secret"); |
|
|
|
String appSecret = companyserviceProp.getValue(); |
|
|
|
String appSecret = companyserviceProp.getValue(); |
|
|
|
if (appSecret == null || "".equals(appSecret)) { |
|
|
|
if (appSecret == null || "".equals(appSecret)) { |
|
|
@ -288,11 +288,9 @@ public class ElephantUtils { |
|
|
|
header.put("Content-Type", "application/json"); |
|
|
|
header.put("Content-Type", "application/json"); |
|
|
|
String info = HttpUtils.sendJsonPost(url, jsonObject, header); |
|
|
|
String info = HttpUtils.sendJsonPost(url, jsonObject, header); |
|
|
|
JSONObject obj = JSONObject.parseObject(info); |
|
|
|
JSONObject obj = JSONObject.parseObject(info); |
|
|
|
Long exprieTime = System.currentTimeMillis(); |
|
|
|
redisCache.setCacheObject(ElephantConstants.TOKEN_REDIS_KEY + "appkey:" + appkey, obj,(int) obj.get("expires_in") - 60, TimeUnit.SECONDS); |
|
|
|
exprieTime = exprieTime + (int) obj.get("expires_in") * 1000L; // 过期时间
|
|
|
|
|
|
|
|
obj.put("exprieTime", exprieTime); |
|
|
|
|
|
|
|
redisCache.setCacheObject(ElephantConstants.TOKEN_REDIS_KEY + "appkey:" + appkey, obj); |
|
|
|
|
|
|
|
return (String) obj.get("access_token"); |
|
|
|
return (String) obj.get("access_token"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String getToken() { |
|
|
|
public static String getToken() { |
|
|
@ -302,11 +300,9 @@ public class ElephantUtils { |
|
|
|
|
|
|
|
|
|
|
|
// 如果不为空,且没有过期
|
|
|
|
// 如果不为空,且没有过期
|
|
|
|
if (temp != null) { |
|
|
|
if (temp != null) { |
|
|
|
Long exprieTimeTemp = (Long) temp.get("exprieTime"); |
|
|
|
|
|
|
|
if (System.currentTimeMillis() < exprieTimeTemp) { |
|
|
|
|
|
|
|
return (String) temp.get("access_token"); |
|
|
|
return (String) temp.get("access_token"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String appkey = configService.selectConfigByKey("elephant_appkey"); |
|
|
|
String appkey = configService.selectConfigByKey("elephant_appkey"); |
|
|
|
if (appkey == null || "".equals(appkey)) { |
|
|
|
if (appkey == null || "".equals(appkey)) { |
|
|
|
throw new JianshuiServiceConfigErrorException("未配置大象app key!"); |
|
|
|
throw new JianshuiServiceConfigErrorException("未配置大象app key!"); |
|
|
@ -329,10 +325,7 @@ public class ElephantUtils { |
|
|
|
header.put("Content-Type", "application/json"); |
|
|
|
header.put("Content-Type", "application/json"); |
|
|
|
String info = HttpUtils.sendJsonPost(url, jsonObject, header); |
|
|
|
String info = HttpUtils.sendJsonPost(url, jsonObject, header); |
|
|
|
JSONObject obj = JSONObject.parseObject(info); |
|
|
|
JSONObject obj = JSONObject.parseObject(info); |
|
|
|
Long exprieTime = System.currentTimeMillis(); |
|
|
|
redisCache.setCacheObject(ElephantConstants.TOKEN_REDIS_KEY, obj,(int) obj.get("expires_in") - 60, TimeUnit.SECONDS); |
|
|
|
exprieTime = exprieTime + (int) obj.get("expires_in") * 1000L; // 过期时间
|
|
|
|
|
|
|
|
obj.put("exprieTime", exprieTime); |
|
|
|
|
|
|
|
redisCache.setCacheObject(ElephantConstants.TOKEN_REDIS_KEY, obj); |
|
|
|
|
|
|
|
return (String) obj.get("access_token"); |
|
|
|
return (String) obj.get("access_token"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|