| | |
| | | import com.xiaopeng.gateway.config.properties.SignProperties; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
| | | import org.springframework.cloud.gateway.filter.GlobalFilter; |
| | |
| | | import org.springframework.http.server.reactive.ServerHttpRequestDecorator; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.server.ServerWebExchange; |
| | | import org.springframework.web.server.WebSession; |
| | | import org.springframework.web.server.session.WebSessionManager; |
| | | import reactor.core.publisher.Flux; |
| | | import reactor.core.publisher.Mono; |
| | | |
| | |
| | | byte[] bytes = new byte[dataBuffer.readableByteCount()]; |
| | | dataBuffer.read(bytes); |
| | | String bodyString = new String(bytes, StandardCharsets.UTF_8); |
| | | log.info("请求参数:{}", bodyString); |
| | | if(!authSign(JSON.parseObject(bodyString), sign, nonce, timestamp)){ |
| | | return unauthorizedResponse(exchange, "请求失败,请稍后重试!"); |
| | | } |
| | |
| | | signUrl = sb.substring(0, sb.length() - 1); |
| | | } |
| | | signUrl = signUrl + (StringUtils.isNotEmpty(signUrl) ? "&" : "") + "timestamp=" + timestamp; |
| | | log.info("签名串:" + signUrl); |
| | | return signUrlEncode(signUrl, key); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | private boolean authSign(JSONObject jsonStr, String sign, String nonce, String timestamp) { |
| | | log.info("请求签名:" + sign); |
| | | String signUrlEncode = localSignUrl(jsonStr, nonce, timestamp); |
| | | signUrlEncode = signUrlEncode.replaceAll("& #40;", "\\(") |
| | | .replaceAll("& #41;", "\\)"); |
| | | log.info("签名key:{}", nonce); |
| | | log.info("校验签名值:" + signUrlEncode); |
| | | if (sign.equals(signUrlEncode)) { |
| | | return true; |
| | | } |
| | |
| | | { |
| | | return -200; |
| | | } |
| | | } |
| | | } |