liuyc 1 éve
szülő
commit
99c2308f8e

+ 5 - 1
blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java

@@ -68,6 +68,11 @@ public interface CommonConstant {
 
     String SG_THE_LOG = "SG.theLog";
 
+    /**
+     * 白马公司ids
+     */
+    String BM_COMPANY_IDS = "bm.company.ids";
+
     /**
      * 默认排序字段
      */
@@ -83,5 +88,4 @@ public interface CommonConstant {
      */
     Integer API_SCOPE_CATEGORY = 2;
 
-
 }

+ 17 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/bean/GetBMTokenDTO.java

@@ -0,0 +1,17 @@
+package org.springblade.system.user.bean;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+public class GetBMTokenDTO implements Serializable {
+
+    private String uuid;
+    private String username;
+    private String password;
+    private String source;
+
+}

+ 306 - 33
blade-service/blade-user/src/main/java/org/springblade/system/user/thirdparty/ThirdPartySystemApi.java

@@ -2,7 +2,9 @@ package org.springblade.system.user.thirdparty;
 
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.Consts;
@@ -13,22 +15,34 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.message.BasicNameValuePair;
+import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.DigestUtil;
+import org.springblade.core.tool.utils.ObjectUtil;
+import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.feign.SaveUserInfoByProjectClient;
 import org.springblade.system.entity.AuthClient;
+import org.springblade.system.user.bean.GetBMTokenDTO;
 import org.springblade.system.user.bean.GetTokenDTO;
 import org.springblade.system.user.entity.User;
+import org.springblade.system.user.service.IUserService;
+import org.springblade.system.user.util.AesInfoUtil;
+import org.springblade.system.user.util.HttpClientUtil;
+import org.springblade.system.user.util.RsaUtilToken;
 import org.springblade.system.user.util.RsaUtils;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.data.redis.core.RedisTemplate;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.text.ParseException;
+import java.time.Duration;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
@@ -46,55 +60,85 @@ public class ThirdPartySystemApi {
 
     private final JdbcTemplate jdbcTemplate;
     private final RedisTemplate<String, String> redisTemplate;
+    private final IUserService userService;
+    private final SaveUserInfoByProjectClient saveUserInfoByProjectClient;
+
+    /*白马相关常量*/
+    private final static String IP_PORT = "http://219.152.86.38:13427";
+    private final static String PK_URL = IP_PORT + "/prod-api/auth/touch";
+    private final static String TOKEN_URL = IP_PORT + "/prod-api/auth/login";
+    private final static String USER_LIST_URL = IP_PORT + "/prod-api/openapi/biz-v1/user/list";
+    private final static String USERNAME = "白马质检";
+    private final static String PASSWORD = "Bmzj@654321";
+    private final static String SOURCE = "HongChuangBm";
+    private final static String APP_KEY = "9F3C78FC22D07EAB2AEB4DD6CA9644DB";
 
     /**
-     * 获取公钥信息
+     * 根据appKey获取本系统的公钥信息
+     *
+     * @param appKey = blade_client id
      */
     @GetMapping("/auth/public-key")
     public Map<String, Object> getPublicKey(@RequestParam String appKey) {
-        /*查询Redis中已有的键值对数量*/
-        String redisKeyPattern = "bm-secret-key:*";
-        if (Objects.requireNonNull(redisTemplate.keys(redisKeyPattern)).size() >= 10) {
-            throw new ServiceException("请求频率超过限制,请2分钟后重试");
-        }
-
+        Map<String, Object> resultMap = new HashMap<>();
         if (StringUtils.isEmpty(appKey)) {
-            throw new ServiceException("appKey不能为空");
-        }
-        if (!isValidAppKey(appKey)) {
-            throw new ServiceException("appKey验证失败");
+            resultMap.put("uuid", null);
+            resultMap.put("pk", null);
+            resultMap.put("code", 500);
+            resultMap.put("msg", "param cannot be null");
+            return resultMap;
         }
 
-        /*创建秘钥对*/
-        Map<String, String> keyPair = RsaUtils.createKeyPair();
-        String pk = keyPair.get("pk");
-        String sk = keyPair.get("sk");
-        Long uuid = SnowFlakeUtil.getId();
+        /*Redis加锁,10秒过期*/
+        String lockRedisKey = "bm-secret-key-request-limit:" + appKey;
+        Long currentTime = System.currentTimeMillis();
+        Boolean isAbsent = redisTemplate.opsForValue().setIfAbsent(lockRedisKey, String.valueOf(currentTime), Duration.ofSeconds(10));
 
-        Map<String, Object> resultMap = new HashMap<>();
-        try {
-            //存储到Redis,并设置过期时间为2分钟
-            String redisKey = "bm-secret-key:" + uuid;
-            redisTemplate.opsForValue().set(redisKey + ":pk", pk, 2, TimeUnit.MINUTES);
-            redisTemplate.opsForValue().set(redisKey + ":sk", sk, 2, TimeUnit.MINUTES);
-
-            resultMap.put("uuid", uuid);
-            resultMap.put("pk", pk);
-            resultMap.put("code", 200);
-            resultMap.put("msg", "操作成功");
-            return resultMap;
-        } catch (Exception e) {
+        if (isAbsent != null && isAbsent) {
+            if (!isValidAppKey(appKey)) {
+                resultMap.put("uuid", null);
+                resultMap.put("pk", null);
+                resultMap.put("code", 500);
+                resultMap.put("msg", "appKey authentication failed");
+                return resultMap;
+            }
+
+            /*创建秘钥对*/
+            Map<String, String> keyPair = RsaUtils.createKeyPair();
+            String pk = keyPair.get("pk");
+            String sk = keyPair.get("sk");
+            Long uuid = SnowFlakeUtil.getId();
+
+            try {
+                /*存储到Redis,2分钟过期*/
+                String redisKey = "bm-secret-key:" + uuid;
+                redisTemplate.opsForValue().set(redisKey + ":pk", pk, 2, TimeUnit.MINUTES);
+                redisTemplate.opsForValue().set(redisKey + ":sk", sk, 2, TimeUnit.MINUTES);
+
+                resultMap.put("uuid", uuid);
+                resultMap.put("pk", pk);
+                resultMap.put("code", 200);
+                resultMap.put("msg", "操作成功");
+                return resultMap;
+            } catch (Exception e) {
+                resultMap.put("uuid", null);
+                resultMap.put("pk", null);
+                resultMap.put("code", 500);
+                resultMap.put("msg", e.getMessage());
+                return resultMap;
+            }
+        } else {
             resultMap.put("uuid", null);
             resultMap.put("pk", null);
-            resultMap.put("code", 400);
-            resultMap.put("msg", e.getMessage());
+            resultMap.put("code", 500);
+            resultMap.put("msg", "try again in 10 seconds");
             return resultMap;
         }
     }
 
     private boolean isValidAppKey(String appKey) {
         List<AuthClient> bladeClients = jdbcTemplate.query(
-                "SELECT (1) FROM blade_client WHERE client_id = ?",
+                "SELECT (1) FROM blade_client WHERE id = ? AND status = 1 AND is_deleted = 0",
                 new Object[]{appKey},
                 new BeanPropertyRowMapper<>(AuthClient.class)
         );
@@ -102,7 +146,9 @@ public class ThirdPartySystemApi {
     }
 
     /**
-     * 获取token
+     * 根据idcard获取本系统的token信息
+     *
+     * @param dto
      */
     @PostMapping("/auth/token")
     public R<Object> getToken(@RequestBody GetTokenDTO dto) {
@@ -188,6 +234,7 @@ public class ThirdPartySystemApi {
         return R.data(451, null, "未获取到对应的私钥信息");
     }
 
+
     /*public static void main(String[] args) {
         //公钥
         String pk = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJnZ0kMi0AG9sR97sdRD0/kqX9a7kSsVM56DUwmEbxf9n5SW0aRwxYcoyZQUC7ZW2MrXSNbzwbtmdD0RfQ4TJI0CAwEAAQ==";
@@ -201,5 +248,231 @@ public class ThirdPartySystemApi {
         System.out.println("Encrypted Id Card: " + encryptedIdCard);
     }*/
 
+
+    /**
+     * 获取白马系统token
+     *
+     * @return
+     */
+    public static R<Object> getBMToken() {
+        /*获取uuid与公钥*/
+        Map<String, String> param = new HashMap<>();
+        param.put("appKey", APP_KEY);
+        String pkAndUuid = HttpClientUtil.doGet(PK_URL, param);
+        JSONObject jsonObject = JSON.parseObject(pkAndUuid);
+        String pk = jsonObject.getString("pk");
+        String uuid = jsonObject.getString("uuid");
+        String code = jsonObject.getString("code");
+        /*获取token*/
+        if (StringUtils.isNotEmpty(pk) && StringUtils.isNotEmpty(uuid) && ("200").equals(code)) {
+            String username = RsaUtilToken.encryptWithPk(USERNAME, pk);
+            String password = RsaUtilToken.encryptWithPk(PASSWORD, pk);
+            //移除换行符
+            String usernameRe = username.replaceAll("\\r|\\n", "");
+            String passwordRe = password.replaceAll("\\r|\\n", "");
+
+            String result = HttpClientUtil.doPostJson(TOKEN_URL, JSON.toJSONString(new GetBMTokenDTO(uuid, usernameRe, passwordRe, SOURCE)));
+            return R.data(result);
+        } else {
+            return R.data(jsonObject);
+        }
+    }
+
+
+    /*public static void main(String[] args) {
+     *//*Object data = getBMToken().getData();
+        System.out.println(data);*//*
+
+        syncBMUserInfosToSystemProject();
+    }*/
+
+
+    /**
+     * 同步白马用户信息到系统项目中
+     */
+    /*@Scheduled(cron = "0 0 4 * * ?")*/
+    @PostMapping("/auth/test666")
+    public void syncBMUserInfosToSystemProject() {
+        /*获取token*/
+        Object dataR = getBMToken().getData();
+        JSONObject jsonObject = JSON.parseObject(String.valueOf(dataR));
+        String code = jsonObject.getString("code");
+        String dataToken = jsonObject.getString("data");
+        JSONObject jsonObjectToken = JSON.parseObject(dataToken);
+        String token = jsonObjectToken.getString("access_token");
+
+        if (("200").equals(code) && StringUtils.isNotEmpty(token)) {
+            /*获取白马公司ids*/
+            //String bmCompanyIds = CommonConstant.BM_COMPANY_IDS;
+
+            /*测试公司id*/
+            String bmCompanyIds = "1722072427562467328";
+
+            String[] bmCompanyIdsArr = bmCompanyIds.split(",");
+            for (String companyId : bmCompanyIdsArr) {
+                /*获取用户信息*/
+                Map<String, String> param = new HashMap<>();
+                param.put("pid", companyId);
+                String responseData = HttpClientUtil.doGet(USER_LIST_URL, param, token);
+
+                /*解析响应数据*/
+                JSONObject jsonObjectResponse = JSONObject.parseObject(responseData);
+                String responseStringCode = jsonObjectResponse.getString("code");
+                if (("200").equals(responseStringCode)) {
+                    JSONArray userList = jsonObjectResponse.getJSONArray("data");
+                    if (userList != null && userList.size() >= 1) {
+                        for (int i = 0; i < userList.size(); i++) {
+                            JSONObject jsonUser = userList.getJSONObject(i);
+                            String userid = jsonUser.getString("userid");
+                            //String username = jsonUser.getString("username");
+                            String nickname = jsonUser.getString("nickname");
+                            String idCard = jsonUser.getString("idcard");
+                            String phone = jsonUser.getString("phonenumber");
+                            String status = jsonUser.getString("status");
+
+                            JSONArray companies = jsonUser.getJSONArray("companies");
+                            if (companies != null && companies.size() >= 1) {
+                                for (int j = 0; j < companies.size(); j++) {
+                                    JSONObject companiesJSONObject = companies.getJSONObject(j);
+                                    //String companiesId = companiesJSONObject.getString("id");
+                                    String companyName = companiesJSONObject.getString("name");
+
+                                    if (companyName.contains("重庆白马航运发展有限公司")
+                                            || companyName.contains("四川二滩国际工程咨询有限责任公司")
+                                            || companyName.contains("中国水利水电第四工程局中电建路桥集团联合体")
+                                            || companyName.contains("中国水利水电第八工程局有限公司")
+                                            || companyName.contains("重庆市交通工程监理咨询有限责任公司")
+                                            || companyName.contains("中铁长江交通设计集团有限公司")
+                                            || companyName.contains("中铁八局集团有限公司")) {
+                                        List<User> sysUser = userService.getBaseMapper().selectList(Wrappers.<User>lambdaQuery().eq(User::getSysType, 2).apply("(sys_id = '" + userid + "' OR id_number = '" + idCard + "')"));
+
+                                        /*修改电话号码*/
+                                        if (sysUser.size() > 0 && ObjectUtil.isNotEmpty(phone) && phone.length() == 11) {
+                                            for (User user : sysUser) {
+                                                if (ObjectUtil.isEmpty(user.getPhone())) {
+                                                    userService.lambdaUpdate()
+                                                            .set(User::getPhone, phone)
+                                                            .eq(User::getId, user.getId())
+                                                            .update();
+                                                }
+                                            }
+                                        }
+
+                                        /*只有本系统不存在时才去新增*/
+                                        if (sysUser.size() == 0L) {
+                                            User newUser = new User();
+                                            newUser.setId(SnowFlakeUtil.getId());
+                                            newUser.setDeptId("1588069957940674562"); //白马部门
+
+                                            newUser.setSysType(9); //之前=2是表示同步,现在由于修改了接口,改为9,以便处理数据
+
+                                            newUser.setIsDeleted(0);
+                                            newUser.setCreateUser(Long.parseLong("1541381503819694081"));
+                                            newUser.setUpdateUser(Long.parseLong("1541381503819694081"));
+                                            newUser.setTenantId("000000");
+                                            newUser.setSysId(userid);
+                                            newUser.setUpdateTime(new Date());
+                                            newUser.setCreateTime(new Date());
+                                            newUser.setUserType("1,2");
+                                            newUser.setAccount(idCard);
+                                            newUser.setRealName(nickname);
+                                            newUser.setName(nickname);
+                                            newUser.setPassword("10470c3b4b1fed12c3baac014be15fac67c6e815");
+                                            newUser.setPlaintextPassword("123456");
+                                            newUser.setName(nickname);
+                                            newUser.setStatus(Integer.parseInt(status));
+                                            newUser.setIdNumber(idCard);
+                                            newUser.setCompanyName(companyName);
+                                            newUser.setPhone(ObjectUtil.isNotEmpty(phone) && phone.length() == 11 ? phone : null);
+
+                                            /*所有合同段(白马)*/
+                                            if (companyName.contains("重庆白马航运发展有限公司")) {
+                                                List<ContractInfo> contractInfos = jdbcTemplate.query("select id from m_contract_info where p_id = 1612329251049537537 and is_deleted = 0 and status = 1", new BeanPropertyRowMapper<>(ContractInfo.class));
+                                                for (ContractInfo contractInfo : contractInfos) {
+                                                    Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and project_id = 1612329251049537537 " + " and contract_id = " + contractInfo.getId() + " and post_id is null " + " and status = 1 and is_deleted = 0", Long.class);
+                                                    if (count == null || count == 0L) {
+                                                        /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;所有合同段id:contractInfo.getId();角色施工-资料员id:1537249581371707394*/
+                                                        saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, contractInfo.getId(), 1537249581371707394L);
+                                                        newUser.setRoleId("1537249581371707394");
+                                                    }
+                                                }
+                                            }
+
+                                            /*二期合同段(八局、二滩、长江设计单位、中国水利水电第八工程局有限公司)*/
+                                            if (companyName.contains("中铁八局集团有限公司") || companyName.contains("四川二滩国际工程咨询有限责任公司")
+                                                    || companyName.contains("中铁长江交通设计集团有限公司") || companyName.contains("中国水利水电第八工程局有限公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1612335077269143554 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;第二期合同段id:1612335077269143554;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1612335077269143554L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*一期合同段(四局、长江设计单位)*/
+                                            if (companyName.contains("中国水利水电第四工程局中电建路桥集团联合体") || companyName.contains("中铁长江交通设计集团有限公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1613022750656921601 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;第一期合同段id:1613022750656921601;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1613022750656921601L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*二监办合同段(二滩)*/
+                                            if (companyName.contains("四川二滩国际工程咨询有限责任公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1687370619295309826 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;二监办合同段id:1687370619295309826;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1687370619295309826L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*一监办合同段(重庆市交通工程监理咨询有限责任公司)*/
+                                            if (companyName.contains("重庆市交通工程监理咨询有限责任公司")) {
+                                                Long count = jdbcTemplate.queryForObject("select count(1) from m_project_assignment_user where user_id = " + newUser.getId() + " and  project_id = 1612329251049537537 and contract_id = 1687370014959017986 and post_id is null and status = 1 and is_deleted = 0", Long.class);
+                                                if (count == null || count == 0L) {
+                                                    /*绑定项目,设置默认角色信息 白马项目id:1612329251049537537;一监办合同段id:1687370014959017986;角色施工-资料员id:1537249581371707394*/
+                                                    saveUserInfoByProjectClient.saveInfoRelation(newUser.getId(), 1612329251049537537L, 1687370014959017986L, 1537249581371707394L);
+                                                    newUser.setRoleId("1537249581371707394");
+                                                }
+                                            }
+
+                                            /*入库*/
+                                            userService.save(newUser);
+                                            userService.submitUserDept(newUser);
+
+                                        }
+                                    }
+                                }
+                            }
+
+                            /*JSONArray projects = jsonUser.getJSONArray("projects");
+                            if (projects != null && projects.size() >= 1) {
+                                for (int k = 0; k < projects.size(); k++) {
+                                    JSONObject projectsJSONObject = projects.getJSONObject(k);
+                                    String projectId = projectsJSONObject.getString("projectid");
+                                    String projectName = projectsJSONObject.getString("projectname");
+                                    String subprojectId = projectsJSONObject.getString("subprojectid");
+                                    String subprojectName = projectsJSONObject.getString("subprojectname");
+                                    String contractId = projectsJSONObject.getString("contractid");
+                                    String contractName = projectsJSONObject.getString("contractname");
+                                    String sectionId = projectsJSONObject.getString("sectionid");
+                                    String sectionName = projectsJSONObject.getString("sectionname");
+
+                                    //TODO
+
+                                }
+                            }*/
+
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
 }
 

+ 184 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/util/HttpClientUtil.java

@@ -0,0 +1,184 @@
+package org.springblade.system.user.util;
+
+ 
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+
+public class HttpClientUtil {
+ 
+    public static String doGet(String url, Map<String, String> param) {
+ 
+        // 创建Httpclient对象
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+ 
+        String resultString = "";
+        CloseableHttpResponse response = null;
+        try {
+            // 创建uri
+            URIBuilder builder = new URIBuilder(url);
+            if (param != null) {
+                for (String key : param.keySet()) {
+                    builder.addParameter(key, param.get(key));
+                }
+            }
+            URI uri = builder.build();
+ 
+            // 创建http GET请求
+            HttpGet httpGet = new HttpGet(uri);
+ 
+            // 执行请求
+            response = httpclient.execute(httpGet);
+            // 判断返回状态是否为200
+            if (response.getStatusLine().getStatusCode() == 200) {
+                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return resultString;
+    }
+
+    public static String doGet(String url, Map<String, String> param, String token) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+        String resultString = "";
+        CloseableHttpResponse response = null;
+
+        try {
+            // 创建uri
+            URIBuilder builder = new URIBuilder(url);
+            if (param != null) {
+                for (String key : param.keySet()) {
+                    builder.addParameter(key, param.get(key));
+                }
+            }
+            URI uri = builder.build();
+
+            // 创建http GET请求
+            HttpGet httpGet = new HttpGet(uri);
+
+            // 设置认证信息到请求头
+            httpGet.setHeader("Authorization", "Bearer " + token);
+
+            // 执行请求
+            response = httpclient.execute(httpGet);
+
+            // 判断返回状态是否为200
+            if (response.getStatusLine().getStatusCode() == 200) {
+                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                httpclient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+
+    public static String doGet(String url) {
+        return doGet(url, null);
+    }
+ 
+    public static String doPost(String url, Map<String, String> param) {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            // 创建参数列表
+            if (param != null) {
+                List<NameValuePair> paramList = new ArrayList<>();
+                for (String key : param.keySet()) {
+                    paramList.add(new BasicNameValuePair(key, param.get(key)));
+                }
+                // 模拟表单
+                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,"utf-8");
+                httpPost.setEntity(entity);
+            }
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                response.close();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+ 
+        return resultString;
+    }
+ 
+    public static String doPost(String url) {
+        return doPost(url, null);
+    }
+ 
+    public static String doPostJson(String url, String json) {
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        CloseableHttpResponse response = null;
+        String resultString = "";
+
+        try {
+            HttpPost httpPost = new HttpPost(url);
+
+            // 添加请求头参数时间戳
+            httpPost.setHeader("timestamp", String.valueOf(System.currentTimeMillis()));
+
+            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
+            httpPost.setEntity(entity);
+
+            response = httpClient.execute(httpPost);
+            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return resultString;
+    }
+}

+ 80 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/util/RsaUtilToken.java

@@ -0,0 +1,80 @@
+package org.springblade.system.user.util;
+
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+import javax.crypto.Cipher;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyFactory;
+import java.security.interfaces.RSAPublicKey;
+import java.security.spec.X509EncodedKeySpec;
+
+public final class RsaUtilToken {
+
+    /**
+     * RSA公钥加密
+     *
+     * @param data      加密字符串
+     * @param publicKey 公钥
+     * @return 密文
+     */
+    public static String encryptWithPk(String data, String publicKey) {
+        try {
+            //base64编码的公钥
+            byte[] decoded = decryptBASE64(publicKey);
+            RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
+            //RSA加密
+            Cipher cipher = Cipher.getInstance("RSA");
+            cipher.init(Cipher.ENCRYPT_MODE, pubKey);
+            return encryptBASE64(cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)));
+        } catch (Exception ex) {
+            throw new RuntimeException("数据加密处理失败(encrypt with pk)");
+        }
+    }
+
+    /**
+     * RSA公钥解密
+     *
+     * @param data      加密字符串
+     * @param publicKey 公钥
+     * @return 明文
+     */
+    public static String decryptWithPk(String data, String publicKey) {
+        try {
+            //64位解码加密后的字符串
+            byte[] inputByte = decryptBASE64(data);
+            //base64编码的私钥
+            byte[] decoded = decryptBASE64(publicKey);
+            RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
+            //RSA解密
+            Cipher cipher = Cipher.getInstance("RSA");
+            cipher.init(Cipher.DECRYPT_MODE, pubKey);
+            return new String(cipher.doFinal(inputByte));
+        } catch (Exception ex) {
+            throw new RuntimeException("数据解析处理失败(decrypt with pk)");
+        }
+    }
+
+    /**
+     * 编码返回字符串
+     */
+    private static String encryptBASE64(byte[] key) {
+        try {
+            return (new BASE64Encoder()).encodeBuffer(key);
+        } catch (Exception ex) {
+            throw new RuntimeException("编码返回字符串失败");
+        }
+    }
+
+    /**
+     * 解码返回byte
+     */
+    private static byte[] decryptBASE64(String key) {
+        try {
+            return (new BASE64Decoder()).decodeBuffer(key);
+        } catch (Exception ex) {
+            throw new RuntimeException("解码返回byte失败");
+        }
+    }
+
+}