Browse Source

增加G端ssotoken登录

修改G端登录接口
dev_shibei_match
wxz 5 years ago
parent
commit
95d13b3d5f
  1. 7
      epmet-auth/src/main/java/com/epmet/controller/SsoController.java
  2. 42
      epmet-auth/src/main/java/com/epmet/dto/form/SsoWorkLoginFormDTO.java
  3. 3
      epmet-auth/src/main/java/com/epmet/service/SsoService.java
  4. 10
      epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java
  5. 10
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java
  6. 45
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java
  7. 2
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetCUserInfoResultDTO.java
  8. 25
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetGUserInfoResultDTO.java

7
epmet-auth/src/main/java/com/epmet/controller/SsoController.java

@ -6,6 +6,7 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.SsoEnteOrgFormDTO;
import com.epmet.dto.form.SsoLoginFormDTO;
import com.epmet.dto.form.SsoWorkLoginFormDTO;
import com.epmet.dto.result.SsoLoginResultDTO;
import com.epmet.dto.result.UserTokenResultDTO;
import com.epmet.service.SsoService;
@ -45,7 +46,7 @@ public class SsoController {
public Result<ThirdPlatUserInfo> testssoLogin(){
ThirdPlatUserInfo userInfoByTicket = null;
try {
userInfoByTicket = jcetApiService.getUserInfoByTicket("ssoTicket-vYtMRuXAQZri3wpA2vyq5D8n3Q9oO7ui");
userInfoByTicket = jcetApiService.getCUserInfoByTicket("ssoTicket-vYtMRuXAQZri3wpA2vyq5D8n3Q9oO7ui");
} catch (Exception e) {
e.printStackTrace();
}
@ -58,8 +59,8 @@ public class SsoController {
* @Description 1ticket自动登录获取内部token
**/
@PostMapping("work/login")
public Result<UserTokenResultDTO> ssoWorkLogin(@RequestBody SsoLoginFormDTO formDTO){
ValidatorUtils.validateEntity(formDTO, SsoLoginFormDTO.SsoLoginForm.class);
public Result<UserTokenResultDTO> ssoWorkLogin(@RequestBody SsoWorkLoginFormDTO formDTO){
ValidatorUtils.validateEntity(formDTO, SsoWorkLoginFormDTO.SsoLoginForm.class);
return new Result<UserTokenResultDTO>().ok(ssoService.ssoWorkLogin(formDTO));
}

42
epmet-auth/src/main/java/com/epmet/dto/form/SsoWorkLoginFormDTO.java

@ -0,0 +1,42 @@
package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2021/1/18 下午4:43
*/
@Data
public class SsoWorkLoginFormDTO implements Serializable {
private static final long serialVersionUID = -6543952487970013031L;
public interface SsoLoginForm{}
/**
* sso票据有效期为300秒
*/
@NotBlank(message = "ssotoken不能为空",groups = SsoLoginForm.class)
private String token;
/**
* 三方平台应用AppId
*/
@NotBlank(message = "三方平台应用AppId不能为空",groups = SsoLoginForm.class)
private String appId;
/**
* app类型 resi居民段gov工作端
*/
@NotBlank(message = "app不能为空",groups = SsoLoginForm.class)
private String app;
/**
* app居民段app工作端
*/
@NotBlank(message = "client不能为空",groups = SsoLoginForm.class)
private String client;
}

3
epmet-auth/src/main/java/com/epmet/service/SsoService.java

@ -2,6 +2,7 @@ package com.epmet.service;
import com.epmet.dto.form.SsoEnteOrgFormDTO;
import com.epmet.dto.form.SsoLoginFormDTO;
import com.epmet.dto.form.SsoWorkLoginFormDTO;
import com.epmet.dto.result.SsoLoginResultDTO;
import com.epmet.dto.result.UserTokenResultDTO;
@ -24,7 +25,7 @@ public interface SsoService {
* @Author sun
* @Description 1ticket自动登录获取内部token
**/
UserTokenResultDTO ssoWorkLogin(SsoLoginFormDTO formDTO);
UserTokenResultDTO ssoWorkLogin(SsoWorkLoginFormDTO formDTO);
/**
* @param formDTO

10
epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java

@ -75,6 +75,7 @@ public class SsoServiceImpl implements SsoService {
@Override
public SsoLoginResultDTO ssoLogin(SsoLoginFormDTO formDTO) {
String customerId = getCustomerId(formDTO.getAppId());
//String customerId = "3a4f923665a7a07701bcb311aac9a156";
String userId = "";
Result<ThirdplatApiserviceResultDTO> apiServiceResult = operCrmOpenFeignClient.getApiServiceByCustomerId(new ApiServiceFormDTO(customerId));
@ -89,7 +90,7 @@ public class SsoServiceImpl implements SsoService {
ThirdPlatUserInfo userInfo;
try {
AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(apiServiceResult.getData().getApiServiceName());
userInfo = apiService.getUserInfoByTicket(formDTO.getTicket());
userInfo = apiService.getCUserInfoByTicket(formDTO.getTicket());
} catch (Exception e) {
throw new RenException(e.getMessage());
}
@ -199,10 +200,11 @@ public class SsoServiceImpl implements SsoService {
* @Description 1ticket自动登录获取内部token
**/
@Override
public UserTokenResultDTO ssoWorkLogin(SsoLoginFormDTO formDTO) {
public UserTokenResultDTO ssoWorkLogin(SsoWorkLoginFormDTO formDTO) {
//1.根据appId查询客户id
String customerId = getCustomerId(formDTO.getAppId());
//String customerId = "3a4f923665a7a07701bcb311aac9a156";
//2.客户Id换取第三方apiService,根据ticket换取华为Id
Result<ThirdplatApiserviceResultDTO> apiServiceResult = operCrmOpenFeignClient.getApiServiceByCustomerId(new ApiServiceFormDTO(customerId));
@ -215,7 +217,7 @@ public class SsoServiceImpl implements SsoService {
ThirdPlatUserInfo userInfo;
try {
AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(apiServiceResult.getData().getApiServiceName());
userInfo = apiService.getUserInfoByTicket(formDTO.getTicket());
userInfo = apiService.getGUserInfoBySSOToken(formDTO.getToken());
} catch (Exception e) {
throw new RenException(e.getMessage());
}
@ -431,7 +433,7 @@ public class SsoServiceImpl implements SsoService {
ThirdPlatUserInfo userInfo;
try {
AbstractApiService apiService = (AbstractApiService) SpringContextUtils.getBean(apiServiceResult.getData().getApiServiceName());
userInfo = apiService.getUserInfoByTicket(formDTO.getTicket());
userInfo = apiService.getGUserInfoBySSOToken(formDTO.getTicket());
} catch (Exception e) {
throw new RenException(e.getMessage());
}

10
epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java

@ -19,7 +19,15 @@ public abstract class AbstractApiService {
* @return
* @throws Exception
*/
public abstract ThirdPlatUserInfo getUserInfoByTicket(String ticket) throws Exception;
public abstract ThirdPlatUserInfo getCUserInfoByTicket(String ticket) throws Exception;
/**
* G端用户token获取用户信息
* @param token
* @return
* @throws Exception
*/
public abstract ThirdPlatUserInfo getGUserInfoBySSOToken(String token) throws Exception;
/**
* @Description 解析请求结果

45
epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java

@ -5,7 +5,8 @@ import com.epmet.commons.thirdplat.apiservice.AbstractApiService;
import com.epmet.commons.thirdplat.bean.ThirdPlatUserInfo;
import com.epmet.commons.thirdplat.constants.JcetConstants;
import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO;
import com.epmet.commons.thirdplat.dto.result.jcet.JcetUserInfoResultDTO;
import com.epmet.commons.thirdplat.dto.result.jcet.JcetCUserInfoResultDTO;
import com.epmet.commons.thirdplat.dto.result.jcet.JcetGUserInfoResultDTO;
import com.epmet.commons.thirdplat.encrypt.SignUtils;
import com.epmet.commons.thirdplat.properties.JcetThirdplatProps;
import com.epmet.commons.thirdplat.properties.ThirdplatProps;
@ -37,7 +38,7 @@ public class JcetApiService extends AbstractApiService {
* @author wxz
* @date 2021.01.19 10:26
*/
public ThirdPlatUserInfo getUserInfoByTicket(String ticket) throws UnsupportedEncodingException {
public ThirdPlatUserInfo getCUserInfoByTicket(String ticket) throws UnsupportedEncodingException {
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口开始>>>>>>>>>>>>");
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口入参 ticket:{}", ticket);
@ -50,7 +51,7 @@ public class JcetApiService extends AbstractApiService {
domain.concat(JcetConstants.URL_GET_USER_BY_TICKET),
domain.startsWith("https://"),
JSON.toJSONString(ssoTicket),
getHeaders(ssoTicket, jcetThirdplatCendProps.getAppkey(), jcetThirdplatCendProps.getAppsecret()));
getHeaders(JSON.toJSONString(ssoTicket).getBytes("utf-8").length, jcetThirdplatCendProps.getAppkey(), jcetThirdplatCendProps.getAppsecret()));
try {
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口返回:{}", result.getData());
@ -59,7 +60,7 @@ public class JcetApiService extends AbstractApiService {
}
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口结束<<<<<<<<<<<<");
JcetUserInfoResultDTO resultDTO = parseResult(result, JcetUserInfoResultDTO.class);
JcetCUserInfoResultDTO resultDTO = parseResult(result, JcetCUserInfoResultDTO.class);
ThirdPlatUserInfo userInfo = new ThirdPlatUserInfo();
userInfo.setOpenId(resultDTO.getId());
@ -68,6 +69,38 @@ public class JcetApiService extends AbstractApiService {
return userInfo;
}
@Override
public ThirdPlatUserInfo getGUserInfoBySSOToken(String token) throws Exception {
logger.info("【请求酒城e通第三方平台】getGUserInfoBySSOToken()接口开始>>>>>>>>>>>>");
logger.info("【请求酒城e通第三方平台】getGUserInfoBySSOToken()接口入参 ticket:{}", token);
HashMap<String, Object> params = new HashMap<>();
params.put("ssoToken",token);
String domain = jcetThirdplatGendProps.getDomain();
Result<String> result = HttpClientManager.getInstance().sendGet(
domain.concat(JcetConstants.URL_GET_USER_BY_TOKEN),
domain.startsWith("https://"),
params,
getHeaders(0, jcetThirdplatGendProps.getAppkey(), jcetThirdplatGendProps.getAppsecret()));
try {
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口返回:{}", result.getData());
} catch (Exception e) {
//e.printStackTrace();
}
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口结束<<<<<<<<<<<<");
JcetGUserInfoResultDTO resultDTO = parseResult(result, JcetGUserInfoResultDTO.class);
ThirdPlatUserInfo userInfo = new ThirdPlatUserInfo();
userInfo.setOpenId(resultDTO.getUid());
userInfo.setName(resultDTO.getName());
userInfo.setMobile(resultDTO.getMobile());
return userInfo;
}
/**
* @return
* @Description 通过token获取用户信息
@ -96,12 +129,10 @@ public class JcetApiService extends AbstractApiService {
/**
* 获取请求所需要的头信息
*
* @param contentObject
* @return
* @throws UnsupportedEncodingException
*/
private Map<String, String> getHeaders(Object contentObject, String appKey, String appSecret) throws UnsupportedEncodingException {
int bodyLength = JSON.toJSONString(contentObject).getBytes("utf-8").length;
private Map<String, String> getHeaders(int bodyLength, String appKey, String appSecret) throws UnsupportedEncodingException {
Map<String, String> headers = new HashMap();
long timestamp = System.currentTimeMillis();

2
epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetUserInfoResultDTO.java → epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetCUserInfoResultDTO.java

@ -3,7 +3,7 @@ package com.epmet.commons.thirdplat.dto.result.jcet;
import lombok.Data;
@Data
public class JcetUserInfoResultDTO {
public class JcetCUserInfoResultDTO {
private String id;
/**
* 用户名称

25
epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetGUserInfoResultDTO.java

@ -0,0 +1,25 @@
package com.epmet.commons.thirdplat.dto.result.jcet;
import lombok.Data;
@Data
public class JcetGUserInfoResultDTO {
private String uid;
/**
* 手机号码
*/
private String mobile;
/**
* 姓名
*/
private String name;
/**
* 账号
*/
private String account;
/**
* 用户编码
*/
private String code;
}
Loading…
Cancel
Save