|
@@ -0,0 +1,49 @@
|
|
|
|
+package com.ruoyi.framework.interceptor;
|
|
|
|
+
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.web.method.HandlerMethod;
|
|
|
|
+import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * WMS接口拦截器
|
|
|
|
+ */
|
|
|
|
+@Component
|
|
|
|
+public class SignInterceptor implements HandlerInterceptor {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
|
+
|
|
|
|
+ if (handler instanceof HandlerMethod)
|
|
|
|
+ {
|
|
|
|
+ System.out.println("请求头======>"+request);
|
|
|
|
+ String appKey = request.getHeader("appKey");
|
|
|
|
+ String timestamp = request.getHeader("timestamp");
|
|
|
|
+ String uri = request.getHeader("uri");
|
|
|
|
+ String sign = request.getHeader("sign");
|
|
|
|
+
|
|
|
|
+ String mdUrl = "appKey="+appKey+"×tamp="+timestamp+"&uri="+uri+"&appSecret=irf6DdRkEdR6whj4";
|
|
|
|
+ System.out.println("MD5加密======>"+mdUrl);
|
|
|
|
+ String md5Upper = this.encrypt3ToMD5(mdUrl);
|
|
|
|
+ System.out.println("加密后======>"+md5Upper);
|
|
|
|
+ if (md5Upper.equals(sign)){
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * MD5加密
|
|
|
|
+ * @explain springboot自带MD5加密
|
|
|
|
+ * @param str
|
|
|
|
+ */
|
|
|
|
+ public String encrypt3ToMD5(String str) {
|
|
|
|
+ String md5Upper = DigestUtils.md5DigestAsHex(str.getBytes(StandardCharsets.UTF_8));
|
|
|
|
+ md5Upper = md5Upper.toUpperCase();
|
|
|
|
+ return md5Upper;
|
|
|
|
+ }
|
|
|
|
+}
|