| | |
| | | package com.panzhihua.common.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.constants.Constants; |
| | | import com.panzhihua.common.constants.TokenConstant; |
| | | import com.panzhihua.common.constants.UserConstants; |
| | | import com.panzhihua.common.exceptions.UnAuthenticationException; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.utlis.AES; |
| | | import io.swagger.models.auth.In; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.panzhihua.common.model.vos.community.ComActVO; |
| | | import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import sun.security.krb5.internal.crypto.Aes256; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.constants.Constants; |
| | | import com.panzhihua.common.constants.TokenConstant; |
| | | import com.panzhihua.common.exceptions.ServiceException; |
| | | import com.panzhihua.common.exceptions.UnAuthenticationException; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.utlis.AES; |
| | | |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static org.apache.commons.lang3.StringUtils.isBlank; |
| | | |
| | | /** |
| | | * @program: springcloud_k8s_panzhihuazhihuishequ |
| | |
| | | **/ |
| | | @Slf4j |
| | | public class BaseController { |
| | | |
| | | /** |
| | | * 获取request对象 |
| | | */ |
| | | public HttpServletRequest getRequest() { |
| | | return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取request对象 |
| | | */ |
| | | public HttpServletResponse getResponse() { |
| | | return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse(); |
| | | } |
| | | |
| | | /** |
| | | * 获取登录对象信息 |
| | | * |
| | | * @return 对象userid |
| | | */ |
| | | public Long getUserId(){ |
| | | public Long getUserId() { |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | Long userId = loginUserInfo.getUserId(); |
| | | return userId; |
| | |
| | | |
| | | /** |
| | | * 获取登录对象所在社区id |
| | | * |
| | | * @return 社区id |
| | | */ |
| | | public Long getCommunityId(){ |
| | | public Long getCommunityId() { |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | Long communityId = loginUserInfo.getCommunityId(); |
| | | // if (null == communityId) { |
| | | // throw new ServiceException("用户未绑定社区"); |
| | | // } |
| | | return communityId; |
| | | } |
| | | |
| | | /** |
| | | * 获取登录对象所在小区 |
| | | * @return 小区id |
| | | * 获取登录对象所在社区名称 |
| | | * |
| | | * @return 社区名称 |
| | | */ |
| | | public Long getAreaId(){ |
| | | public String getCommunityName() { |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | Long areaId = loginUserInfo.getAreaId(); |
| | | return areaId; |
| | | Long communityId = loginUserInfo.getCommunityId(); |
| | | if (null == communityId || 0 == communityId) { |
| | | throw new ServiceException("用户未绑定社区"); |
| | | } |
| | | String communityName = loginUserInfo.getCommunityName(); |
| | | return communityName; |
| | | } |
| | | |
| | | /** |
| | | * 获取登录对象所在小区 |
| | | * |
| | | * @return 小区id |
| | | */ |
| | | public Long getAreaId() { |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | Long areaId = loginUserInfo.getAreaId(); |
| | | if (null == areaId) { |
| | | throw new ServiceException("用户未绑定小区"); |
| | | } |
| | | return areaId; |
| | | } |
| | | /** |
| | | * 获取登录对象所在区域编码 |
| | | * |
| | | * @return |
| | | */ |
| | | public String getAreaCode() { |
| | | String appid = this.getRequest().getHeader("appid"); |
| | | if(StringUtils.isNotEmpty(appid)){ |
| | | if(appid.equals("wx08932ba29546ff82")){ |
| | | return "510411"; |
| | | } |
| | | else if(appid.equals("wx50d8c395af50481b")){ |
| | | return "510402"; |
| | | } |
| | | else { |
| | | return "510423"; |
| | | } |
| | | } else { |
| | | LoginUserInfoVO loginUserInfoVO=this.getLoginUserInfo(); |
| | | ComActVO comActVO=loginUserInfoVO.getComActVO(); |
| | | if(isNull(comActVO) || isBlank(comActVO.getAreaCode())){ |
| | | return "510423"; |
| | | } |
| | | return comActVO.getAreaCode(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取登录token |
| | | * |
| | | * @return token |
| | | */ |
| | | public String getToken(){ |
| | | public String getToken() { |
| | | HttpServletRequest request = this.getRequest(); |
| | | String header = request.getHeader(TokenConstant.TOKEN_LOGOUT); |
| | | return header; |
| | | } |
| | | |
| | | public String getAppId(){ |
| | | String appid = this.getRequest().getHeader("appid"); |
| | | if(StringUtils.isEmpty(appid)){ |
| | | return "wx0cef797390444b75"; |
| | | } |
| | | return appid; |
| | | } |
| | | |
| | | public String getAppSecret(){ |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | return loginUserInfo.getAppSecret(); |
| | | } |
| | | /** |
| | | * 获取登录对象所有信息 |
| | | * |
| | | * @return 所有信息 |
| | | */ |
| | | @SneakyThrows |
| | | public LoginUserInfoVO getLoginUserInfo(){ |
| | | public LoginUserInfoVO getLoginUserInfo() { |
| | | HttpServletRequest request = this.getRequest(); |
| | | String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO); |
| | | boolean empty = ObjectUtils.isEmpty(userInfo); |
| | | if (empty) { |
| | | throw new UnAuthenticationException("获取登录人信息失败"); |
| | | } |
| | | log.info("userInfo【{}】",userInfo); |
| | | // log.info("userInfo【{}】",userInfo); |
| | | byte[] bytes = AES.parseHexStr2Byte(userInfo); |
| | | log.info("bytes【{}】",bytes); |
| | | // log.info("bytes【{}】",bytes); |
| | | byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY); |
| | | log.info("decrypt【{}】",decrypt); |
| | | userInfo=new String(decrypt); |
| | | LoginUserInfoVO loginUserInfoVO= JSONObject.parseObject(userInfo,LoginUserInfoVO.class); |
| | | // log.info("decrypt【{}】",decrypt); |
| | | userInfo = new String(decrypt); |
| | | LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(userInfo, LoginUserInfoVO.class); |
| | | return loginUserInfoVO; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | byte[] bytes = AES.parseHexStr2Byte("A5050B4D17DE52A39ECB57C6B160B8285ED8371239D8A6EBB0D2421B8BB6EA12C580D19459D29B97A31F07C8932D275F61F9F440A2A13FA718539CD06190F82036FE692BDE840784A66CD76E2C0360C25F9055DDB2FE33652B1D126B7720280ACC5471B0EF6BD00CFB478A06E1E78CDD6C310C1DE271BDE5348D6899063ADCDD39DE446236809801A14BF47B5468B96128E45DEFCE8365B83D62AA5C3C1570EA16CC51BC228421FFD731016943D7CEEAD36AD8FA055BE628639CE265F524562F99129823989A8D7B8A9B1B202524672E85464E15EB7E6F50C632C085B5602AD4B42E6D645499C5922D3714B6A987E44DA78059D87D5942F9FEFBB1B610C920F89AB76FC32D4C9E945DCDCE2974539BF928B0A2663954849459F8D127D2B50D7BFD5CF2B506785FB515CB9AB106FA9A40F467E75B5148ACE7A8C5E6650E6A3576396F3D08D6D1B90DB0F4CCDE8D4025B86E45CC32CCBB32CC93E2F248DBD9416D957A0C6E0FD4E35DAE29D2E7C1F6EE6213B6BB566159CF248D14680C4F84C051A754D0F1BE100C715030AC4585327D95743DF8B866817E4F7E59868FCEC8AFEB9C4A75C06FC21590E3A46419D7F75CB8A4DD280FF1D138D1E61E3EDE2C41737D0BA21A739C0A5BF8842479F00D4A8919"); |
| | | @SneakyThrows |
| | | public LoginUserInfoVO getLoginUserInfoSureNoLogin() { |
| | | HttpServletRequest request = this.getRequest(); |
| | | String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO); |
| | | boolean empty = ObjectUtils.isEmpty(userInfo); |
| | | if (empty) { |
| | | return null; |
| | | // throw new UnAuthenticationException("获取登录人信息失败"); |
| | | } |
| | | // log.info("userInfo【{}】",userInfo); |
| | | byte[] bytes = AES.parseHexStr2Byte(userInfo); |
| | | // log.info("bytes【{}】",bytes); |
| | | byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY); |
| | | System.out.println(decrypt); |
| | | String s = new String(decrypt); |
| | | System.out.println(s); |
| | | // log.info("decrypt【{}】",decrypt); |
| | | userInfo = new String(decrypt); |
| | | LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(userInfo, LoginUserInfoVO.class); |
| | | return loginUserInfoVO; |
| | | } |
| | | /** |
| | | * 获取三个身边管理后台登录用户信息 |
| | | * @return |
| | | */ |
| | | @SneakyThrows |
| | | public SystemUserVo getLoginUserInfoSanGeShenBian() { |
| | | HttpServletRequest request = this.getRequest(); |
| | | String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO); |
| | | boolean empty = ObjectUtils.isEmpty(userInfo); |
| | | if (empty) { |
| | | return null; |
| | | } |
| | | byte[] bytes = AES.parseHexStr2Byte(userInfo); |
| | | byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY); |
| | | userInfo = new String(decrypt); |
| | | SystemUserVo loginUserInfoVO = JSONObject.parseObject(userInfo, SystemUserVo.class); |
| | | return loginUserInfoVO; |
| | | } |
| | | |
| | | } |