From 80ea9d9c1b4474fb3d14622c945c3ddceb860218 Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期四, 24 四月 2025 14:17:40 +0800 Subject: [PATCH] 代码初始化 --- server/src/main/java/com/doumee/core/utils/qiyeweixin/QywxUtil.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 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 e965335..4170d18 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 @@ -13,7 +13,9 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; +import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -112,12 +114,42 @@ return null; } + public static InputStream getMediaInputstream(String token, String media) { + try { + String[] interfaceUrl = QywxConstant.GET_MEDIA; + String url = qyUtil.qiweiUrl+interfaceUrl[0].replace("${accesstoken}",token).replace("${media_id}",media); + log.error("浼佷笟寰俊涓存椂绱犳潗鑾峰彇url=========="+url); + return HttpsUtil.connectionInputsteam(url,"GET",null,null); + }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>(){}); if(response.getErrcode()!=null && response.getErrcode() ==0){ + return response; + } + return null; + } + + /** + * + * @param token + * @param type 濯掍綋鏂囦欢绫诲瀷锛屽垎鍒湁鍥剧墖锛坕mage锛夈�佽闊筹紙voice锛夈�佽棰戯紙video锛夛紝鏅�氭枃浠讹紙file锛� + * @return + */ + public static QywxUploadMediaResponse uploadMedia(String token,String type,String imgurl) { + String[] interfaceUrl = QywxConstant.UPLOAD_TEMP_MEDIA; + String url = interfaceUrl[0].replace("${accesstoken}",token).replace("${type}",type); + QywxUploadMediaResponse response = sendHttpRequestMultifile(url,interfaceUrl[1],imgurl + ,new TypeReference<QywxUploadMediaResponse>(){}); + if(response !=null && response.getErrcode()!=null && response.getErrcode() ==0){ return response; } return null; @@ -172,6 +204,23 @@ } return null; } + public static <T extends QywxBaseSingleResponse> T sendHttpRequestMultifile(String url, String name, String imgUrl , TypeReference<T> typeReference){ + log.info("銆�"+name+"銆�================寮�濮�===="+ imgUrl); + if ( StringUtils.isNotBlank(url)) { + String res = null; + try { + res = HttpsUtil.uploadTempMedia (qyUtil.qiweiUrl+url,imgUrl); + log.info("浠庝紒寰帴鍙�:{}----涓婁紶涓存椂绱犳潗缁撴灉:{}",url,res); + JSONObject jsonObject = JSONObject.parseObject(res); + T result = JSONObject.parseObject(res, typeReference.getType()); + return result; + }catch (Exception e){ + e.printStackTrace(); + log.error("銆�"+name+"銆�================澶辫触===="+ imgUrl); + } + } + return null; + } public static <T extends QywxBaseSingleResponse> T sendHttpRequestSingle(String url, String name, String param, TypeReference<T> typeReference){ log.info("銆�"+name+"銆�================寮�濮�===="+ JSONObject.toJSONString(param)); if ( StringUtils.isNotBlank(url)) { -- Gitblit v1.9.3