From 92c6dd80d6c26b5a0784d20dcf2c2a6031aec53b Mon Sep 17 00:00:00 2001 From: yinzuomei <57602893@qq.com> Date: Sun, 15 Mar 2020 01:26:44 +0800 Subject: [PATCH] =?UTF-8?q?loginbywxcode=E5=BE=AE=E4=BF=A1=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-auth/pom.xml | 52 ++++- .../com/epmet/controller/LoginController.java | 51 +++++ .../java/com/epmet/dao/CustomerUserDao.java | 41 ++++ .../com/epmet/entity/CustomerUserEntity.java | 91 +++++++++ .../com/epmet/jwt/JwtTokenProperties.java | 41 ++++ .../java/com/epmet/jwt/JwtTokenUtils.java | 105 ++++++++++ .../java/com/epmet/service/LoginService.java | 31 +++ .../epmet/service/impl/LoginServiceImpl.java | 193 ++++++++++++++++++ epmet-auth/src/main/resources/bootstrap.yml | 38 +++- .../main/resources/mapper/CustomerUserDao.xml | 15 ++ .../common/token/constant/LoginConstant.java | 33 +++ .../common/token/dto/DeptDataScopeDTO.java | 32 --- .../com/epmet/common/token/dto/TokenDto.java | 75 ++++--- .../token/dto/WorkUserAuthorizationDTO.java | 48 ----- .../common/token/dto/WorkUserLoginDTO.java | 29 --- .../token/dto/WorkUserTokenFormDTO.java | 25 --- .../dto/form/LoginByPassWordFormDTO.java | 29 +++ .../token/dto/form/LoginByWxCodeFormDTO.java | 34 +++ .../token/dto/form/LoginCommonFormDTO.java | 28 +++ .../token/dto/result/UserTokenResultDTO.java | 20 ++ .../common/token/util/CpUserDetailRedis.java | 114 +++++------ .../epmet/common/token/util/TokenUtil.java | 18 +- .../com/epmet/common/token/util/UserUtil.java | 2 +- .../com/epmet/utils/WxMaServiceUtils.java | 10 +- .../commons/tools/constant/Constant.java | 4 - .../epmet/commons/tools/redis/RedisKeys.java | 188 ++++++++--------- 26 files changed, 999 insertions(+), 348 deletions(-) create mode 100644 epmet-auth/src/main/java/com/epmet/controller/LoginController.java create mode 100644 epmet-auth/src/main/java/com/epmet/dao/CustomerUserDao.java create mode 100644 epmet-auth/src/main/java/com/epmet/entity/CustomerUserEntity.java create mode 100644 epmet-auth/src/main/java/com/epmet/jwt/JwtTokenProperties.java create mode 100644 epmet-auth/src/main/java/com/epmet/jwt/JwtTokenUtils.java create mode 100644 epmet-auth/src/main/java/com/epmet/service/LoginService.java create mode 100644 epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java create mode 100644 epmet-auth/src/main/resources/mapper/CustomerUserDao.xml create mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/constant/LoginConstant.java delete mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/DeptDataScopeDTO.java delete mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserAuthorizationDTO.java delete mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserLoginDTO.java delete mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserTokenFormDTO.java create mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java create mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java create mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java create mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index ed67039a6c..3d6c2500ae 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -57,6 +57,29 @@ kaptcha ${kaptcha.version} + + com.epmet + epmet-common-clienttoken + 2.0.0 + + + com.github.binarywang + weixin-java-miniapp + 3.6.0 + compile + + + com.epmet + epmet-commons-tools-wx-ma + 1.0.0 + compile + + + com.epmet + epmet-commons-mybatis + 2.0.0 + compile + @@ -92,6 +115,12 @@ 8081 dev + + + + + epmet + elink@833066 0 122.152.200.70 @@ -107,13 +136,13 @@ - wx3ef8f2cd12a19fcb - 948aa2f21dbaa3943288ea5b119ac6f2 + wx67fdf7da3fee1890 + ae15094f485af9e5c6b5a8a55945332a 111 111 - wxdd8530c5f4926766 - 5bf4fb813145431b3493a10aa7e041e9 + wx7c95937fa16a58c4 + 5782d372d99820fb4859d6be8e5230b0 @@ -126,6 +155,12 @@ 8081 test + + + + + epmet + elink@833066 0 122.152.200.70 @@ -139,6 +174,15 @@ false + + + wx67fdf7da3fee1890 + ae15094f485af9e5c6b5a8a55945332a + 111 + 111 + + wx7c95937fa16a58c4 + 5782d372d99820fb4859d6be8e5230b0 diff --git a/epmet-auth/src/main/java/com/epmet/controller/LoginController.java b/epmet-auth/src/main/java/com/epmet/controller/LoginController.java new file mode 100644 index 0000000000..147206dd0a --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/controller/LoginController.java @@ -0,0 +1,51 @@ +package com.epmet.controller; + +import com.epmet.common.token.annotation.Login; +import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; +import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; +import com.epmet.common.token.dto.result.UserTokenResultDTO; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.service.LoginService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * @Description 通用登陆接口 + * @Author yinzuomei + * @Date 2020/3/14 13:58 + */ +@RestController +@RequestMapping("login") +public class LoginController { + @Autowired + private LoginService loginService; + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 微信小程序登录 + * @Date 2020/3/14 14:35 + **/ + @PostMapping("loginbywxcode") + public Result loginByWxCode(@RequestBody LoginByWxCodeFormDTO formDTO) { + //效验数据 + ValidatorUtils.validateEntity(formDTO); + return loginService.loginByWxCode(formDTO); + } + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机号+密码登录接口 + * @Date 2020/3/14 19:46 + **/ + @PostMapping("loginbypassword") + public Result loginByPassword(@RequestBody LoginByPassWordFormDTO formDTO) { + //效验数据 + ValidatorUtils.validateEntity(formDTO); + return loginService.loginByPassword(formDTO); + } +} diff --git a/epmet-auth/src/main/java/com/epmet/dao/CustomerUserDao.java b/epmet-auth/src/main/java/com/epmet/dao/CustomerUserDao.java new file mode 100644 index 0000000000..5e2b1956dc --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/dao/CustomerUserDao.java @@ -0,0 +1,41 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.CustomerUserEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 客户用户信息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-03-14 + */ +@Mapper +public interface CustomerUserDao extends BaseDao { + + /** + * @param openId + * @return userId + * @Author yinzuomei + * @Description 根据openId查询居民用户信息 + * @Date 2020/3/14 20:45 + **/ + String selectByWxOpenId(String openId); +} diff --git a/epmet-auth/src/main/java/com/epmet/entity/CustomerUserEntity.java b/epmet-auth/src/main/java/com/epmet/entity/CustomerUserEntity.java new file mode 100644 index 0000000000..99affa17fb --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/entity/CustomerUserEntity.java @@ -0,0 +1,91 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 客户用户信息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-03-14 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("customer_user") +public class CustomerUserEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户Id CUSTOMER.id + */ + private String customerId; + + /** + * 微信openId + */ + private String wxOpenId; + + /** + * 手机号 + */ + private String mobile; + + /** + * 昵称 + */ + private String nickname; + + /** + * 性别:0.男 1.女 字典表(key:sex) + */ + private Integer sex; + + /** + * 头像 + */ + private String headImgUrl; + + /** + * 国家 + */ + private String country; + + /** + * 省份 + */ + private String province; + + /** + * 城市 + */ + private String city; + + /** + * 语言 + */ + private String language; + +} diff --git a/epmet-auth/src/main/java/com/epmet/jwt/JwtTokenProperties.java b/epmet-auth/src/main/java/com/epmet/jwt/JwtTokenProperties.java new file mode 100644 index 0000000000..ddff4febcc --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/jwt/JwtTokenProperties.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.epmet.jwt; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * Jwt + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Configuration +@ConfigurationProperties(prefix = "jwt.token") +public class JwtTokenProperties { + private String secret; + private int expire; + + public String getSecret() { + return secret; + } + + public void setSecret(String secret) { + this.secret = secret; + } + + public int getExpire() { + return expire; + } + + public void setExpire(int expire) { + this.expire = expire; + } +} diff --git a/epmet-auth/src/main/java/com/epmet/jwt/JwtTokenUtils.java b/epmet-auth/src/main/java/com/epmet/jwt/JwtTokenUtils.java new file mode 100644 index 0000000000..25e6308add --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/jwt/JwtTokenUtils.java @@ -0,0 +1,105 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.epmet.jwt; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import org.apache.commons.codec.binary.Base64; +import org.joda.time.DateTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * Jwt工具类 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Component +public class JwtTokenUtils { + private static final Logger logger = LoggerFactory.getLogger(JwtTokenUtils.class); + + @Autowired + private JwtTokenProperties jwtProperties; + + /** + * 生成jwt token 弃用 + */ + @Deprecated + public String generateToken(String userId) { + return Jwts.builder() + .setHeaderParam("typ", "JWT") + .setSubject(userId) + .setIssuedAt(new Date()) + .setExpiration(DateTime.now().plusSeconds(jwtProperties.getExpire()).toDate()) + .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecret()) + .compact(); + } + + public Claims getClaimByToken(String token) { + try { + return Jwts.parser() + .setSigningKey(jwtProperties.getSecret()) + .parseClaimsJws(token) + .getBody(); + } catch (Exception e) { + logger.debug("validate is token error, token = " + token, e); + return null; + } + } + public String createToken(Map map) { + return Jwts.builder() + .setHeaderParam("typ", "JWT") + .setClaims(map) + .setIssuedAt(new Date()) + .setExpiration(DateTime.now().plusSeconds(jwtProperties.getExpire()).toDate()) + .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecret()) + .compact(); + } + + /** + * token是否过期 + * + * @return true:过期 + */ + public boolean isTokenExpired(Date expiration) { + return expiration.before(new Date()); + } + + public static void main(String[] args) { + Map map=new HashMap<>(); + map.put("app","gov"); + map.put("client","wxmp"); + map.put("userId","100526ABC"); + String tokenStr=Jwts.builder() + .setHeaderParam("typ", "JWT") + .setClaims(map) + .setIssuedAt(new Date()) + .setExpiration(DateTime.now().plusSeconds(604800).toDate()) + .signWith(SignatureAlgorithm.HS512, "7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet]") + .compact(); + System.out.println(tokenStr); + Claims claims= Jwts.parser() + .setSigningKey("7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet]") + .parseClaimsJws(tokenStr) + .getBody(); + System.out.println("app="+ claims.get("app")); + System.out.println("client="+ claims.get("client")); + System.out.println("userId="+ claims.get("userId")); + } + +} diff --git a/epmet-auth/src/main/java/com/epmet/service/LoginService.java b/epmet-auth/src/main/java/com/epmet/service/LoginService.java new file mode 100644 index 0000000000..8ecb3bb35d --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/service/LoginService.java @@ -0,0 +1,31 @@ +package com.epmet.service; + +import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; +import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; +import com.epmet.common.token.dto.result.UserTokenResultDTO; +import com.epmet.commons.tools.utils.Result; + +/** + * @Description + * @Author yinzuomei + * @Date 2020/3/14 20:21 + */ +public interface LoginService { + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 微信小程序登录 + * @Date 2020/3/14 19:34 + **/ + Result loginByWxCode(LoginByWxCodeFormDTO formDTO); + + /** + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 手机号+密码登录接口 + * @Date 2020/3/14 19:54 + **/ + Result loginByPassword(LoginByPassWordFormDTO formDTO); +} diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000000..8d5b19864b --- /dev/null +++ b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java @@ -0,0 +1,193 @@ +package com.epmet.service.impl; + +import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; +import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; +import com.epmet.common.token.constant.LoginConstant; +import com.epmet.common.token.dto.TokenDto; +import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; +import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; +import com.epmet.common.token.dto.result.UserTokenResultDTO; +import com.epmet.common.token.util.CpUserDetailRedis; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dao.CustomerUserDao; +import com.epmet.entity.CustomerUserEntity; +import com.epmet.jwt.JwtTokenProperties; +import com.epmet.jwt.JwtTokenUtils; +import com.epmet.service.LoginService; +import com.epmet.utils.WxMaServiceUtils; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxErrorException; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Description + * @Author yinzuomei + * @Date 2020/3/14 20:31 + */ +@Slf4j +@Service +public class LoginServiceImpl implements LoginService { + private static final Logger logger = LoggerFactory.getLogger(AuthServiceImpl.class); + + @Autowired + private CustomerUserDao customerUserDao; + + @Autowired + private WxMaServiceUtils wxMaServiceUtils; + + @Autowired + private JwtTokenUtils jwtTokenUtils; + + @Autowired + private JwtTokenProperties jwtTokenProperties; + + @Autowired + private CpUserDetailRedis cpUserDetailRedis; + + /** + * 微信小程序登录 + * + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @author yinzuomei + * @since 2020/3/14 19:34 + */ + @Override + public Result loginByWxCode(LoginByWxCodeFormDTO formDTO) { + //1、根据wxCode获取微信信息 + WxMaJscode2SessionResult wxMaJscode2SessionResult = this.getWxMaUser(formDTO); + logger.info("openId=[" + wxMaJscode2SessionResult.getOpenid() + "]unionId=[" + wxMaJscode2SessionResult.getUnionid() + "]"); + //2、根据openId查询数据库,没有则直接插入一条记录 + String userId = this.getUserId(formDTO, wxMaJscode2SessionResult); + if (StringUtils.isNotBlank(userId)) { + //3、封装token且存到redis + UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); + userTokenResultDTO.setToken(this.packagingUserToken(formDTO, userId, wxMaJscode2SessionResult)); + return new Result().ok(userTokenResultDTO); + } + return new Result().error("登录失败"); + } + + /** + * 解析微信code获取小程序用户信息 + * + * @param formDTO + * @return cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult + * @author yinzuomei + * @date 2020/3/14 20:16 + */ + private WxMaJscode2SessionResult getWxMaUser(LoginByWxCodeFormDTO formDTO) { + WxMaJscode2SessionResult wxMaJscode2SessionResult = null; + try { + if (LoginConstant.APP_GOV.equals(formDTO.getApp())) { + wxMaJscode2SessionResult = wxMaServiceUtils.govWxMaService().jsCode2SessionInfo(formDTO.getWxCode()); + } else if (LoginConstant.APP_OPER.equals(formDTO.getApp())) { + wxMaJscode2SessionResult = wxMaServiceUtils.operWxMaService().jsCode2SessionInfo(formDTO.getWxCode()); + } else if (LoginConstant.APP_RESI.equals(formDTO.getApp())) { + wxMaJscode2SessionResult = wxMaServiceUtils.resiWxMaService().jsCode2SessionInfo(formDTO.getWxCode()); + } + } catch (WxErrorException e) { + log.error("->[getMaOpenId]::error[{}]", "解析微信code失败"); + } + if (null == wxMaJscode2SessionResult) { + throw new RenException("解析微信用户信息失败"); + } else if (StringUtils.isBlank(wxMaJscode2SessionResult.getOpenid())) { + throw new RenException("获取微信openid失败"); + } + return wxMaJscode2SessionResult; + } + + /** + * 根据openId查询用户id + * + * @param formDTO + * @param wxMaJscode2SessionResult + * @return java.lang.String + * @author yinzuomei + * @since 2020/3/14 19:34 + */ + private String getUserId(LoginByWxCodeFormDTO formDTO, WxMaJscode2SessionResult wxMaJscode2SessionResult) { + String userId = ""; + if (LoginConstant.APP_GOV.equals(formDTO.getApp())) { + //查询customer_staff待完善 + } else if (LoginConstant.APP_OPER.equals(formDTO.getApp())) { + //查询oper_staff待完善 + } else if (LoginConstant.APP_RESI.equals(formDTO.getApp())) { + //查询customer_user + userId = customerUserDao.selectByWxOpenId(wxMaJscode2SessionResult.getOpenid()); + if (StringUtils.isBlank(userId)) { + WxMaUserInfo wxMaUserInfo = wxMaServiceUtils.resiWxMaService().getUserService() + .getUserInfo(wxMaJscode2SessionResult.getSessionKey(), + formDTO.getEncryptedData(), + formDTO.getIv()); + CustomerUserEntity customerUserEntity = new CustomerUserEntity(); + customerUserEntity.setCity(wxMaUserInfo.getCity()); + customerUserEntity.setWxOpenId(wxMaUserInfo.getOpenId()); + customerUserEntity.setNickname(wxMaUserInfo.getNickName()); + customerUserEntity.setCountry(wxMaUserInfo.getCountry()); + customerUserEntity.setHeadImgUrl(wxMaUserInfo.getAvatarUrl()); + customerUserEntity.setCountry(wxMaUserInfo.getCountry()); + customerUserEntity.setProvince(wxMaUserInfo.getProvince()); + customerUserEntity.setSex(Integer.valueOf(wxMaUserInfo.getGender())); + customerUserDao.insert(customerUserEntity); + userId = customerUserEntity.getId(); + } + } + return userId; + } + + /** + * 封装用户token值 + * + * @param formDTO + * @param userId + * @param wxMaJscode2SessionResult + * @return java.lang.String + * @author yinzuomei + * @since 2020/3/14 19:34 + */ + private String packagingUserToken(LoginByWxCodeFormDTO formDTO, + String userId, + WxMaJscode2SessionResult wxMaJscode2SessionResult) { + // 生成token + Map map = new HashMap<>(); + map.put("app", formDTO.getApp()); + map.put("client", formDTO.getClient()); + map.put("userId", userId); + String token = jwtTokenUtils.createToken(map); + int expire = jwtTokenProperties.getExpire(); + TokenDto tokenDto = new TokenDto(); + tokenDto.setApp(formDTO.getApp()); + tokenDto.setClient(formDTO.getClient()); + tokenDto.setUserId(userId); + tokenDto.setOpenId(wxMaJscode2SessionResult.getOpenid()); + tokenDto.setSessionKey(wxMaJscode2SessionResult.getSessionKey()); + tokenDto.setUnionId(wxMaJscode2SessionResult.getUnionid()); + cpUserDetailRedis.set(tokenDto, expire); + return token; + } + + /** + * 手机号+密码登录接口 + * + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @author yinzuomei + * @since 2020/3/14 19:34 + */ + @Override + public Result loginByPassword(LoginByPassWordFormDTO formDTO) { + //1、账号是否存在 + //2、密码是否正确 + //3、生成token返回,且将TokenDto存到redis + return null; + } +} diff --git a/epmet-auth/src/main/resources/bootstrap.yml b/epmet-auth/src/main/resources/bootstrap.yml index dc2f8aef3b..525987775e 100644 --- a/epmet-auth/src/main/resources/bootstrap.yml +++ b/epmet-auth/src/main/resources/bootstrap.yml @@ -23,6 +23,34 @@ spring: port: @spring.redis.port@ password: @spring.redis.password@ timeout: 30s + datasource: + druid: + #MySQL + driver-class-name: com.mysql.cj.jdbc.Driver + url: @spring.datasource.druid.url@ + username: @spring.datasource.druid.username@ + password: @spring.datasource.druid.password@ + initial-size: 10 + max-active: 100 + min-idle: 10 + max-wait: 60000 + pool-prepared-statements: true + max-pool-prepared-statement-per-connection-size: 20 + time-between-eviction-runs-millis: 60000 + min-evictable-idle-time-millis: 300000 + #Oracle需要打开注释 + #validation-query: SELECT 1 FROM DUAL + test-while-idle: true + test-on-borrow: false + test-on-return: false + filter: + stat: + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: false + wall: + config: + multi-statement-allow: true cloud: nacos: discovery: @@ -87,11 +115,11 @@ ribbon: ReadTimeout: 300000 ConnectTimeout: 300000 jwt: - #秘钥 - # secret: 7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet] - secret: f4e2e52034348f86b67cde5[www.renren.io] - #token有效时长,默认7天,单位秒 - expire: 604800 + token: + #秘钥 + secret: 7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet] + #token有效时长,默认7天,单位秒 + expire: 604800 wx: mp: configs: diff --git a/epmet-auth/src/main/resources/mapper/CustomerUserDao.xml b/epmet-auth/src/main/resources/mapper/CustomerUserDao.xml new file mode 100644 index 0000000000..43f12f9172 --- /dev/null +++ b/epmet-auth/src/main/resources/mapper/CustomerUserDao.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/constant/LoginConstant.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/constant/LoginConstant.java new file mode 100644 index 0000000000..b546108bc8 --- /dev/null +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/constant/LoginConstant.java @@ -0,0 +1,33 @@ +package com.epmet.common.token.constant; + +/** + * @Description app、client + * @Author yinzuomei + * @Date 2020/3/14 20:12 + */ +public interface LoginConstant { + /** + * 政府端 + */ + String APP_GOV = "gov"; + + /** + * 居民端 + */ + String APP_RESI = "resi"; + + /** + * 运营端 + */ + String APP_OPER = "oper"; + + /** + * web + */ + String CLIENT_WEB = "web"; + + /** + * 微信小程序 + */ + String CLIENT_WXMP = "wxmp"; +} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/DeptDataScopeDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/DeptDataScopeDTO.java deleted file mode 100644 index 423f31fb62..0000000000 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/DeptDataScopeDTO.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.epmet.common.token.dto; - -import lombok.Data; - -import java.io.Serializable; - -/** - * - * 用户所有角色权限信息 - * - * @Author:liuchuang - * @Date:2019/11/19 23:48 - */ -@Data -public class DeptDataScopeDTO implements Serializable { - private static final long serialVersionUID = -6319876948812713836L; - - /** - * 部门ID - */ - private Long deptId; - - /** - * 部门名称 - */ - private String deptName; - - /** - * 部门类型 - */ - private String typeKey; -} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/TokenDto.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/TokenDto.java index b0989145e7..885c4831ed 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/TokenDto.java +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/TokenDto.java @@ -1,52 +1,49 @@ -package com.elink.esua.epdc.common.token.dto; +package com.epmet.common.token.dto; +import com.google.gson.annotations.SerializedName; import lombok.Data; +import javax.validation.constraints.NotBlank; import java.io.Serializable; /** * 用户token * - * @author rongchao - * @Date 18-10-31 + * @author yinzuomei + * @Date 2020-03-14 */ @Data public class TokenDto implements Serializable { - private static final long serialVersionUID = 1L; - - /** - * 用户ID - */ - private String userId; - - /** - * 昵称 - */ - private String nickname; - - /** - * 用户头像 - */ - private String faceImg; - - /** - * 手机号 - */ - private String mobile; - - /** - * 真实姓名 - */ - private String realName; - - /** - * 网格ID - */ - private Long gridId; - - /** - * 党员标识 0:否、1:是 - */ - private String partyFlag; + private static final long serialVersionUID = 1L; + + /** + * 政府端:gov、居民端:resi、运营端:oper + */ + private String app; + + /** + * PC端:web、微信小程序:wxmp + */ + private String client; + + /** + * 用户ID + */ + private String userId; + + /** + * sessionKey + */ + private String sessionKey; + + /** + * openId + */ + private String openId; + + /** + * unionId + */ + private String unionId; } diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserAuthorizationDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserAuthorizationDTO.java deleted file mode 100644 index a3de3102ea..0000000000 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserAuthorizationDTO.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.epmet.common.token.dto; - -import lombok.Data; - -import java.io.Serializable; -import java.util.List; - -/** - * - * 工作端用户授权信息 - * - * @Author:liuchuang - * @Date:2019/11/19 20:17 - */ -@Data -public class WorkUserAuthorizationDTO implements Serializable { - private static final long serialVersionUID = -4230190448906007120L; - - /** - * 令牌 - */ - private String token; - - /** - * 过期时长,单位秒 - */ - private Integer expire; - - /** - * 部门名称 - */ - private String deptName; - - /** - * 用户标签key - */ - private String userTagKey; - - /** - * 注册状态 0-未注册,1-已注册 - */ - private String registerState; - - /** - * 用户所有角色权限信息 - */ - private List deptDataScopeList; -} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserLoginDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserLoginDTO.java deleted file mode 100644 index 4f2e9a64c2..0000000000 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserLoginDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.epmet.common.token.dto; - -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * - * 工作端用户登录信息 - * - * @Author:liuchuang - * @Date:2019/11/19 20:19 - */ -@Data -public class WorkUserLoginDTO implements Serializable { - private static final long serialVersionUID = 1905641243346550379L; - - @NotBlank(message="用户名不能为空") - private String username; - - @NotBlank(message="密码不能为空") - private String password; - - @NotBlank(message="微信code不能为空") - private String wxCode; - - private String openId; -} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserTokenFormDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserTokenFormDTO.java deleted file mode 100644 index 7b303528c1..0000000000 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/WorkUserTokenFormDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.epmet.common.token.dto; - -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * - * 工作端获取token Form DTO - * - * @Author:liuchuang - * @Date:2019/11/19 20:35 - */ -@Data -public class WorkUserTokenFormDTO implements Serializable { - private static final long serialVersionUID = -2239027109939769097L; - - @NotNull(message = "用户ID不能为空") - private Long id; - - @NotBlank(message = "用户名不能为空") - private String username; -} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java new file mode 100644 index 0000000000..8dfd2750c6 --- /dev/null +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByPassWordFormDTO.java @@ -0,0 +1,29 @@ +package com.epmet.common.token.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description 手机号+密码登录接口入参 + * @Author yinzuomei + * @Date 2020/3/14 19:46 + */ +@Data +public class LoginByPassWordFormDTO extends LoginCommonFormDTO implements Serializable { + private static final long serialVersionUID = -7507437651048051183L; + + /** + * 手机号 + */ + @NotBlank(message = "手机号不能为空") + private String phone; + + /** + * 密码 + */ + @NotBlank(message = "密码不能为空") + private String password; + +} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java new file mode 100644 index 0000000000..149514a0a3 --- /dev/null +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginByWxCodeFormDTO.java @@ -0,0 +1,34 @@ +package com.epmet.common.token.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description 微信小程序登录接口入参 + * @Author yinzuomei + * @Date 2020/3/14 14:39 + */ +@Data +public class LoginByWxCodeFormDTO extends LoginCommonFormDTO implements Serializable { + private static final long serialVersionUID = 7950477424010655108L; + + /** + * 微信code + */ + @NotBlank(message = "wxCode不能为空") + private String wxCode; + + /** + * 用户信息 + */ + @NotBlank(message = "用户信息不能为空") + private String encryptedData; + + /** + * 加密算法的初始向量 + */ + @NotBlank(message = "初始向量不能为空") + private String iv; +} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java new file mode 100644 index 0000000000..9b2390388e --- /dev/null +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/form/LoginCommonFormDTO.java @@ -0,0 +1,28 @@ +package com.epmet.common.token.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Description 登录接口通用入参 + * @Author yinzuomei + * @Date 2020/3/14 19:47 + */ +@Data +public class LoginCommonFormDTO implements Serializable { + private static final long serialVersionUID = -5582224784914714820L; + + /** + * 政府端:gov、居民端:resi、运营端:oper + */ + @NotBlank(message = "app不能为空(政府端:gov、居民端:resi、运营端:oper)") + private String app; + + /** + * PC端:web、微信小程序:wxmp + */ + @NotBlank(message = "client不能为空(PC端:web、微信小程序:wxmp)") + private String client; +} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java new file mode 100644 index 0000000000..e5296bf42b --- /dev/null +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/dto/result/UserTokenResultDTO.java @@ -0,0 +1,20 @@ +package com.epmet.common.token.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description 登录接口返参DTO + * @Author yinzuomei + * @Date 2020/3/14 15:10 + */ +@Data +public class UserTokenResultDTO implements Serializable { + private static final long serialVersionUID = 5214475907074876716L; + + /** + * 令牌 + */ + private String token; +} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/CpUserDetailRedis.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/CpUserDetailRedis.java index d036773660..4d10b38f66 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/CpUserDetailRedis.java +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/CpUserDetailRedis.java @@ -10,7 +10,7 @@ package com.epmet.common.token.util; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.map.MapUtil; -import com.elink.esua.epdc.common.token.dto.TokenDto; +import com.epmet.common.token.dto.TokenDto; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -27,68 +27,68 @@ import java.util.Map; @Component public class CpUserDetailRedis { - @Autowired - private RedisUtils redisUtils; + @Autowired + private RedisUtils redisUtils; - public void set(TokenDto user, long expire) { - if (user == null) { - return; - } - String key = RedisKeys.getCpUserKey(user.getUserId()); - //bean to map - Map map = BeanUtil.beanToMap(user, false, true); - redisUtils.hMSet(key, map, expire); - } + public void set(TokenDto user, long expire) { + if (user == null) { + return; + } + String key = RedisKeys.getCpUserKey(user.getApp(), user.getClient(), user.getUserId()); + //bean to map + Map map = BeanUtil.beanToMap(user, false, true); + redisUtils.hMSet(key, map, expire); + } - /** - * 获取token信息 - * - * @param userId - * @return - */ - public TokenDto get(String userId) { - String key = RedisKeys.getCpUserKey(userId); + /** + * 获取token信息 + * + * @param userId + * @return + */ + public TokenDto get(String app, String client, String userId) { + String key = RedisKeys.getCpUserKey(app, client, userId); - Map map = redisUtils.hGetAll(key); - if (MapUtil.isEmpty(map)) { - return null; - } + Map map = redisUtils.hGetAll(key); + if (MapUtil.isEmpty(map)) { + return null; + } - //map to bean - TokenDto user = BeanUtil.mapToBean(map, TokenDto.class, true); + //map to bean + TokenDto user = BeanUtil.mapToBean(map, TokenDto.class, true); - return user; - } + return user; + } - /** - * 删除用户信息 - * - * @param userId - */ - public void logout(String userId) { - redisUtils.delete(RedisKeys.getCpUserKey(userId)); - } + /** + * 删除用户信息 + * + * @param userId + */ + public void logout(String app, String client, String userId) { + redisUtils.delete(RedisKeys.getCpUserKey(app, client, userId)); + } - /** - * 设置redis时间 - * - * @param userId - * @param expire - * @author rongchao - */ - public boolean expire(String userId, long expire) { - return redisUtils.expire(RedisKeys.getCpUserKey(userId), expire); - } + /** + * 设置redis时间 + * + * @param userId + * @param expire + * @author rongchao + */ + public boolean expire(String app, String client, String userId, long expire) { + return redisUtils.expire(RedisKeys.getCpUserKey(app, client, userId), expire); + } - /** - * 查询token剩余时间 - * - * @param userId - * @return long - * @author yujintao - * @date 2019/9/9 14:18 - */ - public long getExpire(String userId) { - return redisUtils.getExpire(RedisKeys.getCpUserKey(userId)); - } + /** + * 查询token剩余时间 + * + * @param userId + * @return long + * @author yujintao + * @date 2019/9/9 14:18 + */ + public long getExpire(String app, String client, String userId) { + return redisUtils.getExpire(RedisKeys.getCpUserKey(app, client, userId)); + } } diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/TokenUtil.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/TokenUtil.java index d11af40dd6..173e985523 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/TokenUtil.java +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/TokenUtil.java @@ -1,6 +1,6 @@ package com.epmet.common.token.util; -import com.elink.esua.epdc.common.token.dto.TokenDto; +import com.epmet.common.token.dto.TokenDto; import com.epmet.common.token.property.TokenPropertise; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,17 +24,17 @@ public class TokenUtil { @Autowired private CpUserDetailRedis redisUtils; - public TokenDto getTokenInfo(String userId) { - TokenDto tokenDto = redisUtils.get(userId); + public TokenDto getTokenInfo(String app,String client,String userId) { + TokenDto tokenDto = redisUtils.get(app,client,userId); return tokenDto; } - public void expireToken(String userId) { - redisUtils.logout(userId); + public void expireToken(String app,String client,String userId) { + redisUtils.logout(app,client,userId); } - public boolean delayToken(String userId) { - return redisUtils.expire(userId, tokenPropertise.getExpire()); + public boolean delayToken(String app,String client,String userId) { + return redisUtils.expire(app,client,userId, tokenPropertise.getExpire()); } /** @@ -45,7 +45,7 @@ public class TokenUtil { * @author yujintao * @date 2019/9/9 14:19 */ - public long getExpire(String userId) { - return redisUtils.getExpire(userId); + public long getExpire(String app,String client,String userId) { + return redisUtils.getExpire(app,client,userId); } } diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/UserUtil.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/UserUtil.java index 68965da7b6..1868a76674 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/UserUtil.java +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/util/UserUtil.java @@ -1,6 +1,6 @@ package com.epmet.common.token.util; -import com.elink.esua.epdc.common.token.dto.TokenDto; +import com.epmet.common.token.dto.TokenDto; import com.epmet.commons.tools.constant.Constant; import com.epmet.commons.tools.utils.WebUtil; diff --git a/epmet-commons/epmet-commons-tools-wx-ma/src/main/java/com/epmet/utils/WxMaServiceUtils.java b/epmet-commons/epmet-commons-tools-wx-ma/src/main/java/com/epmet/utils/WxMaServiceUtils.java index 05c8f51bcf..8d7aaa463d 100644 --- a/epmet-commons/epmet-commons-tools-wx-ma/src/main/java/com/epmet/utils/WxMaServiceUtils.java +++ b/epmet-commons/epmet-commons-tools-wx-ma/src/main/java/com/epmet/utils/WxMaServiceUtils.java @@ -17,11 +17,11 @@ public class WxMaServiceUtils { @Value("${wx.ma.appId.resi}") private String APPID_RESI; - @Value("${wx.ma.appId.gov}") + /*@Value("${wx.ma.appId.gov}") private String APPID_GOV; @Value("${wx.ma.appId.oper}") - private String APPID_OPER; + private String APPID_OPER;*/ /** * 获取党群e事通-居民端小程序配置 @@ -43,7 +43,8 @@ public class WxMaServiceUtils { * @date 2020/03/13 10:44 */ public final WxMaService govWxMaService() { - final WxMaService wxMaService = WxMaConfig.getMaService(APPID_GOV); +// final WxMaService wxMaService = WxMaConfig.getMaService(APPID_GOV); + final WxMaService wxMaService = WxMaConfig.getMaService(APPID_RESI); return wxMaService; } @@ -57,7 +58,8 @@ public class WxMaServiceUtils { * @since 2020/03/13 10:44 */ public final WxMaService operWxMaService() { - final WxMaService wxMaService = WxMaConfig.getMaService(APPID_OPER); +// final WxMaService wxMaService = WxMaConfig.getMaService(APPID_OPER); + final WxMaService wxMaService = WxMaConfig.getMaService(APPID_RESI); return wxMaService; } } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java index 15b2e92cbf..38a6c0d33a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java @@ -104,8 +104,4 @@ public interface Constant { * 版本控制用 */ String VERSION_CONTROL = "/{version}"; - /** - * 移动端接口标识 - */ - String EPDC_APP = "epdc-app/"; } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 0281c824b0..1517d1220c 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -1,8 +1,8 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. - * + *

* https://www.renren.io - * + *

* 版权所有,侵权必究! */ @@ -14,95 +14,101 @@ package com.epmet.commons.tools.redis; */ public class RedisKeys { - /** - * 党群e事通redis前缀 - */ - private static String rootPrefix = "epdc:"; - - /** - * 系统参数Key - */ - public static String getSysParamsKey() { - return rootPrefix.concat("sys:params"); - } - - /** - * 登录验证码Key - */ - public static String getLoginCaptchaKey(String uuid) { - return rootPrefix.concat("sys:captcha:").concat(uuid); - } - - /** - * 登录用户Key - */ - public static String getSecurityUserKey(Long id) { - return rootPrefix.concat("sys:security:user:").concat(String.valueOf(id)); - } - - /** - * 系统日志Key - */ - public static String getSysLogKey() { - return rootPrefix.concat("sys:log"); - } - - /** - * 系统资源Key - */ - public static String getSysResourceKey() { - return rootPrefix.concat("sys:resource"); - } - - /** - * 用户菜单导航Key - */ - public static String getUserMenuNavKey(Long userId, String language) { - return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_").concat(language); - } - - /** - * 用户菜单导航Key - */ - public static String getUserMenuNavKey(Long userId) { - return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_*"); - } - - /** - * 用户权限标识Key - */ - public static String getUserPermissionsKey(Long userId) { - return rootPrefix.concat("sys:user:permissions:").concat(String.valueOf(userId)); - } - - public static String getCpUserKey(String id) { - return rootPrefix.concat("sys:security:cpuser:").concat(id); - } - - /** - * 拼接手机验证码key---后面需要改!!! - * - * @param phone - * @return java.lang.String - * @author yujintao - * @date 2019/9/6 17:03 - */ - public static String getPhoneSmsCodeKey(String phone) { - return rootPrefix.concat("phone:sms:code:").concat(phone); - } - - /** - * 用户请求发送短信接口,记录本次请求时间,保存一分钟 - * ---后面需要改!!! - * @param phone - * @return java.lang.String - * @author work@yujt.net.cn - * @date 2019/12/6 19:05 - */ - public static String getPhoneSmsHistoryKey(String phone) { - return rootPrefix.concat("phone:sms:history:").concat(phone); - } - + /** + * 党群e事通redis前缀 + */ + private static String rootPrefix = "epmet:"; + + /** + * 系统参数Key + */ + public static String getSysParamsKey() { + return rootPrefix.concat("sys:params"); + } + + /** + * 登录验证码Key + */ + public static String getLoginCaptchaKey(String uuid) { + return rootPrefix.concat("sys:captcha:").concat(uuid); + } + + /** + * 登录用户Key + */ + public static String getSecurityUserKey(Long id) { + return rootPrefix.concat("sys:security:user:").concat(String.valueOf(id)); + } + + /** + * 系统日志Key + */ + public static String getSysLogKey() { + return rootPrefix.concat("sys:log"); + } + + /** + * 系统资源Key + */ + public static String getSysResourceKey() { + return rootPrefix.concat("sys:resource"); + } + + /** + * 用户菜单导航Key + */ + public static String getUserMenuNavKey(Long userId, String language) { + return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_").concat(language); + } + + /** + * 用户菜单导航Key + */ + public static String getUserMenuNavKey(Long userId) { + return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_*"); + } + + /** + * 用户权限标识Key + */ + public static String getUserPermissionsKey(Long userId) { + return rootPrefix.concat("sys:user:permissions:").concat(String.valueOf(userId)); + } + + /** + * 用户token Key + * epmet:sys:security:user:resi:wxmp:100051424889632 + * epmet:sys:security:user:gov:wxmp:5048212821254821 + * epmet:sys:security:user:oper:web:eeedsfsdfds512551 + */ + public static String getCpUserKey(String app, String client, String id) { + return rootPrefix.concat("sys:security:user:").concat(app).concat(":").concat(client).concat(":").concat(id); + } + + /** + * 拼接手机验证码key---后面需要改!!! + * + * @param phone + * @return java.lang.String + * @author yujintao + * @date 2019/9/6 17:03 + */ + public static String getPhoneSmsCodeKey(String phone) { + return rootPrefix.concat("phone:sms:code:").concat(phone); + } + + /** + * 用户请求发送短信接口,记录本次请求时间,保存一分钟 + * ---后面需要改!!! + * + * @param phone + * @return java.lang.String + * @author work@yujt.net.cn + * @date 2019/12/6 19:05 + */ + public static String getPhoneSmsHistoryKey(String phone) { + return rootPrefix.concat("phone:sms:history:").concat(phone); + } }