Browse Source

新增:第三方平台模块相关代码init

feature/evaluate
wxz 5 years ago
parent
commit
5db91f665d
  1. 5
      epmet-auth/pom.xml
  2. 7
      epmet-auth/src/main/resources/bootstrap.yml
  3. 22
      epmet-commons/epmet-commons-thirdplat/pom.xml
  4. 35
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/DemoApp.java
  5. 34
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/AbstractApiService.java
  6. 81
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/apiservice/jcet/JcetApiService.java
  7. 14
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/config/ThirdplatConfig.java
  8. 8
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/constants/JcetApiUrls.java
  9. 8
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTicketFormDTO.java
  10. 8
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/form/jcet/SsoTokenFormDTO.java
  11. 13
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/JcetResult.java
  12. 13
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/dto/result/jcet/UserInfoResultDTO.java
  13. 51
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/EncryptUtils.java
  14. 15
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/encrypt/SignUtils.java
  15. 13
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/JcetThirdplatProps.java
  16. 12
      epmet-commons/epmet-commons-thirdplat/src/main/java/com/epmet/commons/thirdplat/properties/ThirdplatProps.java
  17. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  18. 3
      epmet-commons/pom.xml

5
epmet-auth/pom.xml

@ -18,6 +18,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-thirdplat</artifactId>
<version>2.0.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.epmet</groupId> <groupId>com.epmet</groupId>
<artifactId>epmet-admin-client</artifactId> <artifactId>epmet-admin-client</artifactId>

7
epmet-auth/src/main/resources/bootstrap.yml

@ -132,3 +132,10 @@ shutdown:
graceful: graceful:
enable: true #是否开启优雅停机 enable: true #是否开启优雅停机
waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警
# 调用第三方平台相关参数
thirdplat:
jcet:
domain: http://101.206.141.251:21006
appkey: soXDEoM1
appsecret: V7ea0KnlYt7eSyzc

22
epmet-commons/epmet-commons-thirdplat/pom.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>epmet-commons</artifactId>
<groupId>com.epmet</groupId>
<version>2.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>epmet-commons-thirdplat</artifactId>
<dependencies>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-tools</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>

35
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<String, Object> 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);
}
}

34
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> R parseResult(Result<String> thResult, Class<R> 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);
}
}

81
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<String> 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<String> 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<String, String> getHeaders(Object contentObject) throws UnsupportedEncodingException {
int bodyLength = JSON.toJSONString(contentObject).getBytes("utf-8").length;
Map<String, String> 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;
}
}

14
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 {
}

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

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

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

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

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

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

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

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

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

2
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, "该机关存在网格,不允许删除"), NOT_DEL_AGENCY_GRID(8207, "该机关存在网格,不允许删除"),
REQUIRE_PERMISSION(8301, "您没有足够的操作权限"), REQUIRE_PERMISSION(8301, "您没有足够的操作权限"),
THIRD_PLAT_REQUEST_ERROR(8302, "请求第三方平台错误"),
NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"), NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"),
MOBILE_USED(8402,"该手机号已注册"), MOBILE_USED(8402,"该手机号已注册"),
@ -143,7 +144,6 @@ public enum EpmetErrorCode {
TOPIC_IS_HIDDEN(9006,"该话题已被屏蔽,请先解除屏蔽"), TOPIC_IS_HIDDEN(9006,"该话题已被屏蔽,请先解除屏蔽"),
TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"); TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题");
private int code; private int code;
private String msg; private String msg;

3
epmet-commons/pom.xml

@ -23,6 +23,7 @@
<module>epmet-commons-tools-wx-mp</module> <module>epmet-commons-tools-wx-mp</module>
<module>epmet-commons-service-call</module> <module>epmet-commons-service-call</module>
<module>epmet-commons-extapp-auth</module> <module>epmet-commons-extapp-auth</module>
</modules> <module>epmet-commons-thirdplat</module>
</modules>
</project> </project>

Loading…
Cancel
Save