|
@ -10,11 +10,13 @@ import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.utils.*; |
|
|
import com.epmet.commons.tools.utils.*; |
|
|
import com.epmet.dto.PaCustomerDTO; |
|
|
import com.epmet.dto.PaCustomerDTO; |
|
|
import com.epmet.dto.UserDTO; |
|
|
import com.epmet.dto.UserDTO; |
|
|
import com.epmet.dto.form.ApiServiceFormDTO; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.SsoLoginFormDTO; |
|
|
import com.epmet.dto.result.GovWebOperLoginResultDTO; |
|
|
import com.epmet.dto.form.UserInfoFormDTO; |
|
|
|
|
|
import com.epmet.dto.result.SsoLoginResultDTO; |
|
|
import com.epmet.dto.result.SsoLoginResultDTO; |
|
|
import com.epmet.dto.result.ThirdplatApiserviceResultDTO; |
|
|
import com.epmet.dto.result.ThirdplatApiserviceResultDTO; |
|
|
|
|
|
import com.epmet.dto.result.UserTokenResultDTO; |
|
|
|
|
|
import com.epmet.enums.ThirdPlatformEnum; |
|
|
|
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.OperCrmOpenFeignClient; |
|
|
import com.epmet.feign.OperCrmOpenFeignClient; |
|
|
import com.epmet.jwt.JwtTokenProperties; |
|
|
import com.epmet.jwt.JwtTokenProperties; |
|
@ -22,12 +24,14 @@ import com.epmet.jwt.JwtTokenUtils; |
|
|
import com.epmet.redis.SsoRedis; |
|
|
import com.epmet.redis.SsoRedis; |
|
|
import com.epmet.service.SsoService; |
|
|
import com.epmet.service.SsoService; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@ -56,8 +60,11 @@ public class SsoServiceImpl implements SsoService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private EpmetUserFeignClient epmetUserFeignClient; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description 0、入口:得到token |
|
|
* @Description 0、入口:得到token |
|
|
* @Param formDTO |
|
|
* @Param formDTO |
|
|
* @author zxc |
|
|
* @author zxc |
|
|
* @date 2021/1/18 下午4:59 |
|
|
* @date 2021/1/18 下午4:59 |
|
@ -104,18 +111,60 @@ public class SsoServiceImpl implements SsoService { |
|
|
throw new RenException("【SSO登录】userId为空,生成token失败"); |
|
|
throw new RenException("【SSO登录】userId为空,生成token失败"); |
|
|
} |
|
|
} |
|
|
//生成业务token
|
|
|
//生成业务token
|
|
|
String token = this.generateToken(formDTO.getApp(),formDTO.getClient(), userId); |
|
|
String token = this.generateToken(formDTO.getApp(), formDTO.getClient(), userId); |
|
|
//存放Redis
|
|
|
//存放Redis
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(customerId)){ |
|
|
if (StringUtils.isBlank(customerId)) { |
|
|
throw new RenException("【SSO登录】customerId为空,缓存放置token失败"); |
|
|
throw new RenException("【SSO登录】customerId为空,缓存放置token失败"); |
|
|
} |
|
|
} |
|
|
this.disposeTokenDto(formDTO, userId, token, customerId); |
|
|
this.disposeTokenDto(formDTO.getApp(), formDTO.getClient(), userId, token, customerId); |
|
|
return new SsoLoginResultDTO(token); |
|
|
return new SsoLoginResultDTO(token); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public UserTokenResultDTO thirdLoginOper(SsoLoginOperFormDTO formDTO) { |
|
|
|
|
|
ThirdPlatUserInfo thirdUser; |
|
|
|
|
|
try { |
|
|
|
|
|
ThirdPlatformEnum platformEnum = ThirdPlatformEnum.getEnum(formDTO.getPlatform()); |
|
|
|
|
|
String apiService = platformEnum.getApiService(); |
|
|
|
|
|
AbstractApiService apiServiceImpl = (AbstractApiService) SpringContextUtils.getBean(apiService); |
|
|
|
|
|
thirdUser = apiServiceImpl.getUserInfoByTicket(formDTO.getThirdToken()); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
throw new RenException(e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
//获取用户信息
|
|
|
|
|
|
GovWebOperLoginFormDTO form = new GovWebOperLoginFormDTO(); |
|
|
|
|
|
form.setCustomerId(thirdUser.getCustomerId()); |
|
|
|
|
|
form.setMobile(thirdUser.getMobile()); |
|
|
|
|
|
Result<GovWebOperLoginResultDTO> result = epmetUserFeignClient.getStaffIdAndPwd(form); |
|
|
|
|
|
//todo userId 写死测试 3f7f852ce22c511aa67ecb695395295d start
|
|
|
|
|
|
GovWebOperLoginResultDTO demo = new GovWebOperLoginResultDTO(); |
|
|
|
|
|
demo.setUserId("3f7f852ce22c511aa67ecb695395295d"); |
|
|
|
|
|
result = new Result<>(); |
|
|
|
|
|
result.ok(demo); |
|
|
|
|
|
//test end
|
|
|
|
|
|
|
|
|
|
|
|
if (!result.success() || null == result.getData() || null == result.getData().getUserId()) { |
|
|
|
|
|
logger.error("根据手机号查询PC工作端登陆人员信息失败,返回10003账号不存在"); |
|
|
|
|
|
throw new RenException(EpmetErrorCode.ERR10003.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//4、生成token返回,且将TokenDto存到redis
|
|
|
|
|
|
//生成业务token
|
|
|
|
|
|
GovWebOperLoginResultDTO epmetUser = result.getData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String token = this.generateToken(formDTO.getApp(), formDTO.getClient(), epmetUser.getUserId()); |
|
|
|
|
|
//存放Redis
|
|
|
|
|
|
|
|
|
|
|
|
this.disposeTokenDto(formDTO.getApp(), formDTO.getClient(), epmetUser.getUserId(), token, thirdUser.getCustomerId()); |
|
|
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
|
|
return userTokenResultDTO; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description token放缓存 |
|
|
* @Description token放缓存 |
|
|
* @Param formDTO |
|
|
* @Param formDTO |
|
|
* @Param userId |
|
|
* @Param userId |
|
|
* @Param token |
|
|
* @Param token |
|
@ -123,12 +172,12 @@ public class SsoServiceImpl implements SsoService { |
|
|
* @author zxc |
|
|
* @author zxc |
|
|
* @date 2021/1/18 下午5:32 |
|
|
* @date 2021/1/18 下午5:32 |
|
|
*/ |
|
|
*/ |
|
|
public void disposeTokenDto(SsoLoginFormDTO formDTO, String userId, String token, String customerId){ |
|
|
public void disposeTokenDto(String app, String client, String userId, String token, String customerId) { |
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
TokenDto tokenDto = new TokenDto(); |
|
|
TokenDto tokenDto = new TokenDto(); |
|
|
tokenDto.setCustomerId(customerId); |
|
|
tokenDto.setCustomerId(customerId); |
|
|
tokenDto.setApp(formDTO.getApp()); |
|
|
tokenDto.setApp(app); |
|
|
tokenDto.setClient(formDTO.getClient()); |
|
|
tokenDto.setClient(client); |
|
|
tokenDto.setUserId(userId); |
|
|
tokenDto.setUserId(userId); |
|
|
tokenDto.setToken(token); |
|
|
tokenDto.setToken(token); |
|
|
tokenDto.setUpdateTime(System.currentTimeMillis()); |
|
|
tokenDto.setUpdateTime(System.currentTimeMillis()); |
|
@ -145,7 +194,7 @@ public class SsoServiceImpl implements SsoService { |
|
|
* @author zxc |
|
|
* @author zxc |
|
|
* @date 2021/1/18 下午5:14 |
|
|
* @date 2021/1/18 下午5:14 |
|
|
*/ |
|
|
*/ |
|
|
private String generateToken(String app,String client, String userId) { |
|
|
private String generateToken(String app, String client, String userId) { |
|
|
Map<String, Object> map = new HashMap<>(16); |
|
|
Map<String, Object> map = new HashMap<>(16); |
|
|
map.put("app", app); |
|
|
map.put("app", app); |
|
|
map.put("client", client); |
|
|
map.put("client", client); |
|
@ -182,4 +231,25 @@ public class SsoServiceImpl implements SsoService { |
|
|
log.info("小程序登陆third服务获取客户用户信息PaCustomerDTO->" + customer); |
|
|
log.info("小程序登陆third服务获取客户用户信息PaCustomerDTO->" + customer); |
|
|
return customer.getId(); |
|
|
return customer.getId(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
String url = "https://epmet-ext9.elinkservice.cn/platform/unifiedAuth/loginCheck"; |
|
|
|
|
|
String platformToken = "1348803062424166401_dd08e23b0d524879a5c67e7f2ffd1468"; |
|
|
|
|
|
String appId = "7a5aec009ba4eba8e254ee64fe3775e1"; |
|
|
|
|
|
String appKey = "14faef9af508d1c253b720ea5a43f9de"; |
|
|
|
|
|
String appSecret = "38e7c2604c8dd33c445705d25eebbfc12a2f7ed8a87111e9e10a40312d3a1595"; |
|
|
|
|
|
long ts = System.currentTimeMillis(); |
|
|
|
|
|
String message = appId + appKey + appSecret + ts; |
|
|
|
|
|
String accessToken = DigestUtils.md5Hex(message.getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
//ThirdPlatformEnum platformEnum = ThirdPlatformEnum.getEnum("pyld");
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
|
jsonObject.put("platformToken", platformToken); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> headerMap = new HashMap<>(4); |
|
|
|
|
|
headerMap.put("AppKey", appKey); |
|
|
|
|
|
headerMap.put("Timestamp", ts); |
|
|
|
|
|
headerMap.put("AccessToken", accessToken); |
|
|
|
|
|
Result<String> stringResult = HttpClientManager.getInstance().sendPost(url, url.startsWith("https://"), jsonObject.toJSONString(), headerMap); |
|
|
|
|
|
System.out.println(stringResult); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|