SpringCloud使用Feign拦截器实现URL过滤和RequestParam加密
2020-12-13 05:42
标签:factory lca put print stat mapping jar app int application.yml SpringCloud使用Feign拦截器实现URL过滤和RequestParam加密 标签:factory lca put print stat mapping jar app int 原文地址:https://blog.51cto.com/12012821/2417863package com.xiaohang.socialcard.pre.intercepter;
import com.xiaohang.socialcard.pre.utils.SM4Util;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.*;
@Configuration
@Slf4j
public class FeignInterceptor implements RequestInterceptor {
@Value("${encrypt.urls}")
private String[] urlList;
@Override
public void apply(RequestTemplate template) {
if (Arrays.asList(urlList).contains(template.url())) {//根据URL地址过滤请求
log.info("请求参数为:{}", template.queryLine());//?param=123456
Collection
二、配置文件
changsha-payment.url: http://xx.xx.xx.xx:8080
encrypt.urls: /openInter/getToken,/openInter/dispatchPayEx,/bcs/balance
三、APIFeign接口
package com.xiaohang.socialcard.pre.feign;
import com.xiaohang.socialcard.pre.model.ChangShaResp;
import com.xiaohang.socialcard.pre.pojo.Loffee;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "changsha-payment", url = "${changsha-payment.url}")
public interface ChangShaApi {
@RequestMapping(method = RequestMethod.GET, path = "openInter/getToken", consumes = "*/*", produces = "application/json;charset=UTF-8")
ChangShaResp getToken(@RequestParam(name = "param", required = true) String param);
@RequestMapping(method = RequestMethod.POST, value = "openInter/dispatchPayEx", produces = "text/html", consumes = "application/x-www-form-urlencoded")
String payPage(@RequestParam(name = "param", required = true) String param);
@RequestMapping(method = RequestMethod.POST, path = "/bcs/balance", produces = "text/html", consumes = "application/x-www-form-urlencoded")
String downLoadPay(@RequestParam(name = "param", required = true) String param);
四、启动类Application.class
package com.xiaohang.socialcard.pre;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
@EnableFeignClients
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
五、pom.xml
下一篇:js bug自动预警
文章标题:SpringCloud使用Feign拦截器实现URL过滤和RequestParam加密
文章链接:http://soscw.com/essay/31622.html