真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

SpringCloud使用Feign攔截器實現(xiàn)URL過濾和RequestParam加密

一、FeignInterceptor.class攔截器
package 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())) {//根據(jù)URL地址過濾請求
            log.info("請求參數(shù)為:{}", template.queryLine());//?param=123456
            Collection paramList = template.queries().get("param");
            String param = paramList.iterator().next();
            try {
                // 加密
                param = SM4Util.encryptEcb("1234567890", param);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Map> newQueries = new HashMap<>();
            Collection value = new ArrayList<>();
            value.add(param);
            newQueries.put("param", value);
            template.queries(newQueries);// 替換原有對象
            log.info("加密后參數(shù)為:{}", template.queryLine());//?param=xxxxxx
        }
    }
}
二、配置文件

application.yml

長壽網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,長壽網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為長壽超過千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的長壽做網(wǎng)站的公司定做!

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


    4.0.0

    com.xiaohang
    pre-socialcard-changsha
    1.0-SNAPSHOT
    jar

    
        org.springframework.cloud
        spring-cloud-starter-parent
        Camden.SR5
    
    
        UTF-8
        1.8
        UTF-8
    

    
        
            org.springframework.boot
            spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
        
        
            org.springframework.cloud
            spring-cloud-starter-eureka
            1.2.3.RELEASE
        
        
            org.springframework.cloud
            spring-cloud-starter-feign
            1.2.5.RELEASE
        
        
            org.projectlombok
            lombok
            1.16.18
        
        
            com.fasterxml.jackson.core
            jackson-core
            2.9.9
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        org.springframework
                        springloaded
                        1.2.5.RELEASE
                    
                
            
        
    

當(dāng)前題目:SpringCloud使用Feign攔截器實現(xiàn)URL過濾和RequestParam加密
瀏覽地址:http://weahome.cn/article/gsshie.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部