diff --git a/pom.xml b/pom.xml index 6b028b5..f959b4b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 pom springboot-parent 杭州铁晟科技有限公司基础依赖 @@ -57,55 +57,55 @@ com.tiesheng.springboot-parent springboot-database - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-login - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-web - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-util - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-platform - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-message - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-encrypt - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-annotation - 1.0.17 + 1.0.18 com.tiesheng.springboot-parent springboot-poi - 1.0.17 + 1.0.18 diff --git a/springboot-ademo/pom.xml b/springboot-ademo/pom.xml index 2b49415..1d02c70 100644 --- a/springboot-ademo/pom.xml +++ b/springboot-ademo/pom.xml @@ -6,11 +6,11 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-ademo - 1.0.17 + 1.0.18 8 diff --git a/springboot-annotation/pom.xml b/springboot-annotation/pom.xml index 414e5d6..86bcbbd 100644 --- a/springboot-annotation/pom.xml +++ b/springboot-annotation/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-annotation diff --git a/springboot-database/pom.xml b/springboot-database/pom.xml index 7527870..7496c65 100644 --- a/springboot-database/pom.xml +++ b/springboot-database/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-database diff --git a/springboot-encrypt/pom.xml b/springboot-encrypt/pom.xml index 6ec1320..44321d7 100644 --- a/springboot-encrypt/pom.xml +++ b/springboot-encrypt/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-encrypt diff --git a/springboot-login/pom.xml b/springboot-login/pom.xml index 400fe13..017b5b5 100644 --- a/springboot-login/pom.xml +++ b/springboot-login/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-login diff --git a/springboot-message/pom.xml b/springboot-message/pom.xml index afa64c7..14e2076 100644 --- a/springboot-message/pom.xml +++ b/springboot-message/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-message diff --git a/springboot-platform/pom.xml b/springboot-platform/pom.xml index 44efecc..8b84ff9 100644 --- a/springboot-platform/pom.xml +++ b/springboot-platform/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-platform diff --git a/springboot-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java b/springboot-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java index 0b9c180..d88ba81 100644 --- a/springboot-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java +++ b/springboot-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.TypeReference; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONObject; @@ -49,6 +48,37 @@ public class PlatformDingConfig { return bean; } + + /** + * 发送get请求 + * 会自动增加accessToken在url上面 + * + * @param service + * @return + */ + public String doRequest(String service, String url, JSONObject body) { + if (StrUtil.contains(url, "?")) { + url = url + "&access_token=" + getAccessToken(service); + } else { + url = url + "?access_token=" + getAccessToken(service); + } + + HttpResponse execute; + if (body == null) { + execute = HttpUtil.createGet(url).execute(); + } else { + execute = HttpUtil.createPost(url).body(body.toString()).execute(); + } + + String resp = execute.body(); + if (execute.isOk()) { + return resp; + } + LogFactory.get().info("{}: {}", url, resp); + return ""; + } + + /////////////////////////////////////////////////////////////////////////// // 逻辑方法 /////////////////////////////////////////////////////////////////////////// @@ -89,8 +119,7 @@ public class PlatformDingConfig { DingConfigBean dingConfigBean = getConfigBean(service); String jsapiTicket = TimedCacheHelper.getTimedCache().get(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(), false); if (StrUtil.isEmpty(jsapiTicket)) { - String response = HttpUtil.get("https://oapi.dingtalk.com/get_jsapi_ticket?access_token=" + getAccessToken(service)); - LogFactory.get().info("getJsapiTicket: " + response); + String response = doRequest(service, "https://oapi.dingtalk.com/get_jsapi_ticket", null); JSONObject respJson = JSONUtil.parseObj(response); if (!Objects.equals(respJson.getStr("errcode"), "0")) { throw new ApiException(respJson.getStr("errmsg")); @@ -126,11 +155,9 @@ public class PlatformDingConfig { * @see */ public String getUserIdByCode(String service, String code) { - HttpRequest request = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token=" + getAccessToken(service)) - .body(JSONUtil.createObj().putOpt("code", code).toString()); - try (HttpResponse response = request.execute()) { - return JSONUtil.parseObj(response.body()).getJSONObject("result").getStr("userid"); - } + String resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo", + JSONUtil.createObj().putOpt("code", code)); + return JSONUtil.parseObj(resp).getJSONObject("result").getStr("userid"); } @@ -144,16 +171,15 @@ public class PlatformDingConfig { */ public DingUserInfo topapiV2UserGet(String service, String ddUserId) { DingConfigBean dingConfigBean = getConfigBean(service); - try (HttpResponse response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/get?access_token=" - + getAccessToken(service)) - .body(JSONUtil.createObj().putOpt("userid", ddUserId).toString()).execute()) { - JSONObject resultJson = JSONUtil.parseObj(response.body()).getJSONObject("result"); - DingUserInfo userInfo = JSONUtil.toBean(resultJson, DingUserInfo.class); - // 设置一下job_number - userInfo.setJobNumber(resultJson.getStr("job_number")); - userInfo.setAppId(dingConfigBean.getAppKey()); - return userInfo; - } + + String response = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/get", + JSONUtil.createObj().putOpt("userid", ddUserId)); + JSONObject resultJson = JSONUtil.parseObj(response).getJSONObject("result"); + DingUserInfo userInfo = JSONUtil.toBean(resultJson, DingUserInfo.class); + // 设置一下job_number + userInfo.setJobNumber(resultJson.getStr("job_number")); + userInfo.setAppId(dingConfigBean.getAppKey()); + return userInfo; } /** @@ -168,16 +194,17 @@ public class PlatformDingConfig { if (StrUtil.isEmpty(token)) { return new ArrayList<>(); } - try (HttpResponse response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token=" + token) - .body(JSONUtil.createObj().putOpt("dept_id", deptId).toString()).execute()) { - DingResponse> result = JSONUtil.toBean(response.body(), new TypeReference>>() { - }.getType(), true); - if (!result.isOk()) { - result.setResult(new ArrayList<>()); - } - return result.getResult(); + String resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/department/listsub", + JSONUtil.createObj().putOpt("dept_id", deptId)); + + DingResponse> result = JSONUtil.toBean(resp, new TypeReference>>() { + }.getType(), true); + + if (!result.isOk()) { + result.setResult(new ArrayList<>()); } + return result.getResult(); } @@ -192,16 +219,16 @@ public class PlatformDingConfig { if (StrUtil.isEmpty(token)) { return DingUserListVo.fail(); } - try (HttpResponse response = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/list?access_token=" + token) - .body(JSONUtil.createObj().putOpt("dept_id", deptId).putOpt("cursor", cursor).putOpt("size", 100).toString()) - .execute()) { - DingResponse result = JSONUtil.toBean(response.body(), new TypeReference>() { - }.getType(), true); - if (!result.isOk()) { - result.setResult(DingUserListVo.fail()); - } - return result.getResult(); + + String resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/list", + JSONUtil.createObj().putOpt("dept_id", deptId).putOpt("cursor", cursor).putOpt("size", 100)); + + DingResponse result = JSONUtil.toBean(resp, new TypeReference>() { + }.getType(), true); + if (!result.isOk()) { + result.setResult(DingUserListVo.fail()); } + return result.getResult(); } /** @@ -263,12 +290,11 @@ public class PlatformDingConfig { msg.set("msgtype", "action_card"); msg.set("action_card", actionCard); - HashMap body = new HashMap<>(10); - body.put("agent_id", configBean.getAgentId()); - body.put("userid_list", CollUtil.join(userIds, ",")); - body.put("msg", msg); - String resp = HttpUtil.post("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + getAccessToken(service), - JSONUtil.toJsonStr(body)); + JSONObject body = new JSONObject(); + body.putOpt("agent_id", configBean.getAgentId()); + body.putOpt("userid_list", CollUtil.join(userIds, ",")); + body.putOpt("msg", msg); + doRequest(service, "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2", body); } /////////////////////////////////////////////////////////////////////////// diff --git a/springboot-poi/pom.xml b/springboot-poi/pom.xml index 8a68101..439b138 100644 --- a/springboot-poi/pom.xml +++ b/springboot-poi/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-poi diff --git a/springboot-util/pom.xml b/springboot-util/pom.xml index 6af783d..548a226 100644 --- a/springboot-util/pom.xml +++ b/springboot-util/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-util diff --git a/springboot-web/pom.xml b/springboot-web/pom.xml index 8cfc692..37b40d0 100644 --- a/springboot-web/pom.xml +++ b/springboot-web/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 1.0.17 + 1.0.18 springboot-web