|
|
@ -53,8 +53,6 @@ import com.taobao.dingtalk.vo.result.AccessTokenResult; |
|
|
|
import com.taobao.dingtalk.vo.result.UserBaseInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
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 org.springframework.util.CollectionUtils; |
|
|
@ -73,7 +71,6 @@ import java.util.stream.Collectors; |
|
|
|
@Service |
|
|
|
public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResolver { |
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ThirdLoginServiceImpl.class); |
|
|
|
@Autowired |
|
|
|
private JwtTokenUtils jwtTokenUtils; |
|
|
|
@Autowired |
|
|
@ -99,6 +96,17 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
@Autowired |
|
|
|
private ThirdOpenFeignClient thirdOpenFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* 工作端:gov、居民端:resi、运营端:oper |
|
|
|
*/ |
|
|
|
private static final String APP = "resi"; |
|
|
|
|
|
|
|
private static final String APP_ID = "wx07674c23af51b521"; |
|
|
|
|
|
|
|
private static final String SESSION_KEY = "a2fd0d29b007cbbcf8c8dda8c693d99b"; |
|
|
|
|
|
|
|
private static final String CLIENT = "wxmp"; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
@ -137,6 +145,33 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
return userTokenResultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public UserTokenResultDTO resiLoginByOpenId(String openId) { |
|
|
|
// 1、确定用户是否注册,如果没有,直接注册
|
|
|
|
WxUserFormDTO wxUser = new WxUserFormDTO(); |
|
|
|
wxUser.setApp(APP); |
|
|
|
UserWechatDTO wechatDTO = new UserWechatDTO(); |
|
|
|
wechatDTO.setWxOpenId(openId); |
|
|
|
wxUser.setWechatDTO(wechatDTO); |
|
|
|
UserDTO userDTO = epmetUserOpenFeignClient.saveWxUser(wxUser).getData(); |
|
|
|
// 2、封装数据
|
|
|
|
wechatDTO.setSessionKey(SESSION_KEY); |
|
|
|
wechatDTO.setUserId(userDTO.getId()); |
|
|
|
wechatDTO.setCustomerId(userDTO.getCustomerId()); |
|
|
|
LoginFormDTO loginDto = new LoginFormDTO(); |
|
|
|
loginDto.setClient(CLIENT); |
|
|
|
loginDto.setApp(APP); |
|
|
|
//3.生成业务token
|
|
|
|
String token = generateToken(loginDto, userDTO.getId()); |
|
|
|
//4.存放Redis
|
|
|
|
saveTokenDto(loginDto, userDTO.getId(), wechatDTO, token, userDTO.getCustomerId()); |
|
|
|
//5.接口返参
|
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
return userTokenResultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 居民端登陆生成业务token的key |
|
|
|
**/ |
|
|
@ -204,8 +239,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
throw new RenException(customerStaffResult.getCode()); |
|
|
|
} |
|
|
|
// 8008 前端会提示:登录失效,请重新登录 跳转到登录界面。所以这里写死返回8008.
|
|
|
|
if("disabled".equals(customerStaffResult.getData().get(NumConstant.ZERO).getEnableFlag())){ |
|
|
|
throw new EpmetException(EpmetErrorCode.PLEASE_LOGIN.getCode(),EpmetErrorCode.GOV_STAFF_DISABLED.getMsg(),EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
|
if ("disabled".equals(customerStaffResult.getData().get(NumConstant.ZERO).getEnableFlag())) { |
|
|
|
throw new EpmetException(EpmetErrorCode.PLEASE_LOGIN.getCode(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
//3.记录staff_wechat
|
|
|
@ -537,7 +572,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
//0、验证码是否正确
|
|
|
|
String rightSmsCode = captchaRedis.getSmsCode(formDTO.getMobile()); |
|
|
|
if (!formDTO.getSmsCode().equals(rightSmsCode)) { |
|
|
|
logger.warn(String.format("验证码错误code[%s],msg[%s]",EpmetErrorCode.MOBILE_CODE_ERROR.getCode(),EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); |
|
|
|
logger.warn(String.format("验证码错误code[%s],msg[%s]", EpmetErrorCode.MOBILE_CODE_ERROR.getCode(), EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); |
|
|
|
throw new RenException(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
|
|
|
} |
|
|
|
//1.根据appId查询对应客户Id
|
|
|
@ -553,8 +588,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
|
|
|
throw new RenException(customerStaffResult.getCode()); |
|
|
|
} |
|
|
|
if("disabled".equals(customerStaffResult.getData().get(NumConstant.ZERO).getEnableFlag())){ |
|
|
|
throw new EpmetException(EpmetErrorCode.GOV_STAFF_DISABLED.getCode(),EpmetErrorCode.GOV_STAFF_DISABLED.getMsg(),EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
|
if ("disabled".equals(customerStaffResult.getData().get(NumConstant.ZERO).getEnableFlag())) { |
|
|
|
throw new EpmetException(EpmetErrorCode.GOV_STAFF_DISABLED.getCode(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
|
} |
|
|
|
//3、查询用户所有的组织信息
|
|
|
|
List<String> customerIdList = new ArrayList<>(); |
|
|
@ -564,10 +599,10 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); |
|
|
|
staffOrgFormDTO.setCustomerIdList(customerIdList); |
|
|
|
Result<List<StaffOrgsResultDTO>> result = govOrgOpenFeignClient.getStaffOrgList(staffOrgFormDTO); |
|
|
|
if(result.success()&&null!=result.getData()){ |
|
|
|
if (result.success() && null != result.getData()) { |
|
|
|
return result.getData(); |
|
|
|
} |
|
|
|
logger.error(String .format("手机验证码获取组织,调用%s服务失败,入参手机号%s,验证码%s,返回错误码%s,错误提示信息%s", ServiceConstant.GOV_ORG_SERVER,formDTO.getMobile(),formDTO.getSmsCode(),result.getCode(),result.getMsg())); |
|
|
|
logger.error(String.format("手机验证码获取组织,调用%s服务失败,入参手机号%s,验证码%s,返回错误码%s,错误提示信息%s", ServiceConstant.GOV_ORG_SERVER, formDTO.getMobile(), formDTO.getSmsCode(), result.getCode(), result.getMsg())); |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
@ -588,55 +623,55 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
dto.setCustomerId(customer.getId()); |
|
|
|
dto.setMobile(formDTO.getMobile()); |
|
|
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserOpenFeignClient.getCustsomerStaffByIdAndPhone(dto); |
|
|
|
if (!customerStaffResult.success()||CollectionUtils.isEmpty(customerStaffResult.getData())) { |
|
|
|
if (!customerStaffResult.success() || CollectionUtils.isEmpty(customerStaffResult.getData())) { |
|
|
|
logger.warn(String.format("手机密码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
|
|
|
throw new RenException(customerStaffResult.getCode()); |
|
|
|
} |
|
|
|
//2、密码是否正确
|
|
|
|
List<CustomerStaffDTO> customerStaffList=customerStaffResult.getData(); |
|
|
|
List<CustomerStaffDTO> customerStaffList = customerStaffResult.getData(); |
|
|
|
// 禁用的给予提示
|
|
|
|
if("disabled".equals(customerStaffList.get(NumConstant.ZERO).getEnableFlag())){ |
|
|
|
throw new EpmetException(EpmetErrorCode.GOV_STAFF_DISABLED.getCode(),EpmetErrorCode.GOV_STAFF_DISABLED.getMsg(),EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
|
if ("disabled".equals(customerStaffList.get(NumConstant.ZERO).getEnableFlag())) { |
|
|
|
throw new EpmetException(EpmetErrorCode.GOV_STAFF_DISABLED.getCode(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg()); |
|
|
|
} |
|
|
|
//3、查询用户所有的组织信息
|
|
|
|
List<String> customerIdList = new ArrayList<>(); |
|
|
|
//是否设置过密码
|
|
|
|
boolean havePasswordFlag=false; |
|
|
|
boolean havePasswordFlag = false; |
|
|
|
//密码是否正确
|
|
|
|
boolean passwordRightFlag=false; |
|
|
|
boolean passwordRightFlag = false; |
|
|
|
for (CustomerStaffDTO customerStaffDTO : customerStaffList) { |
|
|
|
if(StringUtils.isNotBlank(customerStaffDTO.getPassword())){ |
|
|
|
havePasswordFlag=true; |
|
|
|
}else{ |
|
|
|
logger.warn(String.format("当前用户:手机号%s,客户Id%s下未设置密码.",formDTO.getMobile(),customerStaffDTO.getCustomerId())); |
|
|
|
if (StringUtils.isNotBlank(customerStaffDTO.getPassword())) { |
|
|
|
havePasswordFlag = true; |
|
|
|
} else { |
|
|
|
logger.warn(String.format("当前用户:手机号%s,客户Id%s下未设置密码.", formDTO.getMobile(), customerStaffDTO.getCustomerId())); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!PasswordUtils.matches(formDTO.getPassword(), customerStaffDTO.getPassword())) { |
|
|
|
logger.warn(String.format("当前用户:手机号%s,客户Id%s密码匹配错误.",formDTO.getMobile(),customerStaffDTO.getCustomerId())); |
|
|
|
logger.warn(String.format("当前用户:手机号%s,客户Id%s密码匹配错误.", formDTO.getMobile(), customerStaffDTO.getCustomerId())); |
|
|
|
|
|
|
|
}else{ |
|
|
|
logger.warn(String.format("当前用户:手机号%s,客户Id%s密码匹配正确.",formDTO.getMobile(),customerStaffDTO.getCustomerId())); |
|
|
|
passwordRightFlag=true; |
|
|
|
} else { |
|
|
|
logger.warn(String.format("当前用户:手机号%s,客户Id%s密码匹配正确.", formDTO.getMobile(), customerStaffDTO.getCustomerId())); |
|
|
|
passwordRightFlag = true; |
|
|
|
customerIdList.add(customerStaffDTO.getCustomerId()); |
|
|
|
} |
|
|
|
} |
|
|
|
//根据手机号查出来所有用户,密码都为空,表明用户未激活账户,未设置密码
|
|
|
|
if(!havePasswordFlag){ |
|
|
|
logger.warn(String.format("当前手机号(%s)下所有账户都未设置密码,请先使用验证码登录激活账户",formDTO.getMobile())); |
|
|
|
if (!havePasswordFlag) { |
|
|
|
logger.warn(String.format("当前手机号(%s)下所有账户都未设置密码,请先使用验证码登录激活账户", formDTO.getMobile())); |
|
|
|
throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); |
|
|
|
} |
|
|
|
//密码错误
|
|
|
|
if(!passwordRightFlag){ |
|
|
|
logger.warn(String.format("根据当前手机号(%s)密码未找到所属组织,密码错误",formDTO.getMobile())); |
|
|
|
if (!passwordRightFlag) { |
|
|
|
logger.warn(String.format("根据当前手机号(%s)密码未找到所属组织,密码错误", formDTO.getMobile())); |
|
|
|
throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); |
|
|
|
} |
|
|
|
StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); |
|
|
|
staffOrgFormDTO.setCustomerIdList(customerIdList); |
|
|
|
Result<List<StaffOrgsResultDTO>> result = govOrgOpenFeignClient.getStaffOrgList(staffOrgFormDTO); |
|
|
|
if(result.success()&&null!=result.getData()){ |
|
|
|
if (result.success() && null != result.getData()) { |
|
|
|
return result.getData(); |
|
|
|
} |
|
|
|
logger.warn(String .format("手机验证码获取组织,调用%s服务失败,入参手机号%s,密码%s,返回错误码%s,错误提示信息%s", |
|
|
|
logger.warn(String.format("手机验证码获取组织,调用%s服务失败,入参手机号%s,密码%s,返回错误码%s,错误提示信息%s", |
|
|
|
ServiceConstant.GOV_ORG_SERVER, |
|
|
|
formDTO.getMobile(), |
|
|
|
formDTO.getPassword(), |
|
|
@ -660,46 +695,46 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
throw new RenException(customerStaffResult.getCode()); |
|
|
|
} |
|
|
|
//2、密码是否正确
|
|
|
|
List<CustomerStaffDTO> customerStaffList=customerStaffResult.getData(); |
|
|
|
List<CustomerStaffDTO> customerStaffList = customerStaffResult.getData(); |
|
|
|
//3、查询用户所有的组织信息
|
|
|
|
List<String> customerIdList = new ArrayList<>(); |
|
|
|
//是否设置过密码
|
|
|
|
boolean havePasswordFlag=false; |
|
|
|
boolean havePasswordFlag = false; |
|
|
|
//密码是否正确
|
|
|
|
boolean passwordRightFlag=false; |
|
|
|
boolean passwordRightFlag = false; |
|
|
|
for (CustomerStaffDTO customerStaffDTO : customerStaffList) { |
|
|
|
if(StringUtils.isNotBlank(customerStaffDTO.getPassword())){ |
|
|
|
havePasswordFlag=true; |
|
|
|
}else{ |
|
|
|
logger.warn(String.format("当前用户:账户%s,客户Id%s下未设置密码.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); |
|
|
|
if (StringUtils.isNotBlank(customerStaffDTO.getPassword())) { |
|
|
|
havePasswordFlag = true; |
|
|
|
} else { |
|
|
|
logger.warn(String.format("当前用户:账户%s,客户Id%s下未设置密码.", formDTO.getUserAccount(), customerStaffDTO.getCustomerId())); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!PasswordUtils.matches(formDTO.getPassword(), customerStaffDTO.getPassword())) { |
|
|
|
logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配错误.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); |
|
|
|
logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配错误.", formDTO.getUserAccount(), customerStaffDTO.getCustomerId())); |
|
|
|
|
|
|
|
}else{ |
|
|
|
logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配正确.",formDTO.getUserAccount(),customerStaffDTO.getCustomerId())); |
|
|
|
passwordRightFlag=true; |
|
|
|
} else { |
|
|
|
logger.warn(String.format("当前用户:账户%s,客户Id%s密码匹配正确.", formDTO.getUserAccount(), customerStaffDTO.getCustomerId())); |
|
|
|
passwordRightFlag = true; |
|
|
|
customerIdList.add(customerStaffDTO.getCustomerId()); |
|
|
|
} |
|
|
|
} |
|
|
|
//根据手机号查出来所有用户,密码都为空,表明用户未激活账户,未设置密码
|
|
|
|
if(!havePasswordFlag){ |
|
|
|
logger.warn(String.format("当前账户(%s)下所有账户都未设置密码,请先使用验证码登录激活账户",formDTO.getUserAccount())); |
|
|
|
if (!havePasswordFlag) { |
|
|
|
logger.warn(String.format("当前账户(%s)下所有账户都未设置密码,请先使用验证码登录激活账户", formDTO.getUserAccount())); |
|
|
|
throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); |
|
|
|
} |
|
|
|
//密码错误
|
|
|
|
if(!passwordRightFlag){ |
|
|
|
logger.warn(String.format("根据当前账户(%s)密码未找到所属组织,密码错误",formDTO.getUserAccount())); |
|
|
|
if (!passwordRightFlag) { |
|
|
|
logger.warn(String.format("根据当前账户(%s)密码未找到所属组织,密码错误", formDTO.getUserAccount())); |
|
|
|
throw new RenException(EpmetErrorCode.PASSWORD_ERROR.getCode()); |
|
|
|
} |
|
|
|
StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); |
|
|
|
staffOrgFormDTO.setCustomerIdList(customerIdList); |
|
|
|
Result<List<StaffOrgsResultDTO>> result = govOrgOpenFeignClient.getStaffOrgList(staffOrgFormDTO); |
|
|
|
if(result.success()&&null!=result.getData()){ |
|
|
|
if (result.success() && null != result.getData()) { |
|
|
|
return result.getData(); |
|
|
|
} |
|
|
|
logger.warn(String .format("手机验证码获取组织,调用%s服务失败,入参账户%s,密码%s,返回错误码%s,错误提示信息%s", |
|
|
|
logger.warn(String.format("手机验证码获取组织,调用%s服务失败,入参账户%s,密码%s,返回错误码%s,错误提示信息%s", |
|
|
|
ServiceConstant.GOV_ORG_SERVER, |
|
|
|
formDTO.getUserAccount(), |
|
|
|
formDTO.getPassword(), |
|
|
@ -709,14 +744,14 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取客户信息 |
|
|
|
* @param appId |
|
|
|
* @Description 获取客户信息 |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public PaCustomerDTO getCustomerInfo(String appId){ |
|
|
|
public PaCustomerDTO getCustomerInfo(String appId) { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(AuthHttpUrlConstant.CUSTOMER_MSG_URL + appId, JSON.toJSONString(jsonObject)).getData(); |
|
|
|
logger.info("ThirdLoginServiceImpl.getCustomerInfo:httpclient->url:"+AuthHttpUrlConstant.CUSTOMER_MSG_URL+",结果->"+data); |
|
|
|
logger.info("ThirdLoginServiceImpl.getCustomerInfo:httpclient->url:" + AuthHttpUrlConstant.CUSTOMER_MSG_URL + ",结果->" + data); |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
Result mapToResult = ConvertUtils.mapToEntity(toResult, Result.class); |
|
|
|
if (null != toResult.get("code")) { |
|
|
@ -728,20 +763,20 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
} |
|
|
|
Object PublicCustomerResultDTO = mapToResult.getData(); |
|
|
|
JSONObject json = JSON.parseObject(PublicCustomerResultDTO.toString()); |
|
|
|
Map<String,Object> map = (Map)json.get("customer"); |
|
|
|
Map<String, Object> map = (Map) json.get("customer"); |
|
|
|
PaCustomerDTO customer = ConvertUtils.mapToEntity(map, PaCustomerDTO.class); |
|
|
|
logger.info("小程序登陆third服务获取客户用户信息PaCustomerDTO->"+customer); |
|
|
|
logger.info("小程序登陆third服务获取客户用户信息PaCustomerDTO->" + customer); |
|
|
|
return customer; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取UserWechatDTO |
|
|
|
* @param resiLoginFormDTO |
|
|
|
* @Description 获取UserWechatDTO |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public UserWechatDTO getUserWeChat(WxLoginFormDTO resiLoginFormDTO){ |
|
|
|
public UserWechatDTO getUserWeChat(WxLoginFormDTO resiLoginFormDTO) { |
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(AuthHttpUrlConstant.RESI_AND_WORK_LOGIN_URL, JSON.toJSONString(resiLoginFormDTO)).getData(); |
|
|
|
logger.info("ThirdLoginServiceImpl.getUserWeChat:httpclient->url:"+AuthHttpUrlConstant.RESI_AND_WORK_LOGIN_URL+",结果->"+data); |
|
|
|
logger.info("ThirdLoginServiceImpl.getUserWeChat:httpclient->url:" + AuthHttpUrlConstant.RESI_AND_WORK_LOGIN_URL + ",结果->" + data); |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
Result mapToResult = ConvertUtils.mapToEntity(toResult, Result.class); |
|
|
|
if (null != toResult.get("code")) { |
|
|
@ -754,7 +789,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
Object UserWeChatDTO = mapToResult.getData(); |
|
|
|
JSONObject json = JSON.parseObject(UserWeChatDTO.toString()); |
|
|
|
UserWechatDTO userWechatDTO = ConvertUtils.mapToEntity(json, UserWechatDTO.class); |
|
|
|
logger.info("小程序登陆third服务获取微信用户信息userWechatDTO->"+userWechatDTO); |
|
|
|
logger.info("小程序登陆third服务获取微信用户信息userWechatDTO->" + userWechatDTO); |
|
|
|
return userWechatDTO; |
|
|
|
} |
|
|
|
|
|
|
@ -837,13 +872,13 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 发送登录事件 |
|
|
|
* @return |
|
|
|
* @Description 发送登录事件 |
|
|
|
* @author wxz |
|
|
|
* @date 2021.06.08 15:27 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void sendLoginEvent(String userId, String appId, String fromApp, String fromClient,String messageType) { |
|
|
|
public void sendLoginEvent(String userId, String appId, String fromApp, String fromClient, String messageType) { |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
|
|
|
|
LoginMQMsg loginMQMsg = new LoginMQMsg(); |
|
|
@ -869,6 +904,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
// (2)通过1、2拿到手机号之后,根据mobile+customerId去user_base_info表找userId,
|
|
|
|
// 是否注册居民:register_relation
|
|
|
|
// (3)没有则生成user、user_Base_info表记录
|
|
|
|
|
|
|
|
/** |
|
|
|
* 钉钉应用的登录-居民端 |
|
|
|
* |
|
|
@ -878,8 +914,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
@Override |
|
|
|
public ResiDingAppLoginResDTO resiLoginDing(ResiDingAppLoginFormDTO formDTO) { |
|
|
|
//获取用户手机号
|
|
|
|
log.info("1、钉钉居民端应用登录入参:"+ JSON.toJSONString(formDTO)); |
|
|
|
ResiDingAppLoginResDTO resDTO= null; |
|
|
|
log.info("1、钉钉居民端应用登录入参:" + JSON.toJSONString(formDTO)); |
|
|
|
ResiDingAppLoginResDTO resDTO = null; |
|
|
|
try { |
|
|
|
resDTO = new ResiDingAppLoginResDTO(); |
|
|
|
resDTO.setCustomerId(getCurrentCustomerId()); |
|
|
@ -887,19 +923,19 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
String miniAppId = formDTO.getMiniAppId(); |
|
|
|
DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(miniAppId); |
|
|
|
DingTalkResult<AccessTokenResult> userAccessToken = dingTalkClientToken.getUserAccessToken(formDTO.getAuthCode(), dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret()); |
|
|
|
log.info("2、resiLoginDing userAccessToken:{}",JSON.toJSONString(userAccessToken)); |
|
|
|
log.info("2、resiLoginDing userAccessToken:{}", JSON.toJSONString(userAccessToken)); |
|
|
|
if (!userAccessToken.success() || null == userAccessToken.getData()) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "调用微信api异常:" + JSON.toJSONString(userAccessToken), EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getMsg()); |
|
|
|
} |
|
|
|
DingTalkResult<UserBaseInfo> me = dingTalkClientUser.getUserInfo("me", userAccessToken.getData().getAccessToken()); |
|
|
|
log.info("3、resiLoginDing me:{}",JSON.toJSONString(me)); |
|
|
|
log.info("3、resiLoginDing me:{}", JSON.toJSONString(me)); |
|
|
|
resDTO.setExtInfo(JSON.toJSONString(me.getData())); |
|
|
|
if (!me.success() || StringUtils.isBlank(me.getData().getMobile())) { |
|
|
|
log.error("resilogin-ding登录接口报错,入参:" + JSON.toJSONString(formDTO) + ";获取手机号为空, userAccessToken.getData().getAccessToken()=" + userAccessToken.getData().getAccessToken()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取手机号为空", "获取手机号为空"); |
|
|
|
} |
|
|
|
// 2、调用userfeign接口获取userId、注册网格相关信息 todo
|
|
|
|
DingLoginResiFormDTO dingLoginResiFormDTO=ConvertUtils.sourceToTarget(me.getData(),DingLoginResiFormDTO.class); |
|
|
|
DingLoginResiFormDTO dingLoginResiFormDTO = ConvertUtils.sourceToTarget(me.getData(), DingLoginResiFormDTO.class); |
|
|
|
dingLoginResiFormDTO.setCustomerId(resDTO.getCustomerId()); |
|
|
|
Result<DingLoginResiResDTO> loginResiResDTOResult = epmetUserOpenFeignClient.dingResiLogin(dingLoginResiFormDTO); |
|
|
|
if (!loginResiResDTOResult.success() || null == loginResiResDTOResult.getData()) { |
|
|
@ -907,7 +943,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
log.error(String.format("resilogin-ding获取epmetUserId异常,入参:%s,user服务返参:%s", JSON.toJSONString(formDTO), JSON.toJSONString(loginResiResDTOResult))); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取epmetUserId异常:" + JSON.toJSONString(loginResiResDTOResult), EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getMsg()); |
|
|
|
} |
|
|
|
DingLoginResiResDTO resiResDTO=loginResiResDTOResult.getData(); |
|
|
|
DingLoginResiResDTO resiResDTO = loginResiResDTOResult.getData(); |
|
|
|
resDTO.setGridId(resiResDTO.getGridId()); |
|
|
|
resDTO.setGridName(resiResDTO.getGridName()); |
|
|
|
resDTO.setAgencyId(resiResDTO.getAgencyId()); |
|
|
@ -915,7 +951,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
resDTO.setRegFlag(resiResDTO.getRegFlag()); |
|
|
|
|
|
|
|
//3.生成token,并且存放Redis
|
|
|
|
String token=this.saveTokenDtoDing(formDTO.getMiniAppId(),AppClientConstant.APP_RESI,AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); |
|
|
|
String token = this.saveTokenDtoDing(formDTO.getMiniAppId(), AppClientConstant.APP_RESI, AppClientConstant.MINI_DING, resDTO.getEpmetUserId(), resDTO.getCustomerId()); |
|
|
|
resDTO.setAuthorization(token); |
|
|
|
|
|
|
|
} catch (ApiException e) { |
|
|
@ -924,7 +960,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
return resDTO; |
|
|
|
} |
|
|
|
|
|
|
|
private String saveTokenDtoDing(String miniAppId,String app,String client, String userId,String customerId) { |
|
|
|
private String saveTokenDtoDing(String miniAppId, String app, String client, String userId, String customerId) { |
|
|
|
//生成token串
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put(AppClientConstant.APP, app); |
|
|
@ -1032,16 +1068,16 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
* 企业内部应用开发,不授权了 |
|
|
|
* https://open.dingtalk.com/document/orgapp-server/enterprise-internal-application-logon-free
|
|
|
|
* 建议用户信息保存在前端缓存中(dd.setStorage)或者cookie中,避免每次进入应用都调用钉钉接口进行免登。 |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 获取免登授权码。 |
|
|
|
* 小程序免登 |
|
|
|
* 微应用免登 |
|
|
|
* 获取AccessToken。 |
|
|
|
* 调用接口获取access_token,详情请参考获取企业内部应用的access_token。 |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 获取userid。 |
|
|
|
* 调用接口获取用户的userid,详情请参考通过免登码获取用户信息。 |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 获取用户详情。 |
|
|
|
* 调用接口获取用户详细信息,详情请参考根据userId获取用户详情。 |
|
|
|
* |
|
|
@ -1064,7 +1100,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
if (!loginResiResDTOResult.success() || null == loginResiResDTOResult.getData()) { |
|
|
|
// 临时打个日志
|
|
|
|
log.error(String.format("resiLoginInternalDing获取epmetUserId异常,入参:%s", JSON.toJSONString(dingLoginResiFormDTO))); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取epmetUserId异常:"+ JSON.toJSONString(loginResiResDTOResult), "获取epmetUserId异常"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取epmetUserId异常:" + JSON.toJSONString(loginResiResDTOResult), "获取epmetUserId异常"); |
|
|
|
} |
|
|
|
DingLoginResiResDTO resiResDTO = loginResiResDTOResult.getData(); |
|
|
|
resDTO.setGridId(resiResDTO.getGridId()); |
|
|
@ -1103,8 +1139,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
@Override |
|
|
|
public UserTokenResultDTO yanTaiSSOLogin(String authCode) { |
|
|
|
YantaiSSOUser ssoUserInfo = YantaiApi.getLoginToken(authCode); |
|
|
|
if (ssoUserInfo== null){ |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"登录失败-sso获取用户失败","登录失败-sso获取用户失败"); |
|
|
|
if (ssoUserInfo == null) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "登录失败-sso获取用户失败", "登录失败-sso获取用户失败"); |
|
|
|
} |
|
|
|
|
|
|
|
GovWebLoginFormDTO loginGovParam = new GovWebLoginFormDTO(); |
|
|
@ -1116,13 +1152,14 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
|
|
|
|
/** |
|
|
|
* 最原始的企业内部应用开发,不授权给产品服务商 |
|
|
|
* |
|
|
|
* @param miniAppId |
|
|
|
* @param authCode |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private DingLoginResiFormDTO getDingLoginResiFormDTOInternal(String miniAppId, String authCode) { |
|
|
|
DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(miniAppId); |
|
|
|
if (dingMiniInfo == null){ |
|
|
|
if (dingMiniInfo == null) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉应用配置异常", "获取钉钉应用配置异常"); |
|
|
|
} |
|
|
|
// 1、获取企业内部应用的accessToken文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-access_token-of-an-internal-app
|
|
|
@ -1172,20 +1209,21 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
|
|
|
|
/** |
|
|
|
* 客户写死吧 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String getCurrentCustomerId() { |
|
|
|
String customerId=""; |
|
|
|
String customerId = ""; |
|
|
|
EnvEnum currentEnv = EnvEnum.getCurrentEnv(); |
|
|
|
if (EnvEnum.PROD.getCode().equals(currentEnv.getCode())) { |
|
|
|
// 烟台的客户id
|
|
|
|
customerId="1535072605621841922"; |
|
|
|
customerId = "1535072605621841922"; |
|
|
|
} else if (EnvEnum.TEST.getCode().equals(currentEnv.getCode())) { |
|
|
|
// 最美琴岛
|
|
|
|
customerId="0c41b272ee9ee95ac6f184ad548a30eb"; |
|
|
|
customerId = "0c41b272ee9ee95ac6f184ad548a30eb"; |
|
|
|
} else { |
|
|
|
// 其余统一走开发环境
|
|
|
|
customerId="45687aa479955f9d06204d415238f7cc"; |
|
|
|
customerId = "45687aa479955f9d06204d415238f7cc"; |
|
|
|
} |
|
|
|
return customerId; |
|
|
|
} |
|
|
|