diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index 69713f1908..4164a50134 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -18,6 +18,11 @@ + + com.epmet + epmet-commons-thirdplat + 2.0.0 + com.epmet epmet-admin-client diff --git a/epmet-auth/src/main/resources/bootstrap.yml b/epmet-auth/src/main/resources/bootstrap.yml index e7fa54d000..865035f3f7 100644 --- a/epmet-auth/src/main/resources/bootstrap.yml +++ b/epmet-auth/src/main/resources/bootstrap.yml @@ -131,4 +131,11 @@ dingTalk: shutdown: graceful: enable: true #是否开启优雅停机 - waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 \ No newline at end of file + waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 + +# 调用第三方平台相关参数 +thirdplat: + jcet: + domain: http://101.206.141.251:21006 + appkey: soXDEoM1 + appsecret: V7ea0KnlYt7eSyzc \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/pom.xml b/epmet-commons/epmet-commons-thirdplat/pom.xml new file mode 100644 index 0000000000..8689c09054 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/pom.xml @@ -0,0 +1,22 @@ + + + + epmet-commons + com.epmet + 2.0.0 + + 4.0.0 + + epmet-commons-thirdplat + + + + com.epmet + epmet-commons-tools + 2.0.0 + + + + \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java new file mode 100644 index 0000000000..92d525b186 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java @@ -0,0 +1,35 @@ +package com.epmet.commons.thirdplat; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO; +import com.epmet.commons.thirdplat.encrypt.SignUtils; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; + +public class DemoApp { + + private static String appid = "soXDEoM1"; + private static String appsecret = "V7ea0KnlYt7eSyzc"; + + public static void main(String[] args) throws UnsupportedEncodingException { + + //SsoToken ssoToken = new SsoToken(); + //ssoToken.setSsoToken("wxz"); + + SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); + ssoTicket.setSsoTicket("wxz"); + + int bodyLength = JSON.toJSONString(ssoTicket).getBytes("utf-8").length; + + Map headers = new HashMap(); + long timestamp = System.currentTimeMillis(); + headers.put("openTimestamp", String.valueOf(timestamp)); + headers.put("openAppId", appid); + String encryptContent = appid + timestamp + bodyLength; + headers.put("openSign", SignUtils.generate(encryptContent, appsecret)); + System.out.println(headers); + } + +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java new file mode 100644 index 0000000000..7950526fd1 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java @@ -0,0 +1,34 @@ +package com.epmet.commons.thirdplat.apiservice; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.thirdplat.dto.result.jcet.JcetResult; +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.Result; + +public class AbstractApiService { + + protected ThirdplatProps thirdplatProps; + + /** + * @Description 解析请求结果 + * @return + * @author wxz + * @date 2021.01.19 09:53 + */ + protected R parseResult(Result thResult, Class resultType) { + if (!thResult.success()) { + throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), + EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getMsg().concat(":").concat(thResult.getInternalMsg())); + } + + JcetResult jcetResult = JSON.parseObject(thResult.getData(), JcetResult.class); + if (!jcetResult.isSuccess()) { + throw new RenException(EpmetErrorCode.THIRD_PLAT_REQUEST_ERROR.getCode(), + jcetResult.getMsg().concat(",错误码:") + jcetResult.getCode()); + } + + return JSON.parseObject(jcetResult.getMsg(), resultType); + } +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java new file mode 100644 index 0000000000..edb59e6611 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java @@ -0,0 +1,81 @@ +package com.epmet.commons.thirdplat.apiservice.jcet; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.thirdplat.apiservice.AbstractApiService; +import com.epmet.commons.thirdplat.constants.JcetApiUrls; +import com.epmet.commons.thirdplat.dto.form.jcet.SsoTicketFormDTO; +import com.epmet.commons.thirdplat.dto.result.jcet.UserInfoResultDTO; +import com.epmet.commons.thirdplat.encrypt.SignUtils; +import com.epmet.commons.thirdplat.properties.JcetThirdplatProps; +import com.epmet.commons.thirdplat.properties.ThirdplatProps; +import com.epmet.commons.tools.utils.HttpClientManager; +import com.epmet.commons.tools.utils.Result; +import org.springframework.stereotype.Component; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; + +@Component +public class JcetApiService extends AbstractApiService { + + private JcetThirdplatProps jcetThirdplatProps; + + public JcetApiService(ThirdplatProps props) { + this.thirdplatProps = props; + jcetThirdplatProps = props.getJcet(); + } + + public UserInfoResultDTO login(String ticket) { + + try { + UserInfoResultDTO userInfoByTicket = getUserInfoByTicket(ticket); + // todo + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + return null; + } + + private UserInfoResultDTO getUserInfoByTicket(String ticket) throws UnsupportedEncodingException { + SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); + ssoTicket.setSsoTicket(ticket); + Result result = HttpClientManager.getInstance().sendPostByJSONAndHeader( + jcetThirdplatProps.getDomain().concat(JcetApiUrls.GET_USER_BY_TICKET), + JSON.toJSONString(ssoTicket), getHeaders(ssoTicket)); + + UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); + return resultDTO; + } + + private UserInfoResultDTO getUserInfoByToken(String ticket) throws UnsupportedEncodingException { + SsoTicketFormDTO ssoTicket = new SsoTicketFormDTO(); + ssoTicket.setSsoTicket(ticket); + Result result = HttpClientManager.getInstance().sendPostByJSONAndHeader( + jcetThirdplatProps.getDomain().concat(JcetApiUrls.GET_USER_BY_TICKET), + JSON.toJSONString(ssoTicket), getHeaders(ssoTicket)); + + UserInfoResultDTO resultDTO = parseResult(result, UserInfoResultDTO.class); + return resultDTO; + } + + /** + * 获取请求所需要的头信息 + * @param contentObject + * @return + * @throws UnsupportedEncodingException + */ + private Map getHeaders(Object contentObject) throws UnsupportedEncodingException { + int bodyLength = JSON.toJSONString(contentObject).getBytes("utf-8").length; + + Map headers = new HashMap(); + long timestamp = System.currentTimeMillis(); + headers.put("openTimestamp", String.valueOf(timestamp)); + headers.put("openAppId", jcetThirdplatProps.getAppkey()); + String encryptContent = jcetThirdplatProps.getAppkey() + timestamp + bodyLength; + headers.put("openSign", SignUtils.generate(encryptContent, jcetThirdplatProps.getAppsecret())); + return headers; + } + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java new file mode 100644 index 0000000000..16258ed150 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java @@ -0,0 +1,14 @@ +package com.epmet.commons.thirdplat.config; + +import com.epmet.commons.thirdplat.properties.ThirdplatProps; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * 第三方平台的相关配置 + */ +@Configuration +@EnableConfigurationProperties(ThirdplatProps.class) +public class ThirdplatConfig { + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java new file mode 100644 index 0000000000..ee0438c5cd --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java @@ -0,0 +1,8 @@ +package com.epmet.commons.thirdplat.constants; + +public interface JcetApiUrls { + + // 根据ticket查询用户 + String GET_USER_BY_TICKET = "/openapi-cgw/openapi-login/sso/getUserInfoByTicket"; + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java new file mode 100644 index 0000000000..b0f905d972 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java @@ -0,0 +1,8 @@ +package com.epmet.commons.thirdplat.dto.form.jcet; + +import lombok.Data; + +@Data +public class SsoTicketFormDTO { + private String ssoTicket; +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java new file mode 100644 index 0000000000..f3a7707082 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java @@ -0,0 +1,8 @@ +package com.epmet.commons.thirdplat.dto.form.jcet; + +import lombok.Data; + +@Data +public class SsoTokenFormDTO { + private String ssoToken; +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java new file mode 100644 index 0000000000..aea748f51a --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java @@ -0,0 +1,13 @@ +package com.epmet.commons.thirdplat.dto.result.jcet; + +import lombok.Data; + +@Data +public class JcetResult { + + private boolean success; + private String msg; + private Object data; + private int code; + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java new file mode 100644 index 0000000000..5adf33436d --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java @@ -0,0 +1,13 @@ +package com.epmet.commons.thirdplat.dto.result.jcet; + +import lombok.Data; + +@Data +public class UserInfoResultDTO { + + private String name; + private String mobile; + private String uid; + private String account; + +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java new file mode 100644 index 0000000000..699d12ea40 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java @@ -0,0 +1,51 @@ +package com.epmet.commons.thirdplat.encrypt; + + +import com.epmet.commons.tools.exception.RenException; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class EncryptUtils { + private final static char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + /** + * 32位 MD5加密 + * + * @param s + * @return + */ + public static String md5Hex(String s) throws UnsupportedEncodingException { + byte[] result = digest("MD5", s.getBytes(Charset.defaultCharset())); + return hex(result); + } + /** + * 32 位 sha256加密 + * + * @param s + * @return + */ + public static String sha256(String s) { + byte[] result = digest("SHA-256", s.getBytes(Charset.defaultCharset())); + return hex(result); + } + private static byte[] digest(String algorithm, byte[] data) { + try { + MessageDigest digest = MessageDigest.getInstance(algorithm); + digest.update(data, 0, data.length); + return digest.digest(); + } catch (NoSuchAlgorithmException e) { + throw new RenException(algorithm + " error", e); + } + } + private static String hex(byte[] data) { + char[] result = new char[data.length * 2]; + int c = 0; + for (byte b : data) { + result[c++] = HEX_DIGITS[(b >> 4) & 0xf]; + result[c++] = HEX_DIGITS[b & 0xf]; + } + return new String(result); + } +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java new file mode 100644 index 0000000000..1c45e44b6b --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java @@ -0,0 +1,15 @@ +package com.epmet.commons.thirdplat.encrypt; + +import java.io.UnsupportedEncodingException; + +public class SignUtils { + public static String generate(String content, String secret) throws UnsupportedEncodingException { + String sign = EncryptUtils.sha256(content); + sign = EncryptUtils.md5Hex(sign + secret); + return sign; + } + + public static void main(String[] args) { + System.out.println(777); + } +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java new file mode 100644 index 0000000000..1682a86fce --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java @@ -0,0 +1,13 @@ +package com.epmet.commons.thirdplat.properties; + +import lombok.Data; + +/** + * 酒城e通三方平台配置 + */ +@Data +public class JcetThirdplatProps { + private String domain; + private String appkey; + private String appsecret; +} diff --git a/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java new file mode 100644 index 0000000000..07c4919bd9 --- /dev/null +++ b/epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java @@ -0,0 +1,12 @@ +package com.epmet.commons.thirdplat.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@Data +@ConfigurationProperties(prefix = "thirdplat") +public class ThirdplatProps { + + private JcetThirdplatProps jcet; + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 4d3c107de3..8bdcadf260 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -71,6 +71,7 @@ public enum EpmetErrorCode { NOT_DEL_AGENCY_GRID(8207, "该机关存在网格,不允许删除"), REQUIRE_PERMISSION(8301, "您没有足够的操作权限"), + THIRD_PLAT_REQUEST_ERROR(8302, "请求第三方平台错误"), NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"), MOBILE_USED(8402,"该手机号已注册"), @@ -143,7 +144,6 @@ public enum EpmetErrorCode { TOPIC_IS_HIDDEN(9006,"该话题已被屏蔽,请先解除屏蔽"), TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"); - private int code; private String msg; diff --git a/epmet-commons/pom.xml b/epmet-commons/pom.xml index d4b8e270b4..dbec54a340 100644 --- a/epmet-commons/pom.xml +++ b/epmet-commons/pom.xml @@ -23,6 +23,7 @@ epmet-commons-tools-wx-mp epmet-commons-service-call epmet-commons-extapp-auth - + epmet-commons-thirdplat +