吴树波 1 週間 前
コミット
08452f8560

+ 18 - 21
fs-service/src/main/java/com/fs/wxwork/service/WxWorkServiceNew.java

@@ -1,6 +1,5 @@
 package com.fs.wxwork.service;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.TypeReference;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.exception.CustomException;
@@ -16,9 +15,7 @@ import com.fs.wxwork.dto.*;
 import com.fs.wxwork.utils.WxWorkHttpUtil;
 import com.fs.wxwork.utils.WxWorkHttpUtilNew;
 import lombok.AllArgsConstructor;
-import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -51,53 +48,53 @@ public class WxWorkServiceNew {
     public WxWorkResponseDTO<WxWorkInitRespDTO> init(WxWorkInitDTO param,Long serverId) {
         String url = getUrl(serverId) + "/init";
         return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkInitRespDTO>>() {
-        });
+        }, serverId);
     }
 
     public WxWorkResponseDTO<WxWorkSendTextMsgRespDTO> SendTextMsg(WxWorkSendTextMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendTextMsg";
         return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkSendTextMsgRespDTO>>() {
-        });
+        }, serverId);
     }
 
 
     public WxWorkResponseDTO<WxWorkSendAppMsgRespDTO> SendAppMsg(WxWorkSendAppMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendAppMsg";
         return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkSendAppMsgRespDTO>>() {
-        });
+        }, serverId);
     }
 
 
     public WxWorkResponseDTO<WxwSendLinkMsgRespDTO> SendLinkMsg(WxwSendLinkMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendLinkMsg";
         return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendLinkMsgRespDTO>>() {
-        });
+        }, serverId);
     }
 
     public WxWorkResponseDTO<WxwSendCDNImgMsgRespDTO> SendCDNImgMsg(WxwSendCDNImgMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendCDNImgMsg";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNImgMsgRespDTO>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNImgMsgRespDTO>>() {}, serverId);
 
     }
 
     public WxWorkResponseDTO<WxwSendCDNFileMsgRespDTO> SendCDNFileMsg(WxwSendCDNFileMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendCDNFileMsg";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNFileMsgRespDTO>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNFileMsgRespDTO>>() {}, serverId);
     }
 
     public WxWorkResponseDTO<WxwSendCDNVoiceMsgRespDTO> SendCDNVoiceMsg(WxwSendCDNVoiceMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendCDNVoiceMsg";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNVoiceMsgRespDTO>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNVoiceMsgRespDTO>>() {}, serverId);
     }
 
     public WxWorkResponseDTO<WxwSendCDNVideoMsgRespDTO> SendCDNVideoMsg(WxwSendCDNVideoMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendCDNVideoMsg";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNVideoMsgRespDTO>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNVideoMsgRespDTO>>() {}, serverId);
     }
 
     public WxWorkResponseDTO<WxwSendVideoNumberRespDTO> SendVideoNumber(WxwSendVideoNumberMsgDTO param,Long serverId) {
         String url = getUrl(serverId) + "/SendVideoNumber";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendVideoNumberRespDTO>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendVideoNumberRespDTO>>() {}, serverId);
     }
 
     public String getCorpId(String uuid, Long corpId,Long serverId) {
@@ -111,7 +108,7 @@ public class WxWorkServiceNew {
         param.setUuid(uuid);
         param.setCorpid(corpId);
 
-        WxWorkResponseDTO<WxWorkCorpRespDTO> listWxWorkResponseDTO = WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkCorpRespDTO>>() {});
+        WxWorkResponseDTO<WxWorkCorpRespDTO> listWxWorkResponseDTO = WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkCorpRespDTO>>() {}, serverId);
         WxWorkCorpRespDTO data = listWxWorkResponseDTO.getData();
         List<WxWorkCorpRespDTO.CorpInfo> list = data.getList();
         if (list != null && !list.isEmpty()) {
@@ -134,18 +131,18 @@ public class WxWorkServiceNew {
     public WxWorkResponseDTO<WxwUploadCdnLinkFileRespDTO> uploadCdnLinkFile(WxwUploadCdnLinkFileDTO param, Long serverId) {
 
         String url = getUrl(serverId) + "/UploadCdnLinkFile";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwUploadCdnLinkFileRespDTO>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwUploadCdnLinkFileRespDTO>>() {}, serverId);
     }
 
     public WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>> UserId2Vid(WxWorkUserId2VidDTO param,Long serverId) {
         String url = getUrl(serverId) + "/UserId2Vid";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>>>() {}, serverId);
     }
 
 
     public WxWorkResponseDTO<WxWorkChatIdToRoomIdResp> ChatIdToRoomId(WxWorkChatIdToRoomIdDTO param, Long serverId) {
         String url = getUrl(serverId) + "/ChatIdToRoomId";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkChatIdToRoomIdResp>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkChatIdToRoomIdResp>>() {}, serverId);
     }
 
     /**
@@ -157,7 +154,7 @@ public class WxWorkServiceNew {
 
     public WxWorkResponseDTO<WxCdnUploadImgLinkResp> cdnUploadImgLink(WxCdnUploadImgLinkDTO param, Long serverId) {
         String url = getUrl(serverId) + "/CdnUploadImgLink";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxCdnUploadImgLinkResp>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxCdnUploadImgLinkResp>>() {}, serverId);
     }
     /**
      * CDN上传网络视频
@@ -168,7 +165,7 @@ public class WxWorkServiceNew {
 
     public WxWorkResponseDTO<WxCdnUploadVideoResp> uploadCdnVideoLink(WxCdnUploadVideoLinkDTO param, Long serverId) {
         String url = getUrl(serverId) + "/UploadCdnVideoLink";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxCdnUploadVideoResp>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxCdnUploadVideoResp>>() {}, serverId);
     }
 
     /**
@@ -185,13 +182,13 @@ public class WxWorkServiceNew {
         param.setAuthkey(authkey.getData().getAuthKey());
         param.setFilekey(authkey.getData().getFilekey());
         String url = getUrl(serverId) + "/BigFileUploadLink";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxBigFileUploadLinkResp>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxBigFileUploadLinkResp>>() {}, serverId);
     }
 
 
     public WxWorkResponseDTO<WxLoginResp> isLogin(WxLoginDTO param, Long serverId) {
         String url = getUrl(serverId) + "/GetRunClientByUuid";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxLoginResp>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxLoginResp>>() {}, serverId);
     }
 
     /**
@@ -202,7 +199,7 @@ public class WxWorkServiceNew {
      */
     public WxWorkResponseDTO<WxGetBigAuthkeyResp> getBigAuthkey(WGetBigAuthkeyDTO param, Long serverId) {
         String url = getUrl(serverId) + "/GetBigAuthkey";
-        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxGetBigAuthkeyResp>>() {});
+        return WxWorkHttpUtilNew.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxGetBigAuthkeyResp>>() {}, serverId);
     }
 
     public void LoginOut(WxWorkGetQrCodeDTO dto, Long serverId) {

+ 13 - 24
fs-service/src/main/java/com/fs/wxwork/utils/WxWorkHttpUtilNew.java

@@ -1,5 +1,6 @@
 package com.fs.wxwork.utils;
 
+import cn.hutool.core.io.IORuntimeException;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
@@ -77,34 +78,17 @@ public class WxWorkHttpUtilNew {
 
         return responseBody;
     }
-
-    /**
-     * 发送POST请求(JSON格式)
-     * @param url 请求URL
-     * @param jsonBody JSON请求体
-     * @return 响应字符串
-     */
-    public static String post(String url, String jsonBody) {
-        return post(url, jsonBody, null);
-    }
-    /**
-     * 发送POST请求(JSON格式)
-     * @param url 请求URL
-     * @param jsonBody JSON请求体
-     * @return 响应字符串
-     */
-    public static String post(String url, Object jsonBody) {
-        return post(url, JSON.toJSONString(jsonBody), null);
-    }
     /**
      * 发送POST请求(JSON格式)
-     * @param url 请求URL
+     *
+     * @param url      请求URL
      * @param jsonBody JSON请求体
+     * @param serverId
      * @return 响应字符串
      */
-    public static <T> T postWithType(String url, Object jsonBody, TypeReference<T> type) {
+    public static <T> T postWithType(String url, Object jsonBody, TypeReference<T> type, Long serverId) {
         String json = JSON.toJSONString(jsonBody);
-        String post = post(url, json, null);
+        String post = post(url, json, null, serverId);
         WxWorkResponseCodeDTO respone = JSON.parseObject(post, WxWorkResponseCodeDTO.class);
         if(respone.getErrcode() != 0){
             log.error("请求服务器地址:{},请求参数:{},返回数据:{},请求时间:{}", url, json, JSON.toJSONString(respone), LocalDateTime.now());
@@ -123,7 +107,7 @@ public class WxWorkHttpUtilNew {
      * @param headers 请求头
      * @return 响应字符串
      */
-    public static String post(String url, String jsonBody, Map<String, String> headers) {
+    public static String post(String url, String jsonBody, Map<String, String> headers, Long serviceId) {
         // 记录请求信息
         logRequest("POST", url, null, jsonBody, headers);
 
@@ -137,7 +121,12 @@ public class WxWorkHttpUtilNew {
         }
 
         // 执行请求并获取响应
-        HttpResponse response = request.execute();
+        HttpResponse response;
+        try {
+            response = request.execute();
+        }catch (IORuntimeException e){
+            return "{\"data\":null,\"errcode\":400,\"errmsg\":\"连接超时,服务器宕机 - serviceId: " + serviceId +"\"}";
+        }
         String responseBody = response.body();
 
         // 记录响应信息