diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/client/SystemClient.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/client/SystemClient.java index 5120b7f..f178854 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/client/SystemClient.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/client/SystemClient.java @@ -13,9 +13,15 @@ import org.springframework.cloud.openfeign.SpringQueryMap; import org.springframework.web.bind.annotation.*; import java.util.List; +import org.springframework.context.annotation.Bean; +import org.springframework.beans.factory.annotation.Value; +import feign.RequestInterceptor; +import org.springframework.context.annotation.Configuration; -@FeignClient(name = ServiceNameConstants.SYSTEM_SERVICE - ,fallback = SystemClientFallback.class +@FeignClient( + name = ServiceNameConstants.SYSTEM_SERVICE, + fallback = SystemClientFallback.class, + configuration = SystemClient.FeignConfig.class ) public interface SystemClient { @@ -23,15 +29,14 @@ public interface SystemClient { @ApiOperation("分页查询用户信息") @PostMapping("/v1/sysuser/getPage") BaseResponse> getUserPage( - @ApiParam(value = "对象数据", required = true) @RequestBody SysUserVO sysUserDTO, - @RequestHeader("isFegin") String privateKey + @ApiParam(value = "对象数据", required = true) @RequestBody SysUserVO sysUserDTO ); @ApiOperation("查询用户列表") @GetMapping("/v1/sysuser/list") BaseResponse> getUserlist( - @RequestHeader("isFegin") String privateKey, - @ApiParam(value = "查询对象数据", required = false) @SpringQueryMap SysUser param); + @ApiParam(value = "查询对象数据", required = false) @SpringQueryMap SysUser param + ); // -----------------------组织接口----------------------- @ApiOperation("查询组织信息(当前组织及下级组织列表)") @@ -50,4 +55,36 @@ public interface SystemClient { @GetMapping("/v1/sysorg/queryAll") BaseResponse> queryAll(@SpringQueryMap SysOrg sysOrg); + @Configuration + class FeignConfig { + @Value("${check.tokentime.checkpublicKey}") + private String publicKeyStr; + + @Bean + public RequestInterceptor feignRequestInterceptor() { + return template -> { + try { + String str = "isfegin"; + // 1. Base64 decode public key + byte[] keyBytes = java.util.Base64.getDecoder().decode(publicKeyStr); + java.security.spec.X509EncodedKeySpec keySpec = new java.security.spec.X509EncodedKeySpec(keyBytes); + java.security.KeyFactory keyFactory = java.security.KeyFactory.getInstance("RSA"); + java.security.PublicKey publicKey = keyFactory.generatePublic(keySpec); + + // 2. Encrypt str with public key + javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("RSA"); + cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey); + byte[] encrypted = cipher.doFinal(str.getBytes()); + + // 3. Base64 encode encrypted result + String encoded = java.util.Base64.getEncoder().encodeToString(encrypted); + + template.header("isFegin", encoded); + } catch (Exception e) { + throw new RuntimeException("Failed to encrypt isFegin header", e); + } + }; + } + } + } diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/fallback/SystemClientFallback.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/fallback/SystemClientFallback.java index f51fba7..631d15c 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/fallback/SystemClientFallback.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/base/fallback/SystemClientFallback.java @@ -14,14 +14,18 @@ import java.util.List; @Component public class SystemClientFallback implements SystemClient { - @Override - public BaseResponse> getUserPage(SysUserVO sysUserDTO, String privateKey) { + public BaseResponse> getUserPage(SysUserVO sysUserDTO) { return null; } @Override - public BaseResponse> getUserlist(String privateKey, SysUser param) { + public BaseResponse> getUserlist(SysUser param) { + return null; + } + + @Override + public BaseResponse> getOrgWithChildren(SysOrg sysOrg) { return null; } @@ -39,9 +43,4 @@ public class SystemClientFallback implements SystemClient { public BaseResponse> queryAll(SysOrg sysOrg) { return null; } - - @Override - public BaseResponse> getOrgWithChildren(SysOrg sysOrg) { - return null; - } } \ No newline at end of file