大象接口token获取问题处理 2023-05-22

beta-prop-all^2
dongxiaoke 2 years ago
parent f5c59530be
commit 0be025910c
  1. 12
      jianshui-income/src/main/java/com/jianshui/income/utils/elephant/ElephantUtils.java
  2. 25
      jianshui-invoice/src/main/java/com/jianshui/invoice/utils/elephant/ElephantUtils.java

@ -41,6 +41,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.codec.binary.Base64;
@ -141,10 +142,11 @@ public class ElephantUtils {
// 如果不为空,且没有过期
if (temp != null) {
Long exprieTimeTemp = (Long) temp.get("exprieTime");
/*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");
if (appkey == null || "".equals(appkey)) {
@ -168,10 +170,10 @@ public class ElephantUtils {
header.put("Content-Type", "application/json");
String info = HttpUtils.sendJsonPost(url, jsonObject, header);
JSONObject obj = JSONObject.parseObject(info);
Long exprieTime = System.currentTimeMillis();
/*Long exprieTime = System.currentTimeMillis();
exprieTime = exprieTime + (int) obj.get("expires_in") * 1000L; // 过期时间
obj.put("exprieTime", exprieTime);
redisCache.setCacheObject(ElephantConstants.TOKEN_REDIS_KEY, obj);
obj.put("exprieTime", exprieTime);*/
redisCache.setCacheObject(ElephantConstants.TOKEN_REDIS_KEY, obj,(int) obj.get("expires_in") - 60, TimeUnit.SECONDS);
return (String) obj.get("access_token");
}

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