Просмотр исходного кода

互联互通对接调试:优化

skyline 1 год назад
Родитель
Сommit
ec1c5a1a65

+ 2 - 2
common/src/main/java/com/kym/common/constant/ResponseEnum.java

@@ -51,10 +51,10 @@ public enum ResponseEnum implements BusinessExceptionAssert {
 
 
     // 互联互通平台
-    PLATFORM__API_EXCEPTION(90000, "接口数据异常"),
+    PLATFORM_API_EXCEPTION(90000, "接口数据异常"),
     PLATFORM_QUERY_TOKEN_ERROR(90001, "TOKEN获取异常"),
     PLATFORM_PUSH_SIGN_FAIL(90002, "推送数据验签失败"),
-    PLATFORM_TOKEN_EXCEPTION(90003, "EN+TOKEN过期");
+    PLATFORM_QUERY_TOKEN_EXCEPTION(90003, "EN+TOKEN过期");
 
     private final Integer code;
     private final String message;

+ 0 - 11
common/src/main/java/com/kym/common/wxpay/WxJsApi.java

@@ -1,11 +0,0 @@
-package com.kym.common.wxpay;
-
-/**
- * @author skyline
- * @description JSAPI下单
- * @date 2023-08-10 14:01
- */
-public class WxJsApi {
-
-
-}

+ 5 - 1
entity/src/main/java/com/kym/entity/common/RedisKeys.java

@@ -6,7 +6,11 @@ package com.kym.entity.common;
  * @date 2023-07-31 18:26
  */
 public interface RedisKeys {
-    String EN_PLUS_TOKEN = "EN_PLUS_TOKEN:";
+    String PLATFORM_QUERY_TOKEN = "PLATFORM_QUERY_TOKEN:";
+
+    /**
+     * 我们自己平台生成的Token,给外部调用获取
+     */
     String PLATFORM_TOKEN = "PLATFORM_TOKEN:";
     String EN_PLUS_SASS_TOKEN = "EN_PLUS_SASS_TOKEN";
     String OFFLINE = "OFFLINE:";

+ 1 - 1
miniapp/src/main/java/com/kym/miniapp/jobs/StartChargeDelayJob.java

@@ -101,7 +101,7 @@ public class StartChargeDelayJob implements DelayService<DelayChargeOrder> {
                         log.error("预约充电队列take异常", e);
                     } else {
                         log.info("预约启动充电失败,订单号:{}", threadLocal.get());
-                        if (e instanceof BusinessException && (ResponseEnum.PLATFORM_TOKEN_EXCEPTION.getCode().equals(((BusinessException) e).getCode()))) {
+                        if (e instanceof BusinessException && (ResponseEnum.PLATFORM_QUERY_TOKEN_EXCEPTION.getCode().equals(((BusinessException) e).getCode()))) {
                             if (retryList.contains(threadLocal.get())) {
                                 log.info("EN+ token异常,预约订单:{}已重试忽略", threadLocal.get());
                                 log.error(e.getMessage());

+ 8 - 14
service/src/main/java/com/kym/service/platform/impl/PlatformApiServiceImpl.java

@@ -1,24 +1,19 @@
 package com.kym.service.platform.impl;
 
-import cn.hutool.core.date.DatePattern;
-import cn.hutool.core.date.LocalDateTimeUtil;
-import cn.hutool.crypto.digest.HMac;
-import cn.hutool.crypto.digest.HmacAlgorithm;
 import com.alibaba.fastjson2.JSONObject;
 import com.kym.common.annotation.ConnectorID;
 import com.kym.common.annotation.DynamicCache;
 import com.kym.common.annotation.PlatformConvert;
 import com.kym.common.annotation.PlatformName;
+import com.kym.common.cache.PlatformCache;
 import com.kym.common.constant.ResponseEnum;
 import com.kym.common.exception.BusinessException;
-import com.kym.common.exception.PlatformPushException;
 import com.kym.common.utils.CommUtil;
 import com.kym.common.utils.PlatformAesUtil;
 import com.kym.common.utils.PlatformConvertUtil;
 import com.kym.entity.common.RedisKeys;
 import com.kym.entity.platform.PlatformRespQueryToken;
 import com.kym.entity.platform.response.PlatformResponse;
-import com.kym.common.cache.PlatformCache;
 import com.kym.service.platform.PlatformApi;
 import com.kym.service.platform.PlatformApiService;
 import lombok.extern.slf4j.Slf4j;
@@ -27,7 +22,6 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
-import java.time.LocalDateTime;
 import java.util.concurrent.TimeUnit;
 
 import static com.kym.common.utils.PlatformAesUtil.buildPlatformParams;
@@ -88,10 +82,10 @@ public class PlatformApiServiceImpl implements PlatformApiService {
             log.error(":url:{}, params:{},token:{},返回信息:{}", url, params, token, response);
             if (4002 == response.getRet()) {
                 // 如果返回Ret=4002,token错误的情况下,删除redis中的token,如果是预约订单则将此订单设置为延迟启动
-                redisTemplate.delete(RedisKeys.EN_PLUS_TOKEN + platformName);
-                throw new BusinessException(ResponseEnum.PLATFORM_TOKEN_EXCEPTION);
+                redisTemplate.delete(RedisKeys.PLATFORM_QUERY_TOKEN + platformName);
+                throw new BusinessException(ResponseEnum.PLATFORM_QUERY_TOKEN_EXCEPTION);
             }
-            throw new BusinessException(ResponseEnum.PLATFORM__API_EXCEPTION);
+            throw new BusinessException(ResponseEnum.PLATFORM_API_EXCEPTION);
         }
     }
 
@@ -117,10 +111,10 @@ public class PlatformApiServiceImpl implements PlatformApiService {
     @Override
     public String queryPlatformToken(String platformName) {
         log.info("查询互联互通平台{}token", platformName);
-        var token = redisTemplate.opsForValue().get(RedisKeys.EN_PLUS_TOKEN + platformName);
+        var token = redisTemplate.opsForValue().get(RedisKeys.PLATFORM_QUERY_TOKEN + platformName);
         if (CommUtil.isNotEmptyAndNull(token)) {
             // 不同平台不同key
-            log.debug("从缓存中查询到token:{},ttl:{}", token, redisTemplate.getExpire(RedisKeys.EN_PLUS_TOKEN + platformName));
+            log.debug("从缓存中查询到token:{},ttl:{}", token, redisTemplate.getExpire(RedisKeys.PLATFORM_QUERY_TOKEN + platformName));
             return token;
         }
         var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
@@ -141,7 +135,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
             var platformRespQueryToken = parse(jsonObject.toJSONString(), PlatformRespQueryToken.class);
             log.debug("{}接口AccessToken:{}", platformName, platformRespQueryToken.toString());
             // 缓存token不同平台不同key,有效期7天(我们这里每次请求en+获取token的有效期并不是从7天开始,有效期是在en+的剩余有效时间)
-            redisTemplate.opsForValue().set(RedisKeys.EN_PLUS_TOKEN + platformName,
+            redisTemplate.opsForValue().set(RedisKeys.PLATFORM_QUERY_TOKEN + platformName,
                     platformRespQueryToken.getAccessToken(), platformRespQueryToken.getTokenAvailableTime(), TimeUnit.SECONDS);
             return platformRespQueryToken.getAccessToken();
         } else {
@@ -164,7 +158,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
             return response;
         } else {
             log.error("互联互通接口数据异常:url:{}, params:{},返回信息:{}", url, params, response);
-            throw new BusinessException(ResponseEnum.PLATFORM__API_EXCEPTION);
+            throw new BusinessException(ResponseEnum.PLATFORM_API_EXCEPTION);
         }
     }