//package com.huimv.gateway.filter;
//
//
//import com.huimv.common.utils.Constant;
//import com.huimv.gateway.utils.JdkSignatureUtil;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.net.URLDecoder;
//import java.util.Comparator;
//import java.util.Map;
//
///**
// * @Author yinhao
// * @Date 2021/5/6 9:26
// * @Description
// */
//
//@Slf4j
//@Component
//public class  SignVerifyFilter implements GlobalFilter, Ordered {
//
////    @Value("${huimv.public-key}")
////    private
////    String PUBLIC_KEY;
//
//    @SneakyThrows
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//
//        ServerHttpResponse response = exchange.getResponse();
//
//        Map<String,Object> requestBody = exchange.getAttribute("cachedRequestBodyObject");
//        if (requestBody != null) {
//            String sign = (String) requestBody.remove("sign");
//            String decodeSign = URLDecoder.decode(sign, "UTF-8");
//            StringBuilder sb = new StringBuilder();
//            requestBody.entrySet().forEach(entry ->
//                    sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&")
//            );
//            String paramStr = sb.toString().substring(0, sb.length() - 1);
//            boolean result = JdkSignatureUtil.verifySignature(Constant.RSA_SIGN_PUBLIC_KEY, decodeSign, paramStr);
//            if (!result) {
//                response.setStatusCode(HttpStatus.FORBIDDEN);
//                return response.setComplete();
//            }
//        }
//        return chain.filter(exchange);
//
//    }
//
//    @Override
//    public int getOrder() {
//        return 1;
//    }
//}
