Parcourir la source

获取经销商接口tokenBUG修改

qxp il y a 5 ans
Parent
commit
e598f54afc

+ 17 - 2
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/service/AnalysisDiyCustomerComponent.java

@@ -81,7 +81,15 @@ public class AnalysisDiyCustomerComponent {
         long total = 0;
         long success = 0;
         Set<String> loginNameSet = sysUserService.selectAllUserLoginName();
-        String managerJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.MANAGER));
+        String managerJson ="";
+        try{
+            managerJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.MANAGER));
+        }catch (Exception e){
+            log.error("获取经销商经理接口错误!");
+            customerAccessTokenUtil.reSetToken();
+            throw e;
+        }
+
         JSONObject mjson = JSONObject.parseObject(managerJson);
         Map<String,Customers> codeMap = customersMapper.selectCustomerMapByCode();
 
@@ -94,8 +102,15 @@ public class AnalysisDiyCustomerComponent {
 
 
 
+        String guideJson ="";
+        try{
+            guideJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STOREGUIDE));
+        }catch (Exception e){
+            log.error("获取经销商导购接口错误!");
+            customerAccessTokenUtil.reSetToken();
+            throw e;
+        }
 
-        String guideJson = HttpUtils.sendSSLGet(customerAccessTokenUtil.getUrl(UrlType.STOREGUIDE));
         JSONObject gjson = JSONObject.parseObject(guideJson);
         code = gjson.getInteger("code");
         if(code==0){

+ 29 - 7
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/utils/CustomerAccessTokenUtil.java

@@ -63,24 +63,41 @@ public class CustomerAccessTokenUtil {
 
     public String getAccessToken(){
 
-        //token未过期使用缓存的token
-        long currentTiem = new Date().getSeconds();
-        if(accessToken==null||((currentTiem-createTime)>=expires)){
+        JSONObject json;
+        String url;
+
+        try {
+            //token未过期使用缓存的token
+            long currentTiem = new Date().getTime();
+            log.info("线程id{}",Thread.currentThread().getId());
+            log.info("过期时间为{}",this.createTime+this.expires*1000);
+            log.info("当前时间为{}",currentTiem);
+            if(this.accessToken!=null &&(currentTiem-createTime)<(this.expires-10)*1000){
+                log.info("本身的token为{}",this.accessToken);
+                return this.accessToken;
+            }
+
+            log.info("开始通过接口获取经销商数据token:url==>",tokenUrl);
             String res = HttpUtils.sendSSLGet(String.format(tokenUrl,appid,appsecret));
-            JSONObject json = JSONObject.parseObject(res);
+            json = JSONObject.parseObject(res);
+
+            log.info("结果返回==》",json);
             int code = json.getInteger("code");
             if(code==0){
-                createTime = new Date().getSeconds();
+                createTime = new Date().getTime();
                 expires = json.getInteger("expires_in");
                 accessToken=json.getString("access_token");
             }else{
                 accessToken= null;
                 createTime =0;
                 expires = 0;
-                log.error("获取diy经销商接口报错,错误代码:"+code+",信息:"+json.getString("msg"));
+                log.error("获取经销商数据token出错,错误代码:"+code+",信息:"+json.getString("msg"));
                 throw new BusinessException("获取diy经销商接口报错,错误代码:"+code+",信息:"+json.getString("msg"));
             }
-
+        }catch (Exception e){
+            reSetToken();
+            log.error("获取E签宝token错误",e);
+            throw e;
         }
         return accessToken;
 
@@ -100,7 +117,12 @@ public class CustomerAccessTokenUtil {
         }
         return url;
     }
+    public void reSetToken() {
+        log.info("清除经销商token缓存");
+        this.accessToken =null;
+        this.expires = 0;
 
+    }
 
 
 }