|
@@ -1,10 +1,15 @@
|
|
|
package com.fdkk.bim.Interceptor;
|
|
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.dtflys.forest.exceptions.ForestRuntimeException;
|
|
|
import com.dtflys.forest.http.ForestRequest;
|
|
|
import com.dtflys.forest.http.ForestResponse;
|
|
|
import com.dtflys.forest.interceptor.Interceptor;
|
|
|
import com.dtflys.forest.reflection.ForestMethod;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkk.bim.client.BimFaceClient;
|
|
|
import com.fdkk.bim.config.BimFaceConfig;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -15,8 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public class BimFaceInterceptor<T> implements Interceptor<T> {
|
|
|
- @Autowired
|
|
|
- BimFaceConfig bimFaceConfig;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -27,9 +30,13 @@ public class BimFaceInterceptor<T> implements Interceptor<T> {
|
|
|
@Override
|
|
|
public void onInvokeMethod(ForestRequest req, ForestMethod method, Object[] args) {
|
|
|
log.info("on invoke method");
|
|
|
- if (!method.getMethodName().equals("getToken")){
|
|
|
+ RedisUtil cache = SpringUtil.getBean(RedisUtil.class);
|
|
|
+ if (!method.getMethodName().equals("getToken")&&cache.hasKey("bim:token")){
|
|
|
+ req.addHeader("Authorization", "Bearer "+cache.get("bim:token")); // 添加Header
|
|
|
+ }else if (!method.getMethodName().equals("getToken")){
|
|
|
BimFaceConfig bean = SpringUtil.getBean(BimFaceConfig.class);
|
|
|
- req.addHeader("Authorization", "Bearer "+bean.getAccessToken()); // 添加Header
|
|
|
+ bean.reload();
|
|
|
+ req.addHeader("Authorization", "Bearer "+cache.get("bim:token")); // 添加Header
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -40,5 +47,26 @@ public class BimFaceInterceptor<T> implements Interceptor<T> {
|
|
|
public void onSuccess(T data, ForestRequest req, ForestResponse res) {
|
|
|
log.info("invoke Simple onSuccess {},data:{}",res,data);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 该方法在请求发送失败时被调用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onError(ForestRuntimeException ex, ForestRequest req, ForestResponse res) {
|
|
|
+ log.info("invoke Simple onError {},data:{}",res,req);
|
|
|
+ String content = res.getContent();
|
|
|
+ JSONObject resJSON = JSON.parseObject(content);
|
|
|
+ if (res.getStatusCode()==401&&resJSON.getString("error").equals("invalid_token")){
|
|
|
+ log.info("onError 401 ,retry");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+//
|
|
|
+// // 执行发送请求失败后处理的代码
|
|
|
+// int status = res.getStatusCode(); // 获取请求响应状态码
|
|
|
+// String content = res.getContent(); // 获取请求的响应内容
|
|
|
+// String result = res.getResult(); // 获取方法返回类型对应的返回数据结果
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|