|
|
@ -3,19 +3,20 @@ package com.epmet.service.impl; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.epmet.commons.thirdplat.apiservice.AbstractApiService; |
|
|
|
import com.epmet.commons.thirdplat.apiservice.jcet.JcetApiService; |
|
|
|
import com.epmet.commons.thirdplat.constants.ApiServiceBeansConstants; |
|
|
|
import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; |
|
|
|
import com.epmet.commons.thirdplat.bean.ThirdPlatUserInfo; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.*; |
|
|
|
import com.epmet.constant.SsoConstant; |
|
|
|
import com.epmet.dto.PaCustomerDTO; |
|
|
|
import com.epmet.dto.UserDTO; |
|
|
|
import com.epmet.dto.form.ApiServiceFormDTO; |
|
|
|
import com.epmet.dto.form.SsoLoginFormDTO; |
|
|
|
import com.epmet.dto.form.UserInfoFormDTO; |
|
|
|
import com.epmet.dto.result.SsoLoginResultDTO; |
|
|
|
import com.epmet.dto.result.ThirdplatApiserviceResultDTO; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.feign.OperCrmOpenFeignClient; |
|
|
|
import com.epmet.jwt.JwtTokenProperties; |
|
|
|
import com.epmet.jwt.JwtTokenUtils; |
|
|
|
import com.epmet.redis.SsoRedis; |
|
|
@ -27,7 +28,6 @@ import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
@ -53,6 +53,9 @@ public class SsoServiceImpl implements SsoService { |
|
|
|
@Autowired |
|
|
|
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 0、入口:得到token |
|
|
|
* @Param formDTO |
|
|
@ -61,39 +64,51 @@ public class SsoServiceImpl implements SsoService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public SsoLoginResultDTO ssoLogin(SsoLoginFormDTO formDTO) { |
|
|
|
String customerId = getCustomerId(formDTO.getAppId()); |
|
|
|
String userId = ""; |
|
|
|
if (formDTO.getAppId().equals(SsoConstant.WINE_CITY_E_OPEN_APP_ID)) { |
|
|
|
UserInfoResultDTO userInfo = null; |
|
|
|
try { |
|
|
|
AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(ApiServiceBeansConstants.JCET_API_SERVICE); |
|
|
|
userInfo = apiService.getUserInfoByTicket(formDTO.getTicket()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("调用第三方平台,根据用户ticket查询用户信息失败,错误信息"); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
if (null == userInfo){ |
|
|
|
throw new RenException(SsoConstant.USER_INFO_IS_NULL); |
|
|
|
} |
|
|
|
UserInfoFormDTO userInfoFormDTO = ConvertUtils.sourceToTarget(userInfo, UserInfoFormDTO.class); |
|
|
|
userInfoFormDTO.setApp(formDTO.getApp()); |
|
|
|
userInfoFormDTO.setUid(userInfo.getId()); |
|
|
|
userInfoFormDTO.setName(userInfo.getName()); |
|
|
|
userInfoFormDTO.setMobile(userInfo.getMobile()); |
|
|
|
Result<UserDTO> userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); |
|
|
|
if (!userDTOResult.success()){ |
|
|
|
throw new RenException(SsoConstant.INSERT_UPDATE_USER_FAILURE); |
|
|
|
} |
|
|
|
userId = userDTOResult.getData().getId(); |
|
|
|
|
|
|
|
Result<ThirdplatApiserviceResultDTO> apiServiceResult = operCrmOpenFeignClient.getApiServiceByCustomerId(new ApiServiceFormDTO(customerId)); |
|
|
|
if (!apiServiceResult.success()) { |
|
|
|
throw new RenException("【SSO登录】调用OperCrm获取ApiService接口失败:", apiServiceResult.getInternalMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
if (apiServiceResult.getData() == null || StringUtils.isBlank(apiServiceResult.getData().getApiServiceName())) { |
|
|
|
throw new RenException("【SSO登录】调用OperCrm获取ApiService,查询到的结果为空:", apiServiceResult.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
ThirdPlatUserInfo userInfo; |
|
|
|
try { |
|
|
|
AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(apiServiceResult.getData().getApiServiceName()); |
|
|
|
userInfo = apiService.getUserInfoByTicket(formDTO.getTicket()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RenException(e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
if (null == userInfo){ |
|
|
|
throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), |
|
|
|
"【SSO登录】调用第三方平台查询用户信息失败,用户信息为空"); |
|
|
|
} |
|
|
|
UserInfoFormDTO userInfoFormDTO = new UserInfoFormDTO(); |
|
|
|
userInfoFormDTO.setApp(formDTO.getApp()); |
|
|
|
userInfoFormDTO.setUid(userInfo.getOpenId()); |
|
|
|
userInfoFormDTO.setName(userInfo.getName()); |
|
|
|
userInfoFormDTO.setMobile(userInfo.getMobile()); |
|
|
|
|
|
|
|
Result<UserDTO> userDTOResult = epmetUserOpenFeignClient.saveUserInfo(userInfoFormDTO); |
|
|
|
if (!userDTOResult.success()){ |
|
|
|
throw new RenException("【SSO登录】新增或更新user_weChat失败"); |
|
|
|
} |
|
|
|
userId = userDTOResult.getData().getId(); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(userId)){ |
|
|
|
throw new RenException(SsoConstant.USER_ID_IS_NULL); |
|
|
|
throw new RenException("【SSO登录】userId为空,生成token失败"); |
|
|
|
} |
|
|
|
//生成业务token
|
|
|
|
String token = this.generateToken(formDTO.getApp(),formDTO.getClient(), userId); |
|
|
|
//存放Redis
|
|
|
|
String customerId = getCustomerId(formDTO.getAppId()); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(customerId)){ |
|
|
|
throw new RenException(SsoConstant.CUSTOMER_ID_IS_NULL); |
|
|
|
throw new RenException("【SSO登录】customerId为空,缓存放置token失败"); |
|
|
|
} |
|
|
|
this.disposeTokenDto(formDTO, userId, token, customerId); |
|
|
|
return new SsoLoginResultDTO(token); |
|
|
|