|
@@ -0,0 +1,42 @@
|
|
|
+package com.gis.common.httpclient.interceptor;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.dtflys.forest.http.ForestRequest;
|
|
|
+import com.dtflys.forest.interceptor.Interceptor;
|
|
|
+import com.dtflys.forest.reflection.ForestMethod;
|
|
|
+import com.fdkankan.sign.RsaUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.time.Instant;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Xiewj
|
|
|
+ * @date 2025/7/8
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class SignInterceptor implements Interceptor<JSONObject> {
|
|
|
+
|
|
|
+ @Value("${sign.publicKey}")
|
|
|
+ private String publicKey;
|
|
|
+ @Value("${sign.appId}")
|
|
|
+ private String appid;
|
|
|
+ /**
|
|
|
+ * 该方法在被调用时,并在beforeExecute前被调用
|
|
|
+ * @Param request Forest请求对象
|
|
|
+ * @Param args 方法被调用时传入的参数数组
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
|
|
|
+ log.info("on invoke method sign");
|
|
|
+ JSONObject playload = new JSONObject();
|
|
|
+ long epochSecond = System.currentTimeMillis();
|
|
|
+ playload.put("appId", appid);
|
|
|
+ playload.put("timestamp", epochSecond);
|
|
|
+ request.addHeader("sign", RsaUtils.encipher(playload.toJSONString(), publicKey)); // 添加Header
|
|
|
+ request.addHeader("appid", appid); // 添加Header
|
|
|
+
|
|
|
+ }
|
|
|
+}
|