Commit 61f4c1ea by yanru

增加拦截器、跨域、页面跳转的配置

parent 9b129b12
package com.founder.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/*
* 跨域访问配置(访问本系统)
*/
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT")
.maxAge(3600);
}
}
...@@ -18,7 +18,7 @@ import java.util.List; ...@@ -18,7 +18,7 @@ import java.util.List;
* @Date 2020/9/318:49 * @Date 2020/9/318:49
*/ */
@Configuration @Configuration
public class DefaultViewConfig implements WebMvcConfigurer { public class WebMvcConfig implements WebMvcConfigurer {
/** /**
* 页面跳转 * 页面跳转
......
package com.founder.util;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
/**
* @Author yanru
* @Date 2020/9/49:55
*/
public class TestUtil {
public static void main(String[] args) {
try {
String secret=HMACSHA256("app_id=XZ15000000&app_key=pSFRNTQQXDJKSjzL&xz_token=2d69c3e2da6e8ecc8e977603&timestamp=1591152151950", "zdejRKFNCUSSAIjbvijEdRFxjnzKAI");
System.out.println(secret);
}catch (Exception e){
e.printStackTrace();
}
}
/**
*HMac-SHA256算法加密
* @param data
* @param key
* @return
* @throws Exception
*/
public static String HMACSHA256(String data, String key) throws Exception {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
StringBuilder sb = new StringBuilder();
for (byte item : array) {
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
}
return sb.toString();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment