Преглед изворни кода

新增 身份证识别,营业执照识别,企查查

Administrator пре 1 година
родитељ
комит
885c460061

+ 203 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/Idcard/BusinessLicense.java

@@ -0,0 +1,203 @@
+package com.ruoyi.web.controller.Idcard;
+
+
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.utils.Base64Util;
+import com.ruoyi.common.utils.FileUtil;
+import com.ruoyi.common.utils.HttpUtil;
+
+import java.net.URLEncoder;
+/**
+ * 营业执照识别
+ * @Author: tjf
+ * @Date: 2024/4/17 9:57
+ * @Describe:
+ */
+public class BusinessLicense {
+
+    /**
+     * 重要提示代码中所需工具类
+     * FileUtil,Base64Util,HttpUtil,GsonUtils请从
+     * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
+     * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
+     * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
+     * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
+     * 下载
+     */
+    public static JSONObject businessLicense(String image) {
+        // 请求url
+        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license";
+        try {
+            // 本地文件路径
+            byte[] imgData = FileUtil.readFileByBytes(image);
+            String imgStr = Base64Util.encode(imgData);
+            String imgParam = URLEncoder.encode(imgStr, "UTF-8");
+
+            String param = "image=" + imgParam;
+
+            // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
+            String accessToken = Idcard.getAccessToken();
+
+            String result = HttpUtil.post(url, accessToken, param);
+            /**
+             *
+             {
+             "words_result": {
+             "经营范围": {
+             "location": {
+             "top": 589,
+             "left": 381,
+             "width": 90,
+             "height": 19
+             },
+             "words": "商务服务业"
+             },
+             "组成形式": {
+             "location": {
+             "top": -1,
+             "left": -1,
+             "width": 0,
+             "height": 0
+             },
+             "words": "无"
+             },
+             "法人": {
+             "location": {
+             "top": 537,
+             "left": 381,
+             "width": 36,
+             "height": 19
+             },
+             "words": "方平"
+             },
+             "证件编号": {
+             "location": {
+             "top": 218,
+             "left": 302,
+             "width": 140,
+             "height": 15
+             },
+             "words": "921MA190538210301"
+             },
+             "注册资本": {
+             "location": {
+             "top": 431,
+             "left": 1044,
+             "width": 152,
+             "height": 21
+             },
+             "words": "200万元"
+             },
+             "单位名称": {
+             "location": {
+             "top": 431,
+             "left": 384,
+             "width": 71,
+             "height": 20
+             },
+             "words": "有限公司"
+             },
+             "有效期": {
+             "location": {
+             "top": 536,
+             "left": 1044,
+             "width": 198,
+             "height": 20
+             },
+             "words": "长期"
+             },
+             "社会信用代码": {
+             "location": {
+             "top": 300,
+             "left": 241,
+             "width": 156,
+             "height": 16
+             },
+             "words": "10440119MA06M85"
+             },
+             "实收资本": {
+             "location": {
+             "top": -1,
+             "left": -1,
+             "width": 0,
+             "height": 0
+             },
+             "words": "无"
+             },
+             "有效期起始日期": {
+             "location": {
+             "top": 536,
+             "left": 1044,
+             "width": 198,
+             "height": 20
+             },
+             "words": "2019年01月01日"
+             },
+             "核准日期": {
+             "location": {
+             "top": 884,
+             "left": 1188,
+             "width": 199,
+             "height": 22
+             },
+             "words": "2019年01月01日"
+             },
+             "成立日期": {
+             "location": {
+             "top": 484,
+             "left": 1043,
+             "width": 126,
+             "height": 19
+             },
+             "words": "2019年01月01日"
+             },
+             "税务登记号": {
+             "location": {
+             "top": -1,
+             "left": -1,
+             "width": 0,
+             "height": 0
+             },
+             "words": "无"
+             },
+             "地址": {
+             "location": {
+             "top": 588,
+             "left": 1043,
+             "width": 55,
+             "height": 22
+             },
+             "words": "广州市"
+             },
+             "登记机关": {
+             "location": {
+             "top": 0,
+             "left": 0,
+             "width": 0,
+             "height": 0
+             },
+             "words": "无"
+             },
+             "类型": {
+             "location": {
+             "top": 484,
+             "left": 382,
+             "width": 258,
+             "height": 20
+             },
+             "words": "有限责任公司(自然人投资或控股)"
+             }
+             },
+             "direction": 0,
+             "words_result_num": 16,
+             "log_id": "3166723741167575145"
+             }
+             */
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            return jsonObject;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 330 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/Idcard/Idcard.java

@@ -0,0 +1,330 @@
+package com.ruoyi.web.controller.Idcard;
+
+/**
+ * @Author: tjf
+ * @Date: 2024/4/17 9:35
+ * @Describe:
+ */
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.utils.FileUtil;
+import com.ruoyi.common.utils.HttpUtil;
+import okhttp3.*;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.Base64;
+
+public class Idcard {
+
+    /**
+     * 重要提示代码中所需工具类
+     * FileUtil,HttpUtil请从
+     * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
+     * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
+     * 下载
+     * <p>
+     * https://cloud.baidu.com/doc/OCR/s/rk3h7xzck 文档地址
+     */
+
+    // 请求url
+    static String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";
+
+    // aes key 从console控制台获取
+    static String aesKey = "[16位 aeskey]";
+
+    static byte[] originAesKey = null;
+
+    /**
+     * 身份证识别
+     * {
+     * "log_id": "1559208562721579319",
+     * "direction": 0,
+     * "image_status": "normal",
+     * "photo": "/9j/4AAQSkZJRgABA......",
+     * "photo_location": {
+     * "width": 1189,
+     * "top": 638,
+     * "left": 2248,
+     * "height": 1483
+     * },
+     * "card_image": "/9j/4AAQSkZJRgABA......",
+     * "card_location": {
+     * "top": 328,
+     * "left": 275,
+     * "width": 1329,
+     * "height": 571
+     * },
+     * "words_result": {
+     * "住址": {
+     * "location": {
+     * "left": 267,
+     * "top": 453,
+     * "width": 459,
+     * "height": 99
+     * },
+     * "words": "南京市江宁区弘景大道3889号"
+     * },
+     * "公民身份号码": {
+     * "location": {
+     * "left": 443,
+     * "top": 681,
+     * "width": 589,
+     * "height": 45
+     * },
+     * "words": "330881199904173914"
+     * },
+     * "出生": {
+     * "location": {
+     * "left": 270,
+     * "top": 355,
+     * "width": 357,
+     * "height": 45
+     * },
+     * "words": "19990417"
+     * },
+     * "姓名": {
+     * "location": {
+     * "left": 267,
+     * "top": 176,
+     * "width": 152,
+     * "height": 50
+     * },
+     * "words": "伍云龙"
+     * },
+     * "性别": {
+     * "location": {
+     * "left": 269,
+     * "top": 262,
+     * "width": 33,
+     * "height": 52
+     * },
+     * "words": "男"
+     * },
+     * "民族": {
+     * "location": {
+     * "left": 492,
+     * "top": 279,
+     * "width": 30,
+     * "height": 37
+     * },
+     * "words": "汉"
+     * }
+     * },
+     * "words_result_num": 6
+     * }
+     *
+     * @return
+     */
+    public static JSONObject idcard(String image) {
+        try {
+            // 文件路径
+            byte[] imgData = FileUtil.readFileByBytes(image);
+
+            String imgStr = encryptImg(aesKey, imgData);
+
+            String imgParam = URLEncoder.encode(imgStr, "UTF-8");
+
+            String param = "id_card_side=" + "front" +
+                    "&image=" + imgParam +
+                    "&AESEncry=" + true;
+
+            String accessToken = getAccessToken();
+
+            String encryptResult = HttpUtil.post(url, accessToken, param);
+
+            String decryptResult = parseResult(encryptResult);
+            JSONObject jsonObject = JSON.parseObject(decryptResult);
+            return jsonObject;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 加密图片
+     *
+     * @param aesKey
+     * @param imgData
+     * @return
+     * @throws Exception
+     */
+    private static String encryptImg(String aesKey, byte[] imgData) throws Exception {
+        originAesKey = AesKeyUtil.parseAesKey(aesKey);
+        byte[] encImgBytes = AesUtil.encrypt(imgData, originAesKey);
+        String imgStr = Base64Util.encodeBase64(encImgBytes);
+        return imgStr;
+    }
+
+    /**
+     * 解密结果
+     *
+     * @param encryptResult
+     * @return
+     * @throws Exception
+     */
+    private static String parseResult(String encryptResult) throws Exception {
+        JSONObject obj = JSONObject.parseObject(encryptResult);
+        String result = obj.getString("result");
+        byte[] arr = Base64Util.decodeBase64(result);
+        String decryptResult = new String(AesUtil.decrypt(arr, originAesKey));
+        return decryptResult;
+    }
+
+
+    static class AesKeyUtil {
+        private static final String HEX = "0123456789abcdef";
+
+        /**
+         * 获得原生的128位的aeskey
+         * 因为一个byte位8位最后生成的byte数组长度为16
+         * <p>
+         * 16 * 8 = 128
+         *
+         * @param hex
+         * @return
+         */
+        public static byte[] parseAesKey(String hex) throws Exception {
+            char[] data = hex.toCharArray();
+            if (data.length != 16) {
+                throw new Exception(" ase key illegal ");
+            }
+            return decode(hex.toCharArray());
+        }
+
+        private static byte[] decode(char[] data) throws IllegalArgumentException {
+            int len = data.length;
+
+            byte[] out = new byte[len];
+
+            for (int i = 0; i < len; i++) {
+                int f = toDigit(data[i]);
+                out[i] = (byte) (f);
+            }
+            return out;
+        }
+
+        private static int toDigit(char ch) {
+            return HEX.indexOf(ch);
+        }
+    }
+
+    static class AesUtil {
+
+        private static final String ALGORITHM = "AES";
+
+        private static final String ALGORITHM_STR = "AES/ECB/PKCS5Padding";
+
+        /**
+         * aes 加密
+         */
+        private static byte[] encrypt(byte[] src, byte[] aesKey) throws Exception {
+            Cipher cipher = getCipher(aesKey, Cipher.ENCRYPT_MODE);
+            byte[] ret = cipher.doFinal(src);
+            return ret;
+        }
+
+        /**
+         * aes 解密
+         */
+        public static byte[] decrypt(byte[] src, byte[] aesKey) throws Exception {
+            Cipher cipher = getCipher(aesKey, Cipher.DECRYPT_MODE);
+            byte[] original = cipher.doFinal(src);
+            return original;
+        }
+
+        private static Cipher getCipher(byte[] aesKey, int mode) throws Exception {
+            SecretKeySpec secretKeySpec = new SecretKeySpec(aesKey, ALGORITHM);
+            Cipher cipher = Cipher.getInstance(ALGORITHM_STR);
+            cipher.init(mode, secretKeySpec);
+            return cipher;
+        }
+    }
+
+    static class Base64Util {
+
+        private static Base64.Encoder ENCODER = Base64.getEncoder();
+
+        // base64 加密
+        private static Base64.Decoder DECODER = Base64.getDecoder();
+
+        /**
+         * base64加密
+         *
+         * @param arr
+         * @return
+         */
+        private static String encodeBase64(byte[] arr) {
+            String base64 = null;
+            try {
+                base64 = ENCODER.encodeToString(arr);
+            } catch (Exception e) {
+            }
+            return base64;
+        }
+
+        /**
+         * base64解密
+         *
+         * @param str
+         * @return
+         */
+        public static byte[] decodeBase64(String str) {
+            byte[] encodeBase64 = new byte[0];
+            try {
+                encodeBase64 = DECODER.decode(str);
+            } catch (Exception e) {
+            }
+            return encodeBase64;
+        }
+    }
+
+
+    static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
+
+    /**
+     * 获取百度开放平台的AccessToken
+     * @return
+     */
+    public static String getAccessToken() {
+        MediaType mediaType = MediaType.parse("application/json");
+        RequestBody body = RequestBody.create(mediaType, "");
+        String url = "https://aip.baidubce.com/oauth/2.0/token";
+        /**
+         * grant_type: 必须参数,固定为client_credentials;
+         * client_id: 必须参数,应用的API Key;
+         * client_secret: 必须参数,应用的Secret Key;
+         */
+        String grantType = "client_credentials";
+        String clientId = "11111111111111";
+        String clientSecret = "22222222222222222";
+        String apiUrl = String.format("%s?grant_type=%s&client_id=%s&client_secret=%s",
+                url, grantType, clientId, clientSecret);
+
+        Request request = new Request.Builder()
+                .url(apiUrl)
+                .method("POST", body)
+                .addHeader("Content-Type", "application/json")
+                .addHeader("Accept", "application/json")
+                .build();
+        Response response = null;
+        try {
+            response = HTTP_CLIENT.newCall(request).execute();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        //todo 判断是否成功调用
+        //取出返回的access_token
+        JSONObject jsonObject = null;
+        String accessToken = null;
+        if (response != null) {
+            jsonObject = JSON.parseObject(response.toString());
+            accessToken = jsonObject.getString("access_token");
+        }
+        return accessToken;
+    }
+}

+ 0 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SendSmsController.java

@@ -48,6 +48,5 @@ public class SendSmsController {
             return AjaxResult.success();
         }
         return AjaxResult.error("当前手机号不存在");
-
     }
 }

+ 56 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/qichacha/QiChaCha.java

@@ -0,0 +1,56 @@
+package com.ruoyi.web.controller.qichacha;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.http.HttpUtils;
+import com.ruoyi.common.utils.sign.Md5Utils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Author: tjf
+ * @Date: 2024/4/17 10:24
+ * @Describe:
+ */
+public class QiChaCha extends BaseController {
+    /**
+     * 企查查
+     */
+    private static final String KEY = "e50f4b2011ea41a3ad489f0476160041";
+    private static final String SECRET_KEY = "BD8D23FCD36CDEE7E0B25DAB28588163";
+    /**
+     * 通过企查查,查询企业信息
+     *
+     * @param searchKey
+     * @return
+     */
+    @GetMapping("/qichachaSearch/{searchKey}")
+    public AjaxResult qichachaSearch(@PathVariable("searchKey") String searchKey) {
+        if (StringUtils.isNotBlank(searchKey)){
+            //Headers头信息
+            Map<String,String> map = new HashMap<>();
+            StringBuilder sb = new StringBuilder();
+            String unix = DateUtils.getUnix();
+            map.put("Timespan", unix);
+            sb.append(KEY).append(unix).append(SECRET_KEY);
+            map.put("Token", Md5Utils.hash(sb.toString()).toUpperCase());
+            StringBuilder sbd = new StringBuilder();
+            sbd.append("key=").append(KEY).append("&").append("searchKey=").append(searchKey);
+            String s = HttpUtils.sendGetMap("https://api.qichacha.com/FuzzySearch/GetList",sbd.toString(),map);
+            JSONObject result = JSONObject.parseObject(s);
+            JSONArray resultOut = result.getJSONArray("Result");
+            if (resultOut != null){
+                return AjaxResult.success(resultOut);
+            }
+        }
+        return AjaxResult.success(new ArrayList<>());
+    }
+}

+ 65 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/Base64Util.java

@@ -0,0 +1,65 @@
+package com.ruoyi.common.utils;
+
+/**
+ * Base64 工具类
+ */
+public class Base64Util {
+    private static final char last2byte = (char) Integer.parseInt("00000011", 2);
+    private static final char last4byte = (char) Integer.parseInt("00001111", 2);
+    private static final char last6byte = (char) Integer.parseInt("00111111", 2);
+    private static final char lead6byte = (char) Integer.parseInt("11111100", 2);
+    private static final char lead4byte = (char) Integer.parseInt("11110000", 2);
+    private static final char lead2byte = (char) Integer.parseInt("11000000", 2);
+    private static final char[] encodeTable = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
+
+    public Base64Util() {
+    }
+
+    public static String encode(byte[] from) {
+        StringBuilder to = new StringBuilder((int) ((double) from.length * 1.34D) + 3);
+        int num = 0;
+        char currentByte = 0;
+
+        int i;
+        for (i = 0; i < from.length; ++i) {
+            for (num %= 8; num < 8; num += 6) {
+                switch (num) {
+                    case 0:
+                        currentByte = (char) (from[i] & lead6byte);
+                        currentByte = (char) (currentByte >>> 2);
+                    case 1:
+                    case 3:
+                    case 5:
+                    default:
+                        break;
+                    case 2:
+                        currentByte = (char) (from[i] & last6byte);
+                        break;
+                    case 4:
+                        currentByte = (char) (from[i] & last4byte);
+                        currentByte = (char) (currentByte << 2);
+                        if (i + 1 < from.length) {
+                            currentByte = (char) (currentByte | (from[i + 1] & lead2byte) >>> 6);
+                        }
+                        break;
+                    case 6:
+                        currentByte = (char) (from[i] & last2byte);
+                        currentByte = (char) (currentByte << 4);
+                        if (i + 1 < from.length) {
+                            currentByte = (char) (currentByte | (from[i + 1] & lead4byte) >>> 4);
+                        }
+                }
+
+                to.append(encodeTable[currentByte]);
+            }
+        }
+
+        if (to.length() % 4 != 0) {
+            for (i = 4 - to.length() % 4; i > 0; --i) {
+                to.append("=");
+            }
+        }
+
+        return to.toString();
+    }
+}

+ 8 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -188,4 +188,12 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
+    /**
+     * 获取时间戳
+     *
+     * @return
+     */
+    public static String getUnix() {
+        return Long.toString(System.currentTimeMillis() / 1000L);
+    }
 }

+ 72 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/FileUtil.java

@@ -0,0 +1,72 @@
+package com.ruoyi.common.utils;
+
+import java.io.*;
+
+/**
+ * 文件读取工具类
+ */
+public class FileUtil {
+
+    /**
+     * 读取文件内容,作为字符串返回
+     */
+    public static String readFileAsString(String filePath) throws IOException {
+        File file = new File(filePath);
+        if (!file.exists()) {
+            throw new FileNotFoundException(filePath);
+        } 
+
+        if (file.length() > 1024 * 1024 * 1024) {
+            throw new IOException("File is too large");
+        } 
+
+        StringBuilder sb = new StringBuilder((int) (file.length()));
+        // 创建字节输入流  
+        FileInputStream fis = new FileInputStream(filePath);  
+        // 创建一个长度为10240的Buffer
+        byte[] bbuf = new byte[10240];  
+        // 用于保存实际读取的字节数  
+        int hasRead = 0;  
+        while ( (hasRead = fis.read(bbuf)) > 0 ) {  
+            sb.append(new String(bbuf, 0, hasRead));  
+        }  
+        fis.close();  
+        return sb.toString();
+    }
+
+    /**
+     * 根据文件路径读取byte[] 数组
+     */
+    public static byte[] readFileByBytes(String filePath) throws IOException {
+        File file = new File(filePath);
+        if (!file.exists()) {
+            throw new FileNotFoundException(filePath);
+        } else {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length());
+            BufferedInputStream in = null;
+
+            try {
+                in = new BufferedInputStream(new FileInputStream(file));
+                short bufSize = 1024;
+                byte[] buffer = new byte[bufSize];
+                int len1;
+                while (-1 != (len1 = in.read(buffer, 0, bufSize))) {
+                    bos.write(buffer, 0, len1);
+                }
+
+                byte[] var7 = bos.toByteArray();
+                return var7;
+            } finally {
+                try {
+                    if (in != null) {
+                        in.close();
+                    }
+                } catch (IOException var14) {
+                    var14.printStackTrace();
+                }
+
+                bos.close();
+            }
+        }
+    }
+}

+ 77 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java

@@ -0,0 +1,77 @@
+package com.ruoyi.common.utils;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * http 工具类
+ */
+public class HttpUtil {
+
+    public static String post(String requestUrl, String accessToken, String params)
+            throws Exception {
+        String contentType = "application/x-www-form-urlencoded";
+        return HttpUtil.post(requestUrl, accessToken, contentType, params);
+    }
+
+    public static String post(String requestUrl, String accessToken, String contentType, String params)
+            throws Exception {
+        String encoding = "UTF-8";
+        if (requestUrl.contains("nlp")) {
+            encoding = "GBK";
+        }
+        return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding);
+    }
+
+    public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding)
+            throws Exception {
+        String url = requestUrl + "?access_token=" + accessToken;
+        return HttpUtil.postGeneralUrl(url, contentType, params, encoding);
+    }
+
+    public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding)
+            throws Exception {
+        URL url = new URL(generalUrl);
+        // 打开和URL之间的连接
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        connection.setRequestMethod("POST");
+        // 设置通用的请求属性
+        connection.setRequestProperty("Content-Type", contentType);
+        connection.setRequestProperty("Connection", "Keep-Alive");
+        connection.setUseCaches(false);
+        connection.setDoOutput(true);
+        connection.setDoInput(true);
+
+        // 得到请求的输出流对象
+        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
+        out.write(params.getBytes(encoding));
+        out.flush();
+        out.close();
+
+        // 建立实际的连接
+        connection.connect();
+        // 获取所有响应头字段
+        Map<String, List<String>> headers = connection.getHeaderFields();
+        // 遍历所有的响应头字段
+        for (String key : headers.keySet()) {
+            System.err.println(key + "--->" + headers.get(key));
+        }
+        // 定义 BufferedReader输入流来读取URL的响应
+        BufferedReader in = null;
+        in = new BufferedReader(
+                new InputStreamReader(connection.getInputStream(), encoding));
+        String result = "";
+        String getLine;
+        while ((getLine = in.readLine()) != null) {
+            result += getLine;
+        }
+        in.close();
+        System.err.println("result:" + result);
+        return result;
+    }
+}

+ 80 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java

@@ -11,6 +11,7 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
 import java.security.cert.X509Certificate;
+import java.util.Map;
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLContext;
@@ -271,4 +272,83 @@ public class HttpUtils
             return true;
         }
     }
+
+    /**
+     * 向指定 URL 发送GET方法的请求
+     *
+     * @param url 发送请求的 URL
+     * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+     * @return 所代表远程资源的响应结果
+     */
+    public static String sendGetMap(String url, String param, Map<String,String> map)
+    {
+        return sendGetMap(url, param, Constants.UTF8,map);
+    }
+    /**
+     * 向指定 URL 发送GET方法的请求(接收一个MAP头信息)
+     *
+     * @param url 发送请求的 URL
+     * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+     * @param contentType 编码类型
+     * @return 所代表远程资源的响应结果
+     */
+    public static String sendGetMap(String url, String param, String contentType, Map<String,String> map)
+    {
+        StringBuilder result = new StringBuilder();
+        BufferedReader in = null;
+        try
+        {
+            String urlNameString = url + "?" + param;
+            log.info("sendGet - {}", urlNameString);
+            URL realUrl = new URL(urlNameString);
+            URLConnection connection = realUrl.openConnection();
+            connection.setRequestProperty("accept", "*/*");
+            connection.setRequestProperty("connection", "Keep-Alive");
+            connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+            if (map != null && map.size() > 0){
+                for (String key : map.keySet()) {
+                    connection.setRequestProperty(key,map.get(key));
+                }
+            }
+            connection.connect();
+            in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
+            String line;
+            while ((line = in.readLine()) != null)
+            {
+                result.append(line);
+            }
+            log.info("recv - {}", result);
+        }
+        catch (ConnectException e)
+        {
+            log.error("调用HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e);
+        }
+        catch (SocketTimeoutException e)
+        {
+            log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e);
+        }
+        catch (IOException e)
+        {
+            log.error("调用HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e);
+        }
+        catch (Exception e)
+        {
+            log.error("调用HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e);
+        }
+        finally
+        {
+            try
+            {
+                if (in != null)
+                {
+                    in.close();
+                }
+            }
+            catch (Exception ex)
+            {
+                log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
+            }
+        }
+        return result.toString();
+    }
 }