From 6c1bfcd25d3bafcdf2765c5c9d0709a8f423eac4 Mon Sep 17 00:00:00 2001
From: chenjiahe <763432473@qq.com>
Date: 星期四, 21 十月 2021 12:09:31 +0800
Subject: [PATCH] 工具包

---
 src/main/java/com/platform/util/HttpPlatformUtil.java            |   79 +++++++
 src/main/java/com/platform/util/corp/entity/PersonnelQrInfo.java |   49 ++++
 src/main/java/com/platform/verification/VerificationTool.java    |   59 +++++
 /dev/null                                                        |   84 --------
 src/main/java/com/platform/util/corp/entity/PersonnelQr.java     |   50 +++++
 src/main/java/com/platform/exception/PlatServiceException.java   |   33 +++
 src/main/java/com/platform/resultTool/PlatformCode.java          |   31 +++
 src/main/java/com/platform/util/corp/PersonnelTool.java          |   38 +++
 src/main/java/com/platform/exception/PlatTipsException.java      |   36 +++
 src/main/java/com/platform/resultTool/SystemCode.java            |   16 +
 pom.xml                                                          |   15 
 src/main/java/com/platform/resultTool/PlatformResult.java        |   92 +++++++++
 12 files changed, 492 insertions(+), 90 deletions(-)

diff --git a/pom.xml b/pom.xml
index 72bb15e..d9081a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,19 +4,22 @@
          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>
diff --git a/src/main/java/com/platform/exception/PlatServiceException.java b/src/main/java/com/platform/exception/PlatServiceException.java
new file mode 100644
index 0000000..2e0b28a
--- /dev/null
+++ b/src/main/java/com/platform/exception/PlatServiceException.java
@@ -0,0 +1,33 @@
+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;
+    }
+}
diff --git a/src/main/java/com/platform/exception/PlatTipsException.java b/src/main/java/com/platform/exception/PlatTipsException.java
new file mode 100644
index 0000000..5008c7d
--- /dev/null
+++ b/src/main/java/com/platform/exception/PlatTipsException.java
@@ -0,0 +1,36 @@
+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;
+    }
+}
diff --git a/src/main/java/com/platform/resultTool/PlatformCode.java b/src/main/java/com/platform/resultTool/PlatformCode.java
new file mode 100644
index 0000000..3d03c3b
--- /dev/null
+++ b/src/main/java/com/platform/resultTool/PlatformCode.java
@@ -0,0 +1,31 @@
+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";
+
+
+}
+
diff --git a/src/main/java/com/platform/resultTool/PlatformResult.java b/src/main/java/com/platform/resultTool/PlatformResult.java
new file mode 100644
index 0000000..fb02e72
--- /dev/null
+++ b/src/main/java/com/platform/resultTool/PlatformResult.java
@@ -0,0 +1,92 @@
+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;
+    }
+
+}
+
diff --git a/src/main/java/com/platform/resultTool/ResponseCode.java b/src/main/java/com/platform/resultTool/ResponseCode.java
deleted file mode 100644
index 5bdb7ec..0000000
--- a/src/main/java/com/platform/resultTool/ResponseCode.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.platform.resultTool;
-
-/**
- * 缁熶竴鐘舵�佺爜
- * @author chenjiahe
- * @Data: 2020-06-20
- */
-public final class ResponseCode {
-
-    /*鎴愬姛*/
-    public static final String SUCCESS = "100";
-    /*閿欒鎻愮ず*/
-    public static final String ERROR_TIPS="200";
-    /*鍙傛暟楠岃瘉閿欒*/
-    public static final String ERROR_PARAMS_VALIDATOR="205";
-    /*涓氬姟楠岃瘉閿欒*/
-    public static final String ERROR_SERVICE_VALIDATOR="300";
-    /*绯荤粺鏁版嵁閿欒*/
-    public static final String ERROR_DATA_VALIDATOR="400";
-    /*鐧诲綍鏈夎*/
-    public static final String ERROR_LOGIN="603";
-    /*绯荤粺寮傚父*/
-    public static final String ERROR_SYSTEM = "999";
-    /*绛惧悕閿欒*/
-    public static final String ERROR_SIGN = "203";
-
-
-
-}
-
diff --git a/src/main/java/com/platform/resultTool/Result.java b/src/main/java/com/platform/resultTool/Result.java
deleted file mode 100644
index 1649efc..0000000
--- a/src/main/java/com/platform/resultTool/Result.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.platform.resultTool;
-
-import java.io.Serializable;
-
-/**
- * 缁熶竴杩斿洖鏍煎紡
- * @author chenjiahe
- * @Data: 2020-06-20
- */
-public class Result implements Serializable {
-
-    private static final long serialVersionUID = -3948389268046368059L;
-
-    private String code;
-
-    private String msg;
-
-    private Object data;
-
-    public Result() {}
-
-    public Result(String code, String msg) {
-        this.code = code;
-        this.msg = msg;
-    }
-
-    public static Result success() {
-        Result Result = new Result();
-        Result.setCode(ResponseCode.SUCCESS);
-        Result.setMsg("SUCCESS");
-        return Result;
-    }
-
-    public static Result success(Object data) {
-        Result Result = new Result();
-        Result.setCode(ResponseCode.SUCCESS);
-        Result.setData(data);
-        Result.setMsg("SUCCESS");
-        return Result;
-    }
-
-    public static Result failure(String code, String msg) {
-        Result Result = new Result();
-        Result.setCode(code);
-        Result.setMsg(msg);
-        return Result;
-    }
-
-    public static Result failure(String code, String msg, Object data) {
-        Result Result = new Result();
-        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;
-    }
-
-}
-
diff --git a/src/main/java/com/platform/resultTool/SystemCode.java b/src/main/java/com/platform/resultTool/SystemCode.java
new file mode 100644
index 0000000..57c0b71
--- /dev/null
+++ b/src/main/java/com/platform/resultTool/SystemCode.java
@@ -0,0 +1,16 @@
+package com.platform.resultTool;
+
+/**
+ * 骞冲彴缁熶竴閿欒鐮佺姸鎬佺爜
+ * @author chenjiahe
+ * @Data: 2020-06-20
+ */
+public final class SystemCode {
+
+    /*鑾峰彇浼佷笟token澶辫触*/
+    public static final String ERROR_GET_CORP_TOKEN = "001";
+
+
+
+}
+
diff --git a/src/main/java/com/platform/util/HttpPlatformUtil.java b/src/main/java/com/platform/util/HttpPlatformUtil.java
new file mode 100644
index 0000000..f676fd4
--- /dev/null
+++ b/src/main/java/com/platform/util/HttpPlatformUtil.java
@@ -0,0 +1,79 @@
+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鍙傛暟鍚嶇О锛寁alue鍙傛暟鍊�
+     * @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;
+    }
+
+}
diff --git a/src/main/java/com/platform/util/corp/PersonnelTool.java b/src/main/java/com/platform/util/corp/PersonnelTool.java
new file mode 100644
index 0000000..a6cabd2
--- /dev/null
+++ b/src/main/java/com/platform/util/corp/PersonnelTool.java
@@ -0,0 +1,38 @@
+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);
+
+    }
+
+}
diff --git a/src/main/java/com/platform/util/corp/entity/PersonnelQr.java b/src/main/java/com/platform/util/corp/entity/PersonnelQr.java
new file mode 100644
index 0000000..ef22069
--- /dev/null
+++ b/src/main/java/com/platform/util/corp/entity/PersonnelQr.java
@@ -0,0 +1,50 @@
+package com.platform.util.corp.entity;
+
+
+/**鎵爜鐧诲綍鎺堟潈鐨勭敤鎴蜂俊鎭�
+ * @author CJH
+ * @date 2021-10-21
+ */
+public class PersonnelQr {
+    /**杩斿洖鐮併�傝嫢杩斿洖璇ュ瓧娈碉紝骞朵笖errcode!=0锛屼负璋冪敤澶辫触锛�*/
+    private String errcode;
+    /**瀵硅繑鍥炵爜鐨勬枃鏈弿杩板唴瀹广�備粎褰揺rrcode瀛楁杩斿洖鏃讹紝鍚屾椂杩斿洖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;
+    }
+}
diff --git a/src/main/java/com/platform/util/corp/entity/PersonnelQrInfo.java b/src/main/java/com/platform/util/corp/entity/PersonnelQrInfo.java
new file mode 100644
index 0000000..74dff81
--- /dev/null
+++ b/src/main/java/com/platform/util/corp/entity/PersonnelQrInfo.java
@@ -0,0 +1,49 @@
+package com.platform.util.corp.entity;
+
+
+/**鎵爜鐧诲綍鎺堟潈鐨勭敤鎴蜂俊鎭�-user_info
+ * @author CJH
+ * @date 2021-10-21
+ */
+public class PersonnelQrInfo {
+    /**鐧诲綍鐢ㄦ埛鐨剈serid锛岀櫥褰曠敤鎴峰湪閫氳褰曚腑鏃惰繑鍥�*/
+    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;
+    }
+}
diff --git a/src/main/java/com/platform/verification/VerificationTool.java b/src/main/java/com/platform/verification/VerificationTool.java
new file mode 100644
index 0000000..705f492
--- /dev/null
+++ b/src/main/java/com/platform/verification/VerificationTool.java
@@ -0,0 +1,59 @@
+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 鐢ㄦ埛鐨凙PPID
+     * @param sign 鐢ㄦ埛绛惧悕
+     * @param sys_appId 绯荤粺鐨刟ppid
+     * @param sys_private_key 绯荤粺鐨凴SA绉橀挜
+     * @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閿欒");
+        }
+
+        //瑙e瘑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鏍煎紡锛歛ppId_鏃堕棿鎴砡闅忔満鏁帮紙灏介噺灏戯級
+        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();
+    }
+
+}

--
Gitblit v1.8.0