|
@@ -0,0 +1,36 @@
|
|
|
+package com.fdkankan.tk.httpClient;
|
|
|
+
|
|
|
+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.agent.config.AgentConfig;
|
|
|
+import com.fdkankan.sign.RsaUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.time.Instant;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class SignInterceptor implements Interceptor<JSONObject> {
|
|
|
+
|
|
|
+ @Value("${takelook.publicKey}")
|
|
|
+ public String publicKey;
|
|
|
+ @Value("${takelook.appid}")
|
|
|
+ public String appid;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
|
|
|
+ JSONObject playload = new JSONObject();
|
|
|
+ Instant now = Instant.now();
|
|
|
+ long epochSecond = now.getEpochSecond();
|
|
|
+ playload.put("appId",appid);
|
|
|
+ playload.put("timestamp", epochSecond);
|
|
|
+ request.addHeader("appId",appid);
|
|
|
+ request.addHeader("sign", RsaUtils.encipher(playload.toJSONString(), publicKey));
|
|
|
+
|
|
|
+ }
|
|
|
+}
|