18 changed files with 477 additions and 31 deletions
			
			
		@ -0,0 +1,34 @@ | 
				
			|||
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 SsoLoginOperFormDTO extends LoginCommonFormDTO implements Serializable { | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    private static final long serialVersionUID = 8711491709544498082L; | 
				
			|||
 | 
				
			|||
    public interface ThirdPlatformLoginForm { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 上游系统token | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "token不能为空", groups = {ThirdPlatformLoginForm.class}) | 
				
			|||
    private String thirdToken; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 上游系统token | 
				
			|||
     * | 
				
			|||
     * @see com.epmet.enums.ThirdPlatformEnum | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "token不能为空", groups = {ThirdPlatformLoginForm.class}) | 
				
			|||
    private String platform; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,57 @@ | 
				
			|||
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 ThirdPlatFormDTO implements Serializable { | 
				
			|||
 | 
				
			|||
    private static final long serialVersionUID = -6543952487970013031L; | 
				
			|||
 | 
				
			|||
    public interface SsoLoginForm { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public interface ThirdPlatformLoginForm { | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * sso票据,有效期为300秒 | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "sso票据不能为空", groups = {SsoLoginForm.class, ThirdPlatformLoginForm.class}) | 
				
			|||
    private String ticket; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 三方平台应用AppId | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "三方平台应用AppId不能为空", groups = SsoLoginForm.class) | 
				
			|||
    private String appId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * app类型 resi;居民段,work:工作端 | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "app不能为空", groups = SsoLoginForm.class) | 
				
			|||
    private String app; | 
				
			|||
 | 
				
			|||
    @NotBlank(message = "client不能为空", groups = SsoLoginForm.class) | 
				
			|||
    private String client; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 上游系统token | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "token不能为空", groups = {ThirdPlatformLoginForm.class}) | 
				
			|||
    private String thirdToken; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 上游系统token | 
				
			|||
     * | 
				
			|||
     * @see com.epmet.enums.ThirdPlatformEnum | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "token不能为空", groups = {ThirdPlatformLoginForm.class}) | 
				
			|||
    private String platform; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,50 @@ | 
				
			|||
package com.epmet.enums; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 系统环境变量枚举类 | 
				
			|||
 * dev|test|prod | 
				
			|||
 * | 
				
			|||
 * @author jianjun liu | 
				
			|||
 * @date 2020-07-03 11:14 | 
				
			|||
 **/ | 
				
			|||
public enum ThirdPlatformEnum { | 
				
			|||
	/** | 
				
			|||
	 * 平阴联动指挥平台 | 
				
			|||
	 */ | 
				
			|||
	PINGYIN_LIANDONG("pyld", "平阴联动指挥平台", "pyldApiService"), | 
				
			|||
	; | 
				
			|||
 | 
				
			|||
	private String code; | 
				
			|||
	private String name; | 
				
			|||
	private String apiService; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
	ThirdPlatformEnum(String code, String name, String apiService) { | 
				
			|||
		this.code = code; | 
				
			|||
		this.name = name; | 
				
			|||
		this.apiService = apiService; | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public static ThirdPlatformEnum getEnum(String code) { | 
				
			|||
		ThirdPlatformEnum[] values = ThirdPlatformEnum.values(); | 
				
			|||
		for (ThirdPlatformEnum value : values) { | 
				
			|||
			if (value.getCode().equals(code)) { | 
				
			|||
				return value; | 
				
			|||
			} | 
				
			|||
		} | 
				
			|||
		return null; | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
 | 
				
			|||
	public String getCode() { | 
				
			|||
		return code; | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public String getName() { | 
				
			|||
		return name; | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public String getApiService() { | 
				
			|||
		return apiService; | 
				
			|||
	} | 
				
			|||
} | 
				
			|||
@ -0,0 +1,126 @@ | 
				
			|||
package com.epmet.commons.thirdplat.apiservice.pyld; | 
				
			|||
 | 
				
			|||
import com.alibaba.fastjson.JSON; | 
				
			|||
import com.alibaba.fastjson.JSONObject; | 
				
			|||
import com.epmet.commons.thirdplat.apiservice.AbstractApiService; | 
				
			|||
import com.epmet.commons.thirdplat.bean.ThirdPlatUserInfo; | 
				
			|||
import com.epmet.commons.thirdplat.constants.PyldConstants; | 
				
			|||
import com.epmet.commons.thirdplat.dto.result.jcet.PyldUserInfoResultDTO; | 
				
			|||
import com.epmet.commons.thirdplat.properties.PyldThirdplatProps; | 
				
			|||
import com.epmet.commons.thirdplat.properties.ThirdplatProps; | 
				
			|||
import com.epmet.commons.tools.exception.EpmetErrorCode; | 
				
			|||
import com.epmet.commons.tools.exception.RenException; | 
				
			|||
import com.epmet.commons.tools.utils.HttpClientManager; | 
				
			|||
import com.epmet.commons.tools.utils.Result; | 
				
			|||
import org.apache.commons.codec.digest.DigestUtils; | 
				
			|||
import org.apache.commons.lang3.StringUtils; | 
				
			|||
import org.slf4j.Logger; | 
				
			|||
import org.slf4j.LoggerFactory; | 
				
			|||
import org.springframework.stereotype.Service; | 
				
			|||
 | 
				
			|||
import java.nio.charset.StandardCharsets; | 
				
			|||
import java.util.HashMap; | 
				
			|||
import java.util.Map; | 
				
			|||
 | 
				
			|||
@Service | 
				
			|||
public class PyldApiService extends AbstractApiService { | 
				
			|||
 | 
				
			|||
    Logger logger = LoggerFactory.getLogger(getClass()); | 
				
			|||
 | 
				
			|||
    private PyldThirdplatProps pyldThirdplatProps; | 
				
			|||
 | 
				
			|||
    public PyldApiService(ThirdplatProps props) { | 
				
			|||
        this.thirdplatProps = props; | 
				
			|||
        pyldThirdplatProps = props.getPyld(); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @return | 
				
			|||
     * @Description 通过第三方平台ticket获取用户信息 | 
				
			|||
     * @author wxz | 
				
			|||
     * @date 2021.01.19 10:26 | 
				
			|||
     */ | 
				
			|||
    @Override | 
				
			|||
    public ThirdPlatUserInfo getUserInfoByTicket(String platformToken) { | 
				
			|||
 | 
				
			|||
        logger.info("【请求平阴联动指挥平台第三方平台】getUserInfoByTicket()接口开始>>>>>>>>>>>>"); | 
				
			|||
        logger.info("【请求平阴联动指挥平台第三方平台】getUserInfoByTicket()接口入参 platformToken:{}", platformToken); | 
				
			|||
 | 
				
			|||
        try { | 
				
			|||
            JSONObject jsonParam = new JSONObject(); | 
				
			|||
            jsonParam.put(PyldConstants.PLAT_PARAM_TOKEN, platformToken); | 
				
			|||
            jsonParam.put(PyldConstants.PLAT_PARAM_MANAGEMENTKEY, PyldConstants.PLAT_PARAM_MANAGEMENTKEY_VALUE); | 
				
			|||
 | 
				
			|||
            String domain = pyldThirdplatProps.getDomain(); | 
				
			|||
            Result<String> result = HttpClientManager.getInstance().sendPost( | 
				
			|||
                    domain.concat(PyldConstants.METHOD_CHECK_LOGIN), | 
				
			|||
                    domain.startsWith("https://"), | 
				
			|||
                    jsonParam.toJSONString(), | 
				
			|||
                    buildHeaders()); | 
				
			|||
 | 
				
			|||
            logger.info("【请求平阴联动指挥平台第三方平台】getUserInfoByTicket()接口返回:{}", result.getData()); | 
				
			|||
 | 
				
			|||
            logger.info("【请求平阴联动指挥平台第三方平台】getUserInfoByTicket()接口结束<<<<<<<<<<<<"); | 
				
			|||
 | 
				
			|||
            PyldUserInfoResultDTO resultDTO = this.parseResult(result); | 
				
			|||
 | 
				
			|||
            ThirdPlatUserInfo userInfo = new ThirdPlatUserInfo(); | 
				
			|||
            userInfo.setMobile(resultDTO.getMobile()); | 
				
			|||
            userInfo.setCustomerId(resultDTO.getReserved()); | 
				
			|||
            return userInfo; | 
				
			|||
        } catch (Exception e) { | 
				
			|||
            logger.error("getUserInfoByTicket exception", e); | 
				
			|||
        } | 
				
			|||
        return null; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 构建请求头信息 | 
				
			|||
     * | 
				
			|||
     * @return | 
				
			|||
     */ | 
				
			|||
    private Map<String, Object> buildHeaders() { | 
				
			|||
        Map<String, Object> headers = new HashMap(); | 
				
			|||
        long timestamp = System.currentTimeMillis(); | 
				
			|||
        headers.put(PyldConstants.PLAT_HEADER_TIMESTAMP, timestamp); | 
				
			|||
        headers.put(PyldConstants.PLAT_HEADER_APP_KEY, pyldThirdplatProps.getAppkey()); | 
				
			|||
        String encryptContent = pyldThirdplatProps.getAppId() + pyldThirdplatProps.getAppkey() + pyldThirdplatProps.getAppSecret() + timestamp; | 
				
			|||
        headers.put(PyldConstants.PLAT_HEADER_ACCESS_TOKEN, DigestUtils.md5Hex(encryptContent.getBytes(StandardCharsets.UTF_8))); | 
				
			|||
        return headers; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * desc: 解析结果 | 
				
			|||
     * | 
				
			|||
     * @param thResult | 
				
			|||
     * @return com.epmet.commons.thirdplat.dto.result.jcet.JcetUserInfoResultDTO | 
				
			|||
     * @author LiuJanJun | 
				
			|||
     * @date 2021/2/24 10:11 上午 | 
				
			|||
     */ | 
				
			|||
    private PyldUserInfoResultDTO parseResult(Result<String> thResult) { | 
				
			|||
        if (!thResult.success()) { | 
				
			|||
            throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), | 
				
			|||
                    EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getMsg().concat(":").concat(thResult.getInternalMsg())); | 
				
			|||
        } | 
				
			|||
        JSONObject jcetResult = JSON.parseObject(thResult.getData()); | 
				
			|||
        Integer code = jcetResult.getInteger("code"); | 
				
			|||
        String msg = jcetResult.getString("msg"); | 
				
			|||
        if (code == null || code != 0) { | 
				
			|||
            throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), msg.concat(",错误码:") + code); | 
				
			|||
        } | 
				
			|||
        JSONObject data = jcetResult.getJSONObject("data"); | 
				
			|||
        if (data == null) { | 
				
			|||
            throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), | 
				
			|||
                    EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getMsg().concat(":").concat(PyldConstants.REPONSE_USER_NOT_LOGIN)); | 
				
			|||
        } | 
				
			|||
        PyldUserInfoResultDTO userInfo = data.getObject("userInfo", PyldUserInfoResultDTO.class); | 
				
			|||
        if (userInfo == null || StringUtils.isBlank(userInfo.getMobile()) || StringUtils.isBlank(userInfo.getReserved())) { | 
				
			|||
            throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), | 
				
			|||
                    EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getMsg().concat(":").concat(PyldConstants.REPONSE_USER_NOT_LOGIN)); | 
				
			|||
        } | 
				
			|||
        return userInfo; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,18 @@ | 
				
			|||
package com.epmet.commons.thirdplat.constants; | 
				
			|||
 | 
				
			|||
public interface PyldConstants { | 
				
			|||
 | 
				
			|||
    String METHOD_CHECK_LOGIN = "/unifiedAuth/loginCheck"; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    String PLAT_HEADER_TIMESTAMP = "timestamp"; | 
				
			|||
    String PLAT_HEADER_APP_KEY = "appkey"; | 
				
			|||
    String PLAT_HEADER_ACCESS_TOKEN = "accessToken"; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    String PLAT_PARAM_TOKEN = "platformToken"; | 
				
			|||
    String PLAT_PARAM_MANAGEMENTKEY = "managementKey"; | 
				
			|||
    String PLAT_PARAM_MANAGEMENTKEY_VALUE = "epmet_work"; | 
				
			|||
 | 
				
			|||
    String REPONSE_USER_NOT_LOGIN = "用户未登陆"; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,18 @@ | 
				
			|||
package com.epmet.commons.thirdplat.dto.result.jcet; | 
				
			|||
 | 
				
			|||
import lombok.Data; | 
				
			|||
 | 
				
			|||
import java.io.Serializable; | 
				
			|||
 | 
				
			|||
@Data | 
				
			|||
public class PyldUserInfoResultDTO implements Serializable { | 
				
			|||
    private static final long serialVersionUID = 6176427074670949388L; | 
				
			|||
    /** | 
				
			|||
     * 手机号 | 
				
			|||
     */ | 
				
			|||
    private String mobile; | 
				
			|||
    /** | 
				
			|||
     * 客户Id | 
				
			|||
     */ | 
				
			|||
    private String reserved; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,14 @@ | 
				
			|||
package com.epmet.commons.thirdplat.properties; | 
				
			|||
 | 
				
			|||
import lombok.Data; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 酒城e通三方平台配置 | 
				
			|||
 */ | 
				
			|||
@Data | 
				
			|||
public class PyldThirdplatProps { | 
				
			|||
    private String domain; | 
				
			|||
    private String appId; | 
				
			|||
    private String appkey; | 
				
			|||
    private String appSecret; | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue