diff --git a/code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/AESCBCUtils.java b/code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/AESCBCUtils.java new file mode 100644 index 00000000..aa6c2c73 --- /dev/null +++ b/code/smart-community/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/AESCBCUtils.java @@ -0,0 +1,107 @@ +package com.epmet.commons.tools.utils; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +public class AESCBCUtils { + + public static final Log logger = LogFactory.getLog(AESCBCUtils.class); + public static final String KEY_ALGORITHM = "AES"; + // 加密模式为ECB,填充模式为NoPadding + public static final String CIPHER_ALGORITHM = "AES/CBC/NoPadding"; + // 字符集 + public static final String ENCODING = "UTF-8"; + // 向量 + public static final String IV_SEED = "1234567812345678"; + + /** + * AES加密算法 + * + * @param str 密文 + * @param key 密key + * @return + */ + public static String encrypt(String str, String key) { + try { + if (str == null) { + logger.error("AES加密出错:Key为空null"); + return null; + } + // 判断Key是否为16位 + if (key.length() != 16) { + logger.error("AES加密出错:Key长度不是16位"); + return null; + } + byte[] raw = key.getBytes(ENCODING); + SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_ALGORITHM); + Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); + IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING)); + cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); + byte[] srawt = str.getBytes(ENCODING); + int len = srawt.length; + /* 计算补空格后的长度 */ + while (len % 16 != 0) + len++; + byte[] sraw = new byte[len]; + /* 在最后空格 */ + for (int i = 0; i < len; ++i) { + if (i < srawt.length) { + sraw[i] = srawt[i]; + } else { + sraw[i] = 32; + } + } + byte[] encrypted = cipher.doFinal(sraw); + return formatString(new String(Base64.encodeBase64(encrypted), "UTF-8")); + } catch (Exception ex) { + logger.error("AES加密出错:" + ex.toString()); + return null; + } + } + + /** + * AES解密算法 + * + * @param str 密文 + * @param key 密key + * @return + */ + public static String decrypt(String str, String key) { + try { + // 判断Key是否正确 + if (key == null) { + logger.error("AES解密出错:Key为空null"); + return null; + } + // 判断Key是否为16位 + if (key.length() != 16) { + logger.error("AES解密出错:Key长度不是16位"); + return null; + } + byte[] raw = key.getBytes(ENCODING); + SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_ALGORITHM); + Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); + IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING)); + cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); + byte[] bytes = Base64.decodeBase64(str.getBytes("UTF-8")); + bytes = cipher.doFinal(bytes); + return new String(bytes, ENCODING); + } catch (Exception ex) { + logger.error("AES解密出错:" + ex.toString()); + return null; + } + } + + private static String formatString(String sourceStr) { + if (sourceStr == null) { + return null; + } + return sourceStr.replaceAll("\\r", "").replaceAll("\\n", ""); + } + +} \ No newline at end of file diff --git a/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/from/MyResiUserInfoFormDTO.java b/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/from/MyResiUserInfoFormDTO.java index edcde03d..cf3fd3c9 100644 --- a/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/from/MyResiUserInfoFormDTO.java +++ b/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/from/MyResiUserInfoFormDTO.java @@ -16,7 +16,7 @@ public class MyResiUserInfoFormDTO implements Serializable { private static final long serialVersionUID = -6534841370041338474L; @NotBlank(message = "客户Id不能为空") private String customerId; - @NotBlank(message = "网格Id不能为空") +// @NotBlank(message = "网格Id不能为空") private String gridId; @NotBlank(message = "用户Id不能为空") private String userId; diff --git a/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/result/MyResiUserInfoResultDTO.java b/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/result/MyResiUserInfoResultDTO.java index 3f3cbe0f..0ef2dcd8 100644 --- a/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/result/MyResiUserInfoResultDTO.java +++ b/code/smart-community/epmet-module/resi-mine/resi-mine-client/src/main/java/com/epmet/resi/mine/dto/result/MyResiUserInfoResultDTO.java @@ -18,6 +18,11 @@ public class MyResiUserInfoResultDTO implements Serializable { * 用户id * */ private String userId; + + /** + * 居民所属网格ID + */ + private String gridId; /** * 是否已注册居民,true ,false * */ diff --git a/code/smart-community/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/MineController.java b/code/smart-community/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/MineController.java index 21668669..83f16e54 100644 --- a/code/smart-community/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/MineController.java +++ b/code/smart-community/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/MineController.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; import java.util.Date; /** @@ -38,7 +39,7 @@ import java.util.Date; @RequestMapping("mine") public class MineController { - @Autowired + @Resource private EpmetUserFeignClient epmetUserFeignClient; @Autowired private RedisUtils redisUtils; @@ -54,6 +55,7 @@ public class MineController { Result getMyResiInfo(@LoginUser TokenDto tokenDto, @RequestBody MyResiUserInfoFormDTO myResiUserInfoFormDTO) { myResiUserInfoFormDTO.setUserId(tokenDto.getUserId()); ValidatorUtils.validateEntity(myResiUserInfoFormDTO); + return epmetUserFeignClient.resiMyselfMsg(myResiUserInfoFormDTO); } diff --git a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/MyResiUserInfoFormDTO.java b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/MyResiUserInfoFormDTO.java index 722b93ed..719b7fc3 100644 --- a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/MyResiUserInfoFormDTO.java +++ b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/MyResiUserInfoFormDTO.java @@ -16,7 +16,7 @@ public class MyResiUserInfoFormDTO implements Serializable { private static final long serialVersionUID = -6534841370041338474L; @NotBlank(message = "客户Id不能为空") private String customerId; - @NotBlank(message = "网格Id不能为空") +// @NotBlank(message = "网格Id不能为空") private String gridId; @NotBlank(message = "用户Id不能为空") private String userId; diff --git a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/MyResiUserInfoResultDTO.java b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/MyResiUserInfoResultDTO.java index 9ab4663b..00a8fb54 100644 --- a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/MyResiUserInfoResultDTO.java +++ b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/MyResiUserInfoResultDTO.java @@ -18,6 +18,11 @@ public class MyResiUserInfoResultDTO implements Serializable { * 用户id * */ private String userId; + + /** + * 居民所属网格ID + */ + private String gridId; /** * 是否已注册居民,true ,false * */ diff --git a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RizhaoBankUserInfoResultDTO.java b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RizhaoBankUserInfoResultDTO.java new file mode 100644 index 00000000..484def9a --- /dev/null +++ b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RizhaoBankUserInfoResultDTO.java @@ -0,0 +1,31 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class RizhaoBankUserInfoResultDTO implements Serializable { + + /** + * 用户id + */ + private String userId; + + /** + * 手机号(注册手机号) + */ + private String mobile; + + + /** + * 身份证号 + */ + private String idNum; + + /** + * 姓名 + */ + private String name; + +} diff --git a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index ddc7a635..6c2d14b3 100644 --- a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -325,6 +325,9 @@ public interface EpmetUserOpenFeignClient { @PostMapping("/epmetuser/userbaseinfo/extuserinfo") Result extUserInfo( @RequestBody CommonUserIdFormDTO param); + @PostMapping("/epmetuser/rizhaobank/userinfo") + Result rizhaoBankUserInfo(@RequestBody TokenDto tokenDTO); + /** * 更改角色所属组织 * @author zhaoqifeng diff --git a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java index 3bba7ced..85cbeefc 100644 --- a/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java +++ b/code/smart-community/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java @@ -218,6 +218,12 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "extUserInfo", param); } + @Override + public Result rizhaoBankUserInfo(@RequestBody TokenDto tokenDTO) { + + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getUserInfo", tokenDTO); + } + @Override public Result changeRoleOrg(StaffRoleDTO formDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "changeRoleOrg", formDTO); diff --git a/code/smart-community/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/RizhaoBankController.java b/code/smart-community/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/RizhaoBankController.java new file mode 100644 index 00000000..f991c813 --- /dev/null +++ b/code/smart-community/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/RizhaoBankController.java @@ -0,0 +1,53 @@ +package com.epmet.controller; + +import cn.hutool.json.JSONUtil; +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.redis.common.bean.ResiUserInfoCache; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.AESCBCUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.result.RizhaoBankUserInfoResultDTO; +import com.epmet.service.UserBaseInfoService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +@RequestMapping("/rizhaobank") +public class RizhaoBankController { + + @Value("${rizhaobank.aesKey}") + private String AES_KEY; + + @Resource + private UserBaseInfoService userBaseInfoService; + + @PostMapping("/userinfo") + public Result getUserInfo(@LoginUser TokenDto tokenDto) { + + ResiUserInfoCache userInfo = userBaseInfoService.getUserInfo(tokenDto.getUserId()); + + if(userInfo != null) { + RizhaoBankUserInfoResultDTO userInfoResultDTO = new RizhaoBankUserInfoResultDTO(); + + userInfoResultDTO.setUserId(userInfo.getUserId()); + userInfoResultDTO.setMobile(userInfo.getMobile()); + userInfoResultDTO.setIdNum(userInfo.getIdNum()); + userInfoResultDTO.setName(userInfo.getRealName()); + + String encryptStr = AESCBCUtils.encrypt(JSONUtil.toJsonStr(userInfoResultDTO), AES_KEY); + +// System.out.println("encrypt:\n"+encryptStr); +// +// System.out.println("decrypt:\n"+AESCBCUtils.decrypt(encryptStr, AES_KEY)); + + return new Result().ok(encryptStr); + } else { + return new Result().error(1001, "获取用户信息失败"); + } + } + +} diff --git a/code/smart-community/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java b/code/smart-community/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java index 9138496b..aee7ad0a 100644 --- a/code/smart-community/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java +++ b/code/smart-community/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java @@ -278,6 +278,7 @@ public class UserResiInfoServiceImpl extends BaseServiceImpl implem if (null != myselfMsg) { MyResiUserInfoResultDTO result = ConvertUtils.sourceToTarget(myselfMsg, MyResiUserInfoResultDTO.class); + RegisterRelationEntity registerRelation = registerRelationDao.selectRegisteredGridIdByUserId(myResiUserInfoFormDTO.getUserId()); + if (null != registerRelation) { + result.setGridId(registerRelation.getGridId()); + } //registerFlag 是否已注册居民,true ,false result.setRegisterFlag(StringUtils.isNotBlank(myselfMsg.getResiId())); if(StringUtils.isNotBlank(myselfMsg.getIdNum()) && StringUtils.isNotBlank(myselfMsg.getResiId())){