| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -12,6 +12,7 @@ import com.epmet.constant.PublicUserLoginConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.constant.SmsTemplateConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.PaCustomerDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.PaUserDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.PaUserWechatDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.*; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.result.CustomerUserResultDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.result.SaveUserResultDTO; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -77,7 +78,9 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //3.获取用户token
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String token = this.generateGovWxmpToken(resultDTO.getUserId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //4.保存到redis
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.saveLatestGovTokenDto(resultDTO, wxMpUser, token); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String openid = wxMpUser.getOpenId(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String unionId = (null == wxMpUser.getUnionId() ? "" : wxMpUser.getUnionId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.saveLatestGovTokenDto("", resultDTO.getUserId(), openid, unionId, token); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        userTokenResultDTO.setToken(token); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return userTokenResultDTO; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -118,17 +121,17 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    //保存tokenDto到redis
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private void saveLatestGovTokenDto(SaveUserResultDTO resultDTO, WxMpUser wxMpUser, String token) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private void saveLatestGovTokenDto(String customerId, String userId, String openId, String unionId, String token) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        TokenDto tokenDTO = new TokenDto(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        int expire = jwtTokenProperties.getExpire(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setApp(LoginConstant.APP_PUBLIC); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setClient(LoginConstant.CLIENT_MP); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setOpenId(wxMpUser.getOpenId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setUnionId(null == wxMpUser.getUnionId() ? "" : wxMpUser.getUnionId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setOpenId(openId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setUnionId(unionId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setToken(token); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //首次初始化时还没有客户
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setCustomerId(""); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setUserId(resultDTO.getUserId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setCustomerId(customerId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setUserId(userId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        tokenDTO.setUpdateTime(System.currentTimeMillis()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        cpUserDetailRedis.set(tokenDTO, expire); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -206,19 +209,27 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.error(String.format("验证码错误code[%s],msg[%s]", EpmetErrorCode.MOBILE_CODE_ERROR.getCode(), EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            throw new RenException(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //获取缓存中的token
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        TokenDto redisTokenDTO = cpUserDetailRedis.get(LoginConstant.APP_PUBLIC, LoginConstant.CLIENT_MP, userDTO.getId(), TokenDto.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (redisTokenDTO == null) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            return null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //4.判断是否存在客户信息,是否需要生成新的token
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //4.直接生成一个新的token放入缓存中(不管缓存中是否存在旧的token,都重新生成)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //4-1.生成token
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String token = this.generateGovWxmpToken(userDTO.getId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //4-2.判断是否存在信息,给customerId赋值
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        PaCustomerDTO customerDTO = resultDTO.getPaCustomerResult(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String customerId = ""; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (null != customerDTO && !StringUtils.isBlank(customerDTO.getId())) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            redisTokenDTO.setCustomerId(customerDTO.getId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            int expire = jwtTokenProperties.getExpire(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            cpUserDetailRedis.set(redisTokenDTO, expire); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            customerId = customerDTO.getId(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //4-3.token存入redis
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        PaUserWechatDTO wechatDTO = resultDTO.getPaUserWechatResult(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String openid = wechatDTO.getWxOpenId(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String unionId = (null == wechatDTO.getUnionId() ? "" : wechatDTO.getUnionId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.saveLatestGovTokenDto(customerId, userDTO.getId(), openid, unionId, token); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //5.登陆成功,访问记录表新增访问记录(访问记录新增失败不应影响用户登陆)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        SaveUserVisitedFormDTO visited = new SaveUserVisitedFormDTO(); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -232,7 +243,7 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //6.返回token
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        userTokenResultDTO.setToken(redisTokenDTO.getToken()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        userTokenResultDTO.setToken(token); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return userTokenResultDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |