From 64fa2c33cd645e86d4e2a8c34c7881ea4aa678cf Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 17 六月 2025 18:33:37 +0800
Subject: [PATCH] 代码初始化

---
 server/src/main/java/com/doumee/core/utils/qiyeweixin/QywxUtil.java |   58 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/server/src/main/java/com/doumee/core/utils/qiyeweixin/QywxUtil.java b/server/src/main/java/com/doumee/core/utils/qiyeweixin/QywxUtil.java
index a501b01..c3faaed 100644
--- a/server/src/main/java/com/doumee/core/utils/qiyeweixin/QywxUtil.java
+++ b/server/src/main/java/com/doumee/core/utils/qiyeweixin/QywxUtil.java
@@ -6,6 +6,7 @@
 import com.doumee.core.utils.HttpsUtil;
 import com.doumee.core.utils.qiyeweixin.model.request.QywxSendMsgRequest;
 import com.doumee.core.utils.qiyeweixin.model.response.*;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +24,7 @@
 
 @Component
 @Slf4j
+@Data
 public class QywxUtil {
     private static JSONObject json = new JSONObject();
 
@@ -36,6 +38,8 @@
     @PostConstruct
     private void init() {
         qyUtil = this;
+        System.out.println(qyUtil.qiweiUrl);
+        System.out.println(qyUtil.getQiweiUrl());
 //        QywxUtil.qiweiUrl =  serviceurl;
     }
 
@@ -59,7 +63,7 @@
     public static String getAccessToken(String corpId, String corpSecret)  {
         String[] interfaceUrl = QywxConstant.GET_ACCESS_TOKEN;
         String url = interfaceUrl[0].replace("${corpid}",corpId).replace("${secret}",corpSecret);
-        QywxBaseResponse response = sendHttpRequest(url,interfaceUrl[1],"",new TypeReference<QywxBaseResponse<String>>(){});
+        QywxBaseResponse response = sendHttpGetRequest(url,interfaceUrl[1], new TypeReference<QywxBaseResponse<String>>(){});
         if(response.getErrcode()!=null && response.getErrcode() ==0){
             return response.getAccess_token();
         }
@@ -89,7 +93,7 @@
             String[] interfaceUrl = QywxConstant.SEND_MSG;
             String url = interfaceUrl[0].replace("${accesstoken}",token);
             QywxSendMsgResponse response = sendHttpRequestSingle(url,interfaceUrl[1],JSONObject.toJSONString(param)
-                    ,new TypeReference<QywxSendMsgResponse>(){});
+                    ,new TypeReference<QywxSendMsgResponse>(){},true);
             log.error("鎺ㄩ�佹秷鎭粨鏋渰}",JSONObject.toJSONString(response));
             if(response.getErrcode()!=null && response.getErrcode() ==0){
                 return response;
@@ -127,11 +131,26 @@
 
         return null;
     }
+
+    public static   Map<String,Object> getMediaInputstreamMap(String token, String media)   {
+        try {
+            String[] interfaceUrl = QywxConstant.GET_MEDIA;
+            String url = qyUtil.qiweiUrl+interfaceUrl[0].replace("${accesstoken}",token).replace("${media_id}",media);
+            log.info("浼佷笟寰俊涓存椂绱犳潗鑾峰彇url=========="+url);
+            Map<String,Object> map =  HttpsUtil.connInputsteamReturnMap(url,"GET",null,null);
+            return map;
+        }catch (Exception e){
+            e.printStackTrace();
+            log.error("浼佷笟寰俊涓存椂绱犳潗鑾峰彇error=========="+e.getMessage());
+        }
+
+        return null;
+    }
     public static QywxUserInfoResponse getUserInfo(String token,String id)  {
         String[] interfaceUrl = QywxConstant.GET_USER_DETAIL;
         String url = interfaceUrl[0].replace("${accesstoken}",token).replace("${id}",id);
         QywxUserInfoResponse response = sendHttpRequestSingle(url,interfaceUrl[1],""
-                ,new TypeReference<QywxUserInfoResponse>(){});
+                ,new TypeReference<QywxUserInfoResponse>(){},false);
         if(response.getErrcode()!=null && response.getErrcode() ==0){
             return response;
         }
@@ -188,12 +207,12 @@
      * @param <T>
      */
     public static   <T> QywxBaseResponse<T> sendHttpRequest(String url, String name, String param, TypeReference<QywxBaseResponse<T>> typeReference){
-        log.info("銆�"+name+"銆�================寮�濮�===="+url+"\nparam==========================:"+ JSONObject.toJSONString(param));
+        log.info("銆�"+name+"銆�================寮�濮�===="+qyUtil.qiweiUrl+url+"\nparam==========================:"+ JSONObject.toJSONString(param));
         if ( StringUtils.isNotBlank(url)) {
             String res = null;
             try {
                 Map<String,String> headers = new HashMap<>();
-                res = HttpsUtil.postJson(qyUtil.qiweiUrl+url,param);
+                res = HttpsUtil.get(qyUtil.qiweiUrl+url,true);
                 QywxBaseResponse result = JSONObject.parseObject(res, typeReference.getType());
                 logResult(result,name);
                 return  result;
@@ -204,8 +223,25 @@
         }
         return  null;
     }
+    public static   <T> QywxBaseResponse<T> sendHttpGetRequest(String url, String name,  TypeReference<QywxBaseResponse<T>> typeReference){
+        log.info("銆�"+name+"銆�================寮�濮�===="+qyUtil.qiweiUrl+url+"\nparam==========================:"+ JSONObject.toJSONString(url));
+        if ( StringUtils.isNotBlank(url)) {
+            String res = null;
+            try {
+                Map<String,String> headers = new HashMap<>();
+                res = HttpsUtil.get(qyUtil.qiweiUrl+url,true);
+                QywxBaseResponse result = JSONObject.parseObject(res, typeReference.getType());
+                logResult(result,name);
+                return  result;
+            }catch (Exception e){
+                e.printStackTrace();
+                log.error("銆�"+name+"銆�================澶辫触===="+ JSONObject.toJSONString(url));
+            }
+        }
+        return  null;
+    }
     public static  <T extends QywxBaseSingleResponse>  T sendHttpRequestMultifile(String url, String name, String imgUrl  , TypeReference<T> typeReference){
-        log.info("銆�"+name+"銆�================寮�濮�===="+ imgUrl);
+        log.info("銆�"+name+"銆�================寮�濮�===="+qyUtil.qiweiUrl+url+"\nparam==========================:"+ imgUrl);
         if ( StringUtils.isNotBlank(url)) {
             String res = null;
             try {
@@ -221,13 +257,17 @@
         }
         return  null;
     }
-    public static  <T extends QywxBaseSingleResponse>  T sendHttpRequestSingle(String url, String name, String param, TypeReference<T> typeReference){
-        log.info("銆�"+name+"銆�================寮�濮�===="+ JSONObject.toJSONString(param));
+    public static  <T extends QywxBaseSingleResponse>  T sendHttpRequestSingle(String url, String name, String param, TypeReference<T> typeReference,boolean isPost){
+        log.info("銆�"+name+"銆�================寮�濮�===="+qyUtil.qiweiUrl+url+"\nparam==========================:"+ JSONObject.toJSONString(param));
         if ( StringUtils.isNotBlank(url)) {
             String res = null;
             try {
                 Map<String,String> headers = new HashMap<>();
-                res = HttpsUtil.postJson(qyUtil.qiweiUrl+url,param);
+                if(isPost){
+                    res = HttpsUtil.postJson(qyUtil.qiweiUrl+url,param);
+                }else{
+                    res = HttpsUtil.get(qyUtil.qiweiUrl+url,true);
+                }
                 T result = JSONObject.parseObject(res, typeReference.getType());
 //                logResult(result,name);
                 return  result;

--
Gitblit v1.9.3