| | |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <parent> |
| | | <groupId>com.hx.gitee</groupId> |
| | | <artifactId>hx-parent</artifactId> |
| | | <version>1.0-SNAPSHOT</version> |
| | | </parent> |
| | | |
| | | <groupId>com.hx.gitee</groupId> |
| | | <artifactId>platform-common</artifactId> |
| | | <packaging>jar</packaging> |
| | | <version>1.0-SNAPSHOT</version> |
| | | |
| | | <dependencies> |
| | | <dependency> |
| | | <groupId>com.github.ulisesbocchio</groupId> |
| | | <artifactId>jasypt-spring-boot-starter</artifactId> |
| | | <version>2.1.2</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.hx.gitee</groupId> |
| | | <artifactId>hx-common</artifactId> |
| | | <version>1.0-SNAPSHOT</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
New file |
| | |
| | | package com.platform.exception; |
| | | |
| | | /** 判断异常/业务异常 |
| | | * @author ChenJiaHe |
| | | * @Date 2021-10-20 |
| | | */ |
| | | public class PlatServiceException extends RuntimeException { |
| | | |
| | | private String code; |
| | | |
| | | public PlatServiceException(String code,String message) { |
| | | super(message); |
| | | this.code = code; |
| | | } |
| | | |
| | | public PlatServiceException( String code,String message, Throwable cause) { |
| | | super(message, cause); |
| | | this.code = code; |
| | | } |
| | | |
| | | public PlatServiceException( String code,Throwable cause) { |
| | | super(cause); |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(String code) { |
| | | this.code = code; |
| | | } |
| | | } |
New file |
| | |
| | | package com.platform.exception; |
| | | |
| | | /** |
| | | * 前端提示异常 |
| | | * @author ChenJiaHe |
| | | * @Date 2021-10-20 |
| | | */ |
| | | public class PlatTipsException extends RuntimeException { |
| | | |
| | | private String code; |
| | | |
| | | public PlatTipsException( String code,String message) { |
| | | super(message); |
| | | this.code = code; |
| | | } |
| | | |
| | | public PlatTipsException( String code,String message, Throwable cause) { |
| | | super(message, cause); |
| | | this.code = code; |
| | | } |
| | | |
| | | public PlatTipsException(String code,Throwable cause) { |
| | | super(cause); |
| | | this.code = code; |
| | | } |
| | | |
| | | |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(String code) { |
| | | this.code = code; |
| | | } |
| | | } |
New file |
| | |
| | | package com.platform.resultTool; |
| | | |
| | | /** |
| | | * 平台统一状态码 |
| | | * @author chenjiahe |
| | | * @Data: 2020-06-20 |
| | | */ |
| | | public final class PlatformCode { |
| | | |
| | | /*成功*/ |
| | | public static final String SUCCESS = "100"; |
| | | /*错误提示*/ |
| | | public static final String ERROR_TIPS="200"; |
| | | /*签名错误*/ |
| | | public static final String ERROR_SIGN = "201"; |
| | | /*appId错误*/ |
| | | public static final String ERROR_APPIS= "202"; |
| | | /*参数不能为空*/ |
| | | public static final String ERROR_PARAMETER_NULL = "203"; |
| | | /*参数类型错误*/ |
| | | public static final String ERROR_PARAMETER_TYPE = "204"; |
| | | |
| | | /*body格式错误*/ |
| | | public static final String ERROR_BODY_DATA = "500"; |
| | | |
| | | /*系统异常*/ |
| | | public static final String ERROR_SYSTEM = "999"; |
| | | |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package com.platform.resultTool; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * 开发平台统一返回格式 |
| | | * @author chenjiahe |
| | | * @Data: 2021-10-20 |
| | | */ |
| | | public class PlatformResult implements Serializable { |
| | | |
| | | private static final long serialVersionUID = -3948389268046368059L; |
| | | |
| | | private String code; |
| | | |
| | | private String msg; |
| | | |
| | | private Object data; |
| | | |
| | | public PlatformResult() {} |
| | | |
| | | public PlatformResult(String code, String msg) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public static PlatformResult success() { |
| | | PlatformResult Result = new PlatformResult(); |
| | | Result.setCode(PlatformCode.SUCCESS); |
| | | Result.setMsg("SUCCESS"); |
| | | return Result; |
| | | } |
| | | |
| | | public static PlatformResult success(Object data) { |
| | | PlatformResult Result = new PlatformResult(); |
| | | Result.setCode(PlatformCode.SUCCESS); |
| | | Result.setData(data); |
| | | Result.setMsg("SUCCESS"); |
| | | return Result; |
| | | } |
| | | |
| | | public static PlatformResult success(String code, String msg,Object data) { |
| | | PlatformResult Result = new PlatformResult(); |
| | | Result.setCode(code); |
| | | Result.setData(data); |
| | | Result.setMsg(msg); |
| | | return Result; |
| | | } |
| | | |
| | | public static PlatformResult failure(String code, String msg) { |
| | | PlatformResult Result = new PlatformResult(); |
| | | Result.setCode(code); |
| | | Result.setMsg(msg); |
| | | return Result; |
| | | } |
| | | |
| | | public static PlatformResult failure(String code, String msg, Object data) { |
| | | PlatformResult Result = new PlatformResult(); |
| | | Result.setCode(code); |
| | | Result.setMsg(msg); |
| | | Result.setData(data); |
| | | return Result; |
| | | } |
| | | |
| | | /*******************************************************************************/ |
| | | |
| | | public String getCode() { |
| | | return this.code; |
| | | } |
| | | |
| | | public void setCode(final String code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getMsg() { |
| | | return this.msg; |
| | | } |
| | | |
| | | public void setMsg(final String msg) { |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public Object getData() { |
| | | return this.data; |
| | | } |
| | | |
| | | public void setData(final Object data) { |
| | | this.data = data; |
| | | } |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package com.platform.resultTool; |
| | | |
| | | /** |
| | | * 平台统一错误码状态码 |
| | | * @author chenjiahe |
| | | * @Data: 2020-06-20 |
| | | */ |
| | | public final class SystemCode { |
| | | |
| | | /*获取企业token失败*/ |
| | | public static final String ERROR_GET_CORP_TOKEN = "001"; |
| | | |
| | | |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package com.platform.util; |
| | | |
| | | import com.hx.util.StringUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | |
| | | import java.io.OutputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * http 工具类 |
| | | */ |
| | | public class HttpPlatformUtil { |
| | | |
| | | /** 请求http协议 获取信息工具 |
| | | * @param url 请求链接 |
| | | * @param data 请求数据(body) |
| | | * @param keyValues form表单数据 key参数名称,value参数值 |
| | | * @param header 请求头 |
| | | * @param requestMethod 请求头方法,默认POST |
| | | * @return |
| | | */ |
| | | public static String HttpURLUtilJson(String url, String data,Map<String,Object> keyValues,Map<String,String> header,String requestMethod) { |
| | | HttpURLConnection con = null; |
| | | URL u = null; |
| | | String wxMsgXml = null; |
| | | try { |
| | | StringBuilder dataP = new StringBuilder(); |
| | | if (keyValues != null && !keyValues.isEmpty()) { |
| | | for (Map.Entry<String, Object> entry : keyValues.entrySet()) { |
| | | dataP.append((String)entry.getKey()).append("="); |
| | | dataP.append(entry.getValue()); |
| | | dataP.append("&"); |
| | | } |
| | | dataP.deleteCharAt(dataP.length() - 1); |
| | | url = url+"?"+dataP; |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(requestMethod)){ |
| | | requestMethod = "POST"; |
| | | } |
| | | u = new URL(url); |
| | | con = (HttpURLConnection) u.openConnection(); |
| | | con.setRequestMethod(requestMethod); |
| | | con.setDoOutput(true); |
| | | con.setDoInput(true); |
| | | con.setUseCaches(false); |
| | | con.setReadTimeout(5000); |
| | | con.setRequestProperty("Charset", "UTF-8"); |
| | | con.setRequestProperty("Content-Type", "application/json"); |
| | | if(header != null){ |
| | | for (Map.Entry<String, String> entry : header.entrySet()) { |
| | | con.setRequestProperty(entry.getKey(),entry.getValue()); |
| | | } |
| | | } |
| | | |
| | | if (data != null) { |
| | | OutputStream os = con.getOutputStream(); |
| | | os.write(data.getBytes("utf-8")); |
| | | } |
| | | |
| | | if (con.getResponseCode() != 200){ |
| | | throw new RuntimeException("请求url失败"); |
| | | } |
| | | // 读取返回内容 |
| | | wxMsgXml = IOUtils.toString(con.getInputStream(), "utf-8"); |
| | | // //System.out.println("HttpURLUtil:"+wxMsgXml); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (con != null) { |
| | | con.disconnect(); |
| | | } |
| | | } |
| | | return wxMsgXml; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.platform.util.corp; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.hx.mp.util.CorpMpUtil; |
| | | import com.platform.util.HttpPlatformUtil; |
| | | import com.platform.util.corp.entity.PersonnelQr; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.commons.collections.map.HashedMap; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Map; |
| | | |
| | | /**微信企业人员类 |
| | | * @author CJH |
| | | * @date 2021-10-21 |
| | | */ |
| | | public class PersonnelTool { |
| | | |
| | | /**用户详情信息*/ |
| | | public static final String USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"; |
| | | |
| | | /**企业微信,扫码登录 |
| | | * @param accessToken 企业token |
| | | * @param code 扫码code |
| | | * @return |
| | | */ |
| | | public static PersonnelQr qrLoginInfo(String accessToken, String code){ |
| | | |
| | | Map<String,Object> keyValues = new HashedMap(); |
| | | keyValues.put("access_token",accessToken); |
| | | keyValues.put("code",code); |
| | | String data = HttpPlatformUtil.HttpURLUtilJson(USER_INFO,null,keyValues,null,"POST"); |
| | | |
| | | return JSON.parseObject(data,PersonnelQr.class); |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.platform.util.corp.entity; |
| | | |
| | | |
| | | /**扫码登录授权的用户信息 |
| | | * @author CJH |
| | | * @date 2021-10-21 |
| | | */ |
| | | public class PersonnelQr { |
| | | /**返回码。若返回该字段,并且errcode!=0,为调用失败;*/ |
| | | private String errcode; |
| | | /**对返回码的文本描述内容。仅当errcode字段返回时,同时返回errmsg*/ |
| | | private String errmsg; |
| | | /**登录用户的类型:1.创建者 2.内部系统管理员 3.外部系统管理员 4.分级管理员 5.成员*/ |
| | | private String usertype; |
| | | /**登录用户的信息*/ |
| | | private PersonnelQrInfo personnelQrInfo; |
| | | |
| | | |
| | | public String getErrcode() { |
| | | return errcode; |
| | | } |
| | | |
| | | public void setErrcode(String errcode) { |
| | | this.errcode = errcode; |
| | | } |
| | | |
| | | public String getErrmsg() { |
| | | return errmsg; |
| | | } |
| | | |
| | | public void setErrmsg(String errmsg) { |
| | | this.errmsg = errmsg; |
| | | } |
| | | |
| | | public String getUsertype() { |
| | | return usertype; |
| | | } |
| | | |
| | | public void setUsertype(String usertype) { |
| | | this.usertype = usertype; |
| | | } |
| | | |
| | | public PersonnelQrInfo getPersonnelQrInfo() { |
| | | return personnelQrInfo; |
| | | } |
| | | |
| | | public void setPersonnelQrInfo(PersonnelQrInfo personnelQrInfo) { |
| | | this.personnelQrInfo = personnelQrInfo; |
| | | } |
| | | } |
New file |
| | |
| | | package com.platform.util.corp.entity; |
| | | |
| | | |
| | | /**扫码登录授权的用户信息-user_info |
| | | * @author CJH |
| | | * @date 2021-10-21 |
| | | */ |
| | | public class PersonnelQrInfo { |
| | | /**登录用户的userid,登录用户在通讯录中时返回*/ |
| | | private String userid; |
| | | /**全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。 登录用户在通讯录中返回*/ |
| | | private String open_userid; |
| | | /**登录用户的名字,登录用户在通讯录中时返回*/ |
| | | private String name; |
| | | /**登录用户的头像,登录用户在通讯录中时返回*/ |
| | | private String avatar; |
| | | |
| | | public String getUserid() { |
| | | return userid; |
| | | } |
| | | |
| | | public void setUserid(String userid) { |
| | | this.userid = userid; |
| | | } |
| | | |
| | | public String getOpen_userid() { |
| | | return open_userid; |
| | | } |
| | | |
| | | public void setOpen_userid(String open_userid) { |
| | | this.open_userid = open_userid; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getAvatar() { |
| | | return avatar; |
| | | } |
| | | |
| | | public void setAvatar(String avatar) { |
| | | this.avatar = avatar; |
| | | } |
| | | } |
New file |
| | |
| | | package com.platform.verification; |
| | | |
| | | |
| | | import com.hx.util.StringUtils; |
| | | import com.hx.util.rsa.RSAUtil; |
| | | import com.platform.resultTool.PlatformCode; |
| | | import com.platform.resultTool.PlatformResult; |
| | | |
| | | /**平台校验方法 |
| | | * @author CJH |
| | | * @date 2021-10-20 |
| | | */ |
| | | public class VerificationTool { |
| | | |
| | | /**校验方法请求 |
| | | * @param appId 用户的APPID |
| | | * @param sign 用户签名 |
| | | * @param sys_appId 系统的appid |
| | | * @param sys_private_key 系统的RSA秘钥 |
| | | * @return |
| | | */ |
| | | public static PlatformResult verification(String appId,String sign,String sys_appId,String sys_private_key){ |
| | | |
| | | if (StringUtils.isEmpty(sign)) { |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | } |
| | | if (StringUtils.isEmpty(appId)) { |
| | | return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误"); |
| | | } |
| | | |
| | | //校验appid是否存在 |
| | | if(!sys_appId.equals("appId")){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误"); |
| | | } |
| | | |
| | | //解密RSA |
| | | String decrypt = null; |
| | | try{ |
| | | decrypt = RSAUtil.privateDecrypt(sign, sys_private_key); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | if(StringUtils.isEmpty(decrypt)){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | } |
| | | |
| | | //decrypt格式:appId_时间戳_随机数(尽量少) |
| | | String[] decrypts = decrypt.split("_"); |
| | | if(decrypts.length != 3){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | } |
| | | |
| | | if (!appId.equals(decrypts[0])) { |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | } |
| | | return PlatformResult.success(); |
| | | } |
| | | |
| | | } |