Browse Source

fix:token有效期获取问题

lileilei 2 years ago
parent
commit
db94f29ea4

+ 4 - 3
src/main/java/com/yixin/ms/server/JiliangUniversityServer.java

@@ -43,11 +43,11 @@ public class JiliangUniversityServer {
     private String canPassUrl;
 
     /**
-     * 请求密钥有效时间为 一天
+     * 请求密钥有效时间为 一天 12H
      *
      * @see <a href="https://www.hutool.cn/docs/#/cache/TimedCache">定时缓存</a>
      */
-    private static TimedCache<String, String> tokenCache = CacheUtil.newTimedCache(24 * 60 * 60 * 1000);
+    private static TimedCache<String, String> tokenCache = CacheUtil.newTimedCache(12 * 60 * 60 * 1000);
 
     /**
      * 获取accesskey(有效期一天)
@@ -65,11 +65,11 @@ public class JiliangUniversityServer {
         HealthResultVO resultVO = null;
         try {
             String body = HttpUtil.post(getTokenUrl, paramMap);
+            log.info("计量大学开放平台获取token响应内容:{}", body);
             resultVO = JSON.parseObject(body, HealthResultVO.class);
             if (resultVO.getCode().equals(Integer.valueOf(RestCode.SUCCESS.getCode()))) {
                 tokenCache.put(TOKEN, resultVO.getData().toString());
             }
-            log.info("计量大学开放平台获取token响应内容:{}", body);
         }catch (Exception e){
             throw new ServiceException("学校开放接口服务异常,请联系工作人员");
         }
@@ -88,6 +88,7 @@ public class JiliangUniversityServer {
         HealthResultVO<JiliangCanPassVO> resultVO = null;
         try {
             String body = HttpUtil.createPost(canPassUrl).addHeaders(headers).body(JSON.toJSONString(new JiliangCanPassDTO().setData(dto))).execute().body();
+            log.info("计量大学开放平台获取通过结果响应内容:{}", body);
             resultVO = JSON.parseObject(body, HealthResultVO.class);
             if (resultVO.getCode().equals(Integer.valueOf(RestCode.SUCCESS.getCode()))) {
                 resultVO.setData(JSON.parseObject(JSON.toJSONString(resultVO.getData()), JiliangCanPassVO.class));

+ 1 - 1
src/main/java/com/yixin/ms/service/impl/HealthCodeServiceImpl.java

@@ -102,7 +102,7 @@ public class HealthCodeServiceImpl implements HealthCodeService {
 
         String canPass = jiliangUniversityServer.canPass(new JiliangCanPassDataDTO().setIdCard(shortTermDTO.getIdNumber()).setOpTime(DateUtil.date()).setSn(shortTermDTO.getSn()));
         if(canPass.equals(CanPassEnum.NOT_THROUGH.getCode())){
-            throw new ServiceException("暂无通行权限,请联系工作人员");
+            return RestResponse.error("暂无通行权限,请联系工作人员");
         }
 
         /**