Browse Source

Merge remote-tracking branch 'remotes/origin/dev_jcet' into dev_temp

# Conflicts:
#	epmet-auth/src/main/java/com/epmet/controller/SsoController.java
#	epmet-auth/src/main/java/com/epmet/service/SsoService.java
#	epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java
#	epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java
dev_shibei_match
jianjun 5 years ago
parent
commit
f26a99bfb0
  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. 2
      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. 49
      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
  9. 11
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.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.form.SsoLoginOperFormDTO;
import com.epmet.dto.result.SsoLoginResultDTO;
import com.epmet.dto.result.UserTokenResultDTO;
@ -58,7 +59,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();
}
@ -71,8 +72,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;
}

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

@ -25,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

@ -83,6 +83,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));
@ -97,7 +98,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());
}
@ -255,10 +256,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));
@ -271,7 +273,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());
}
@ -487,7 +489,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 解析请求结果

49
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;
@ -41,7 +42,7 @@ public class JcetApiService extends AbstractApiService {
* @date 2021.01.19 10:26
*/
@Override
public ThirdPlatUserInfo getUserInfoByTicket(String ticket) throws UnsupportedEncodingException {
public ThirdPlatUserInfo getCUserInfoByTicket(String ticket) throws UnsupportedEncodingException {
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口开始>>>>>>>>>>>>");
logger.info("【请求酒城e通第三方平台】getUserInfoByTicket()接口入参 ticket:{}", ticket);
@ -54,7 +55,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());
@ -63,7 +64,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());
@ -72,6 +73,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获取用户信息
@ -100,16 +133,14 @@ public class JcetApiService extends AbstractApiService {
/**
* 获取请求所需要的头信息
*
* @param contentObject
* @return
* @throws UnsupportedEncodingException
*/
private Map<String, Object> getHeaders(Object contentObject, String appKey, String appSecret) throws UnsupportedEncodingException {
int bodyLength = JSON.toJSONString(contentObject).getBytes(StandardCharsets.UTF_8).length;
private Map<String, Object> getHeaders(int bodyLength, String appKey, String appSecret) throws UnsupportedEncodingException {
Map<String, Object> headers = new HashMap();
Map<String, String> headers = new HashMap();
long timestamp = System.currentTimeMillis();
headers.put(JcetConstants.PLAT_HEADER_OPEN_TIMESTAMP, String.valueOf(timestamp));
headers.put(JcetConstants.PLAT_HEADER_OPEN_TIMESTAMP, timestamp);
headers.put(JcetConstants.PLAT_HEADER_OPEN_APP_ID, appKey);
String encryptContent = appKey + timestamp + bodyLength;
headers.put(JcetConstants.PLAT_HEADER_OPEN_SIGN, SignUtils.generate(encryptContent, appSecret));

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;
}

11
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java

@ -196,8 +196,9 @@ public class HttpClientManager {
httppost.addHeader(HEADER_CONTENT_TYPE, HEADER_APPLICATION_JSON);
if (null != headerMap) {
headerMap.forEach((k, v) -> {
if (v != null)
httppost.addHeader(k, v.toString());
if (StringUtils.isNotBlank(k)) {
httppost.addHeader(k, v == null ? null : v.toString());
}
});
}
if (StringUtils.isNotEmpty(jsonStrParam)) {
@ -349,7 +350,7 @@ public class HttpClientManager {
}
}
public Result<String> sendGet(String url, boolean isHttps, Map<String, Object> params, Map<String,String> headerMap) {
public Result<String> sendGet(String url, boolean isHttps, Map<String, Object> params, Map<String, Object> headerMap) {
try {
URIBuilder builder = new URIBuilder(url);
@ -364,7 +365,9 @@ public class HttpClientManager {
httpGet.setConfig(requestConfig);
if (null != headerMap){
headerMap.forEach((k,v) -> {
httpGet.addHeader(k,v);
if (StringUtils.isNotBlank(k)) {
httpGet.addHeader(k, v == null ? null : v.toString());
}
});
}
return execute(httpGet, isHttps);

Loading…
Cancel
Save