Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cmeeting
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
翟斌
cmeeting
Commits
224e70d1
提交
224e70d1
authored
11月 17, 2025
作者:
洪东保
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
减少日志量
父级
0c2dc139
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
15 行增加
和
917 行删除
+15
-917
src/main/java/com/cmeeting/ad/service/impl/UserServiceImpl.java
+10
-11
src/main/java/com/cmeeting/job/CmeetingJob.java
+0
-17
src/main/java/com/cmeeting/job/FileProcessTask.java
+0
-2
src/main/java/com/cmeeting/service/impl/MeetingInfoServiceImpl.java
+0
-1
src/main/java/com/cmeeting/service/impl/WeComServiceImpl.java
+0
-1
src/main/java/com/cmeeting/util/AESUtils.java
+0
-17
src/main/java/com/cmeeting/util/HttpClientKnowledgePlatformUtil.java
+0
-222
src/main/java/com/cmeeting/util/HttpClientUtils.java
+0
-640
src/main/resources/logback-spring.xml
+5
-6
没有找到文件。
src/main/java/com/cmeeting/ad/service/impl/UserServiceImpl.java
浏览文件 @
224e70d1
...
...
@@ -3,26 +3,24 @@ package com.cmeeting.ad.service.impl;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.cmeeting.ad.entity.*
;
import
com.cmeeting.ad.util.SecurityUtil
;
import
com.cmeeting.ad.vo.UserVo
;
import
com.cmeeting.dto.UserDTO
;
import
com.cmeeting.exception.RobotBaseException
;
import
com.cmeeting.mapper.primary.AuthMapper
;
import
com.cmeeting.mapper.primary.CommonMapper
;
import
com.cmeeting.ad.service.ILdapService
;
import
com.cmeeting.ad.service.ISysTenantService
;
import
com.cmeeting.ad.service.UserService
;
import
com.cmeeting.ad.util.JwtUtil
;
import
com.cmeeting.ad.util.SecurityUtil
;
import
com.cmeeting.ad.vo.ApplicationUserVO
;
import
com.cmeeting.ad.vo.UserVo
;
import
com.cmeeting.constant.CategoryConstant
;
import
com.cmeeting.constant.UserAdminRouteConstant
;
import
com.cmeeting.exception.RobotBaseException
;
import
com.cmeeting.mapper.primary.AuthMapper
;
import
com.cmeeting.mapper.primary.CommonMapper
;
import
com.cmeeting.mapper.secondary.SysUserSysMapper
;
import
com.cmeeting.pojo.CoreModulePermissions
;
import
com.cmeeting.util.*
;
import
com.cmeeting.ad.vo.ApplicationUserVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -34,10 +32,11 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.time.*
;
import
java.time.format.DateTimeFormatter
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@Service
...
...
src/main/java/com/cmeeting/job/CmeetingJob.java
浏览文件 @
224e70d1
...
...
@@ -78,21 +78,6 @@ public class CmeetingJob {
@Resource
private
EmailSender
emailSender
;
// @PostConstruct
public
void
weComUserInit
()
{
weComUserSync
();
}
// @PostConstruct
public
void
tencentUserInit
()
{
TencentUserSync
();
}
// @PostConstruct
public
void
userBindInit
()
{
userBind
();
}
/**
* 企微人员定时同步
*/
...
...
@@ -179,8 +164,6 @@ public class CmeetingJob {
if
(
CollectionUtils
.
isEmpty
(
accessUserIds
))
{
log
.
info
(
"无生成纪要权限的人员"
);
return
;
}
else
{
log
.
info
(
"生成纪要权限人员:->{}"
,
accessUserIds
.
toString
());
}
List
<
TencentMeetingVO
.
RecordFile
>
meetingFiles
=
tencentMeetingService
.
getMeetingFiles
(
accessUserIds
,
weComUserMap
);
...
...
src/main/java/com/cmeeting/job/FileProcessTask.java
浏览文件 @
224e70d1
...
...
@@ -255,7 +255,6 @@ public class FileProcessTask {
String
downloadUrl
=
transcript
.
getDownloadAddress
();
if
(
"txt"
.
equalsIgnoreCase
(
fileType
))
{
log
.
info
(
"AI Transcript - Type: {}, URL: {}"
,
fileType
,
downloadUrl
);
// 1. 下载文件
byte
[]
fileData
=
downloadFile
(
downloadUrl
);
...
...
@@ -412,7 +411,6 @@ public class FileProcessTask {
// 将字节内容写入本地文件
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
fullPath
))
{
fos
.
write
(
fileData
);
log
.
info
(
"DOCX transcript saved to: {}"
,
fullPath
);
}
catch
(
IOException
e
)
{
log
.
error
(
"Error saving DOCX transcript to file: {}"
,
e
.
getMessage
(),
e
);
}
...
...
src/main/java/com/cmeeting/service/impl/MeetingInfoServiceImpl.java
浏览文件 @
224e70d1
...
...
@@ -207,7 +207,6 @@ public class MeetingInfoServiceImpl extends ServiceImpl<MeetingInfoMapper, Meeti
String
downloadUrl
=
transcript
.
getDownloadAddress
();
if
(
"txt"
.
equalsIgnoreCase
(
fileType
))
{
log
.
info
(
"AI Transcript - Type: {}, URL: {}"
,
fileType
,
downloadUrl
);
// 1. 下载文件
byte
[]
fileData
=
downloadFile
(
downloadUrl
);
...
...
src/main/java/com/cmeeting/service/impl/WeComServiceImpl.java
浏览文件 @
224e70d1
...
...
@@ -213,7 +213,6 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i
public
void
userBind
()
{
//查出没有建立关联的企微人员
List
<
WeComUser
>
noBindUsers
=
noBindUsers
();
List
<
UserId
>
userIds
=
new
ArrayList
<>();
for
(
WeComUser
user
:
noBindUsers
)
{
String
weComToken
=
getToken
();
MeetingInfo
meetingInfo
=
createTempMeeting
(
user
.
getUserId
(),
weComToken
);
...
...
src/main/java/com/cmeeting/util/AESUtils.java
浏览文件 @
224e70d1
...
...
@@ -100,23 +100,6 @@ public class AESUtils {
return
mingwen
;
}
public
static
Boolean
decryptSign
(
HttpServletRequest
request
,
String
AES_KEY
){
String
lid
=
request
.
getHeader
(
"lid"
);
log
.
info
(
"lid============="
+
lid
);
String
sign
=
request
.
getHeader
(
"sign"
);
log
.
info
(
"sign============="
+
sign
);
String
decrypt
=
decrypt
(
sign
,
AES_KEY
);
log
.
info
(
"decrypt============="
+
decrypt
);
if
(
StringUtils
.
isEmpty
(
lid
)
&&
StringUtils
.
isEmpty
(
sign
)
&&
StringUtils
.
isEmpty
(
decrypt
)){
return
true
;
}
if
(!
lid
.
equals
(
decrypt
)){
log
.
info
(
"----判定成功"
);
return
true
;
}
return
false
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
int
code
=
1
;
/*String[] arr = {""};
...
...
src/main/java/com/cmeeting/util/HttpClientKnowledgePlatformUtil.java
浏览文件 @
224e70d1
...
...
@@ -85,217 +85,6 @@ public class HttpClientKnowledgePlatformUtil {
}
/**
* 发送get请求
*
* @param url 路径
* @return
*/
public
static
String
sendHttpGet
(
String
url
)
{
log
.
info
(
"请求地址:【{}】"
,
url
);
log
.
info
(
"请求方式:GET"
);
// get请求返回结果
// 发送get请求
HttpGet
request
=
new
HttpGet
(
url
);
request
.
setConfig
(
requestConfig
);
CloseableHttpResponse
response
=
null
;
String
result
=
""
;
try
{
response
=
getClient
().
execute
(
request
);
// 请求发送成功,并得到响应
HttpEntity
responseEntity
=
response
.
getEntity
();
if
(
responseEntity
!=
null
)
{
// 将响应内容转换为字符串
result
=
EntityUtils
.
toString
(
responseEntity
,
StandardCharsets
.
UTF_8
);
}
log
.
info
(
"请求返回结果:【{}】"
,
result
);
}
catch
(
IOException
e
)
{
log
.
error
(
"get请求提交失败:"
+
url
,
e
);
}
finally
{
if
(
response
!=
null
){
try
{
//此处调优重点,多线程模式下可提高性能。
EntityUtils
.
consume
(
response
.
getEntity
());
response
.
close
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"关闭response失败:"
+
e
);
}
}
request
.
releaseConnection
();
}
return
result
;
}
/**
* 发送POST请求
*
* @param url
* @param parametersBody
* @return
*/
public
static
String
sendPostJsonRequest
(
String
url
,
String
parametersBody
)
{
log
.
info
(
"请求地址:【{}】"
,
url
);
log
.
info
(
"请求方式:POST"
);
log
.
info
(
"请求参数:【{}】"
,
parametersBody
);
HttpPost
post
=
new
HttpPost
(
url
);
post
.
addHeader
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
post
.
addHeader
(
"Accept"
,
"application/json"
);
post
.
setConfig
(
requestConfig
);
StringEntity
entity
=
new
StringEntity
(
parametersBody
,
"UTF-8"
);
post
.
setEntity
(
entity
);
//设置请求头
// if (StringUtils.isNotBlank(token)){
// post.setHeader("Authorization", token);
// }
String
result
=
""
;
CloseableHttpResponse
response
=
null
;
try
{
response
=
getClient
().
execute
(
post
);
HttpEntity
responseEntity
=
response
.
getEntity
();
if
(
responseEntity
!=
null
)
{
// 将响应内容转换为字符串
result
=
EntityUtils
.
toString
(
responseEntity
,
StandardCharsets
.
UTF_8
);
}
log
.
info
(
"请求返回结果:【{}】"
,
result
);
return
result
;
}
catch
(
ClientProtocolException
e
)
{
throw
new
RuntimeException
(
"postRequest -- Client protocol exception!"
,
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"postRequest -- IO error!"
,
e
);
}
finally
{
if
(
response
!=
null
){
try
{
//此处调优重点,多线程模式下可提高性能。
EntityUtils
.
consume
(
response
.
getEntity
());
response
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"关闭response失败:"
+
e
);
}
}
post
.
releaseConnection
();
}
}
/**
* 发送POST请求
*
* @param url
* @param parametersBody
* @return
*/
public
static
String
sendPostJsonBySearch
(
String
url
,
String
parametersBody
)
{
log
.
info
(
"请求地址:【{}】"
,
url
);
log
.
info
(
"请求方式:POST"
);
log
.
info
(
"请求参数:【{}】"
,
parametersBody
);
HttpPost
post
=
new
HttpPost
(
url
);
post
.
addHeader
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
post
.
addHeader
(
"Accept"
,
"application/json"
);
post
.
setConfig
(
requestConfig
);
StringEntity
entity
=
new
StringEntity
(
parametersBody
,
"UTF-8"
);
post
.
setEntity
(
entity
);
String
result
=
""
;
CloseableHttpResponse
response
=
null
;
try
{
response
=
getClient
().
execute
(
post
);
HttpEntity
responseEntity
=
response
.
getEntity
();
if
(
responseEntity
!=
null
)
{
// 将响应内容转换为字符串
result
=
EntityUtils
.
toString
(
responseEntity
,
StandardCharsets
.
UTF_8
);
}
return
result
;
}
catch
(
ClientProtocolException
e
)
{
throw
new
RuntimeException
(
"postRequest -- Client protocol exception!"
,
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"postRequest -- IO error!"
,
e
);
}
finally
{
if
(
response
!=
null
){
try
{
//此处调优重点,多线程模式下可提高性能。
EntityUtils
.
consume
(
response
.
getEntity
());
response
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"关闭response失败:"
+
e
);
}
}
post
.
releaseConnection
();
}
}
/**
* 使用httpclint 发送文件,如果不传输文件,直接设置fileParams=null,
* 如果不设置请求头参数,直接设置headerParams=null,就可以进行普通参数的POST请求了
*
* @param url 请求路径
* @param file 文件参数
* @param otherParams 其他字符串参数
* @return
*/
public
static
String
sendPostByFormData
(
String
url
,
MultipartFile
file
,
Map
<
String
,
String
>
otherParams
)
{
log
.
info
(
"请求地址:{}"
,
url
);
log
.
info
(
"请求方式:POST"
);
log
.
info
(
"请求参数:{}"
,
JSON
.
toJSONString
(
otherParams
));
String
result
=
""
;
CloseableHttpResponse
response
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
url
);
try
{
httpPost
.
setConfig
(
requestConfig
);
//设置请求头
// if (headerParams != null && headerParams.size() > 0) {
// for (Map.Entry<String, String> e : headerParams.entrySet()) {
// String value = e.getValue();
// String key = e.getKey();
// if (StringUtils.isNotBlank(value)) {
// httpPost.setHeader(key, value);
// }
// }
// }
MultipartEntityBuilder
builder
=
MultipartEntityBuilder
.
create
();
builder
.
setCharset
(
StandardCharsets
.
UTF_8
);
builder
.
setMode
(
HttpMultipartMode
.
BROWSER_COMPATIBLE
);
ContentType
contentType
=
ContentType
.
create
(
"multipart/form-data"
,
StandardCharsets
.
UTF_8
);
// 文件传输http请求头(multipart/form-data)
if
(
file
!=
null
)
{
builder
.
addBinaryBody
(
"file"
,
file
.
getBytes
(),
ContentType
.
MULTIPART_FORM_DATA
,
file
.
getOriginalFilename
());
}
// 字节传输http请求头
if
(
otherParams
!=
null
&&
otherParams
.
size
()
>
0
)
{
for
(
Map
.
Entry
<
String
,
String
>
e
:
otherParams
.
entrySet
())
{
String
value
=
e
.
getValue
();
if
(
StringUtils
.
isNotBlank
(
value
))
{
builder
.
addTextBody
(
e
.
getKey
(),
value
,
contentType
);
// 类似浏览器表单提交,对应input的name和value
}
}
}
HttpEntity
entity
=
builder
.
build
();
httpPost
.
setEntity
(
entity
);
response
=
getClient
().
execute
(
httpPost
);
HttpEntity
responseEntity
=
response
.
getEntity
();
if
(
responseEntity
!=
null
)
{
// 将响应内容转换为字符串
result
=
EntityUtils
.
toString
(
responseEntity
,
StandardCharsets
.
UTF_8
);
}
log
.
info
(
"响应数据:{}"
,
JSON
.
toJSONString
(
result
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
){
try
{
//此处调优重点,多线程模式下可提高性能。
EntityUtils
.
consume
(
response
.
getEntity
());
response
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"关闭response失败:"
+
e
);
}
}
httpPost
.
releaseConnection
();
}
return
result
;
}
/**
* 使用httpclint 发送文件,如果不传输文件,直接设置fileParams=null,
* 如果不设置请求头参数,直接设置headerParams=null,就可以进行普通参数的POST请求了
...
...
@@ -315,16 +104,6 @@ public class HttpClientKnowledgePlatformUtil {
HttpPost
httpPost
=
new
HttpPost
(
url
);
try
{
httpPost
.
setConfig
(
requestConfig
);
//设置请求头
// if (headerParams != null && headerParams.size() > 0) {
// for (Map.Entry<String, String> e : headerParams.entrySet()) {
// String value = e.getValue();
// String key = e.getKey();
// if (StringUtils.isNotBlank(value)) {
// httpPost.setHeader(key, value);
// }
// }
// }
MultipartEntityBuilder
builder
=
MultipartEntityBuilder
.
create
();
builder
.
setCharset
(
StandardCharsets
.
UTF_8
);
builder
.
setMode
(
HttpMultipartMode
.
BROWSER_COMPATIBLE
);
...
...
@@ -353,7 +132,6 @@ public class HttpClientKnowledgePlatformUtil {
// 将响应内容转换为字符串
result
=
EntityUtils
.
toString
(
responseEntity
,
StandardCharsets
.
UTF_8
);
}
log
.
info
(
"响应数据:{}"
,
JSON
.
toJSONString
(
result
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
...
...
src/main/java/com/cmeeting/util/HttpClientUtils.java
浏览文件 @
224e70d1
...
...
@@ -49,42 +49,6 @@ public class HttpClientUtils {
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
180000
).
setConnectTimeout
(
180000
).
setConnectionRequestTimeout
(
180000
).
build
();
}
/**
* 发送get请求
*
* @param url 路径
* @return
*/
public
static
JSONObject
httpGet
(
String
url
)
{
log
.
info
(
"请求地址:【{}】"
,
url
);
// get请求返回结果
JSONObject
jsonResult
=
null
;
CloseableHttpClient
client
=
HttpClients
.
createDefault
();
// 发送get请求
HttpGet
request
=
new
HttpGet
(
url
);
request
.
setConfig
(
requestConfig
);
try
{
CloseableHttpResponse
response
=
client
.
execute
(
request
);
// 请求发送成功,并得到响应
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
// 读取服务器返回过来的json字符串数据
HttpEntity
entity
=
response
.
getEntity
();
String
strResult
=
EntityUtils
.
toString
(
entity
,
"utf-8"
);
// 把json字符串转换成json对象
jsonResult
=
JSONObject
.
parseObject
(
strResult
);
log
.
info
(
"请求返回结果:【{}】"
,
jsonResult
.
toJSONString
());
}
else
{
log
.
error
(
"get请求提交失败:"
+
url
);
}
}
catch
(
IOException
e
)
{
log
.
error
(
"get请求提交失败:"
+
url
,
e
);
}
finally
{
request
.
releaseConnection
();
}
return
jsonResult
;
}
public
static
JSONObject
httpGet
(
String
url
,
String
token
)
{
log
.
info
(
"请求地址:【{}】"
,
url
);
// get请求返回结果
...
...
@@ -105,8 +69,6 @@ public class HttpClientUtils {
String
strResult
=
EntityUtils
.
toString
(
entity
,
"utf-8"
);
// 把json字符串转换成json对象
jsonResult
=
JSONObject
.
parseObject
(
strResult
);
log
.
info
(
"请求返回结果:【{}】"
,
jsonResult
.
toJSONString
());
}
else
{
log
.
error
(
"get请求提交失败:"
+
url
);
}
...
...
@@ -118,274 +80,6 @@ public class HttpClientUtils {
return
jsonResult
;
}
public
static
JSONObject
httpGet
(
String
url
,
String
token
,
List
<
Header
>
headers
,
boolean
isSafe
)
{
log
.
info
(
"请求地址:【{}】"
,
url
);
// get请求返回结果
JSONObject
jsonResult
=
null
;
// 发送get请求
HttpGet
request
=
new
HttpGet
(
url
);
if
(
token
!=
null
)
{
request
.
setHeader
(
"Authorization"
,
"Bearer "
+
token
);
}
// 设置头参数
if
(
CollectionUtils
.
isNotEmpty
(
headers
))
{
for
(
Header
item
:
headers
)
{
request
.
setHeader
(
item
.
getName
(),
item
.
getValue
());
log
.
info
(
"请求Header:{}={}"
,
item
.
getName
(),
item
.
getValue
());
}
}
request
.
setConfig
(
requestConfig
);
try
{
CloseableHttpClient
client
=
null
;
if
(
isSafe
){
client
=
HttpClientBuilder
.
create
().
build
();
}
else
{
// 创建一个信任所有证书的SSLContext
SSLContext
sslContext
=
SSLContextBuilder
.
create
()
.
loadTrustMaterial
(
new
TrustStrategy
()
{
@Override
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
// 忽略所有证书验证
}
})
.
build
();
client
=
HttpClientBuilder
.
create
().
setSSLContext
(
sslContext
)
.
setSSLHostnameVerifier
(
new
NoopHostnameVerifier
())
.
build
();
}
CloseableHttpResponse
response
=
client
.
execute
(
request
);
// 请求发送成功,并得到响应
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
// 读取服务器返回过来的json字符串数据
HttpEntity
entity
=
response
.
getEntity
();
String
strResult
=
EntityUtils
.
toString
(
entity
,
"utf-8"
);
// 把json字符串转换成json对象
jsonResult
=
JSONObject
.
parseObject
(
strResult
);
log
.
info
(
"请求返回结果:【{}】"
,
jsonResult
.
toJSONString
());
}
else
{
log
.
error
(
"get请求提交失败:{},code:{}"
,
url
,
response
.
getStatusLine
().
getStatusCode
());
}
}
catch
(
IOException
|
NoSuchAlgorithmException
|
KeyStoreException
e
)
{
log
.
error
(
"get请求提交失败:"
+
url
,
e
);
}
catch
(
KeyManagementException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
request
.
releaseConnection
();
}
return
jsonResult
;
}
/**
* get请求,参数放在map里
*
* @param url 请求地址
* @param map 参数map
* @return 响应
*/
public
static
JSONObject
getMap
(
String
url
,
Map
<
String
,
String
>
map
)
{
log
.
info
(
url
+
"getMap-start :"
+
System
.
currentTimeMillis
());
log
.
info
(
"请求地址:【{}】"
,
url
);
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
List
<
NameValuePair
>
pairs
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
map
.
entrySet
())
{
pairs
.
add
(
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
()));
}
CloseableHttpResponse
response
=
null
;
try
{
URIBuilder
builder
=
new
URIBuilder
(
url
);
builder
.
setParameters
(
pairs
);
HttpGet
get
=
new
HttpGet
(
builder
.
build
());
response
=
httpClient
.
execute
(
get
);
log
.
info
(
url
+
"getMap-end :"
+
System
.
currentTimeMillis
());
HttpEntity
entity
=
response
.
getEntity
();
String
resultJson
=
EntityUtils
.
toString
(
entity
);
log
.
info
(
"请求返回的原始数据:【{}】"
,
resultJson
);
JSONObject
result
=
JSONObject
.
parseObject
(
resultJson
);
if
(
response
!=
null
&&
response
.
getStatusLine
().
getStatusCode
()
==
200
)
{
log
.
info
(
"返回结果:【{}】"
,
result
.
toJSONString
());
}
else
{
log
.
info
(
"返回结果异常:【{}】"
,
result
.
toJSONString
());
}
return
result
;
}
catch
(
URISyntaxException
e
)
{
log
.
error
(
"请求失败"
,
e
);
}
catch
(
ClientProtocolException
e
)
{
log
.
error
(
"请求失败"
,
e
);
}
catch
(
IOException
e
)
{
log
.
error
(
"请求失败"
,
e
);
}
finally
{
try
{
httpClient
.
close
();
if
(
response
!=
null
)
{
response
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
null
;
}
public
static
JSONObject
postForForm
(
String
url
,
Map
<
String
,
String
>
parms
)
{
log
.
info
(
"请求地址:{}"
,
url
);
HttpPost
httpPost
=
new
HttpPost
(
url
);
ArrayList
<
BasicNameValuePair
>
list
=
new
ArrayList
<>();
parms
.
forEach
((
key
,
value
)
->
list
.
add
(
new
BasicNameValuePair
(
key
,
value
)));
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
try
{
if
(
Objects
.
nonNull
(
parms
)
&&
parms
.
size
()
>
0
)
{
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
list
,
"UTF-8"
));
}
HttpResponse
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
EntityUtils
.
toString
(
entity
,
"UTF-8"
));
log
.
info
(
"请求结果:{}"
,
jsonObject
.
toJSONString
());
return
jsonObject
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
Objects
.
nonNull
(
httpClient
))
{
try
{
httpClient
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
null
;
}
/**
* get请求(用于key-value格式的参数,且带有header请求头)
*
* @param url
* @param map 请求的参数map<key,value>键值对
* @return
*/
public
static
String
doGet
(
String
url
,
Map
<
String
,
String
>
map
)
{
log
.
info
(
"请求地址:【{}】"
,
url
);
// 获取连接客户端工具
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
String
entityStr
=
null
;
CloseableHttpResponse
response
=
null
;
try
{
/*
* 由于GET请求的参数都是拼装在URL地址后方,所以我们要构建一个URL,带参数
*/
URIBuilder
uriBuilder
=
new
URIBuilder
(
url
);
/** 第一种添加参数的形式 */
/*uriBuilder.addParameter("name", "root");
uriBuilder.addParameter("password", "123456");*/
for
(
Map
.
Entry
<
String
,
String
>
entry
:
map
.
entrySet
())
{
uriBuilder
.
addParameter
(
entry
.
getKey
(),
entry
.
getValue
());
}
/** 第二种添加参数的形式 */
/* List<NameValuePair> list = new LinkedList<>();
BasicNameValuePair param1 = new BasicNameValuePair("startTime", "2019-1-1 00:00:00");
BasicNameValuePair param2 = new BasicNameValuePair("endTime", "2019-1-9 00:00:00");
list.add(param1);
list.add(param2);
uriBuilder.setParameters(list);*/
// 根据带参数的URI对象构建GET请求对象
HttpGet
httpGet
=
new
HttpGet
(
uriBuilder
.
build
());
/*
* 添加请求头信息
*/
// 浏览器表示
httpGet
.
addHeader
(
"User-Agent"
,
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)"
);
// 传输的类型
httpGet
.
addHeader
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
//header的<key,value>
//httpGet.setHeader(headerKey, headerValue);
// 执行请求
response
=
httpClient
.
execute
(
httpGet
);
// 获得响应的实体对象
HttpEntity
entity
=
response
.
getEntity
();
// 使用Apache提供的工具类进行转换成字符串
entityStr
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
log
.
info
(
"返回结果:【{}】"
,
entityStr
);
}
catch
(
ClientProtocolException
e
)
{
log
.
error
(
"Http协议出现问题"
,
e
);
}
catch
(
ParseException
e
)
{
log
.
error
(
"解析错误"
,
e
);
}
catch
(
URISyntaxException
e
)
{
log
.
error
(
"URI解析异常"
,
e
);
}
catch
(
IOException
e
)
{
log
.
error
(
"IO异常"
,
e
);
}
finally
{
// 释放连接
if
(
null
!=
response
)
{
try
{
response
.
close
();
httpClient
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
entityStr
;
}
/**
* post请求传输json参数
*
* @param url url地址
* @return
*/
public
static
JSONObject
httpPost
(
String
url
,
cn
.
hutool
.
json
.
JSONObject
jsonParam
,
String
token
)
{
// post请求返回结果
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
JSONObject
jsonResult
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
url
);
// 设置请求和传输超时时间
httpPost
.
setConfig
(
requestConfig
);
if
(
token
!=
null
)
{
httpPost
.
setHeader
(
"Authorization"
,
"Bearer "
+
token
);
}
try
{
if
(
null
!=
jsonParam
)
{
// 解决中文乱码问题
StringEntity
entity
=
new
StringEntity
(
jsonParam
.
toString
(),
"utf-8"
);
entity
.
setContentEncoding
(
"UTF-8"
);
entity
.
setContentType
(
"application/json"
);
httpPost
.
setEntity
(
entity
);
}
CloseableHttpResponse
result
=
httpClient
.
execute
(
httpPost
);
// 请求发送成功,并得到响应
if
(
result
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
String
str
=
""
;
try
{
// 读取服务器返回过来的json字符串数据
str
=
EntityUtils
.
toString
(
result
.
getEntity
(),
"utf-8"
);
// 把json字符串转换成json对象
jsonResult
=
JSONObject
.
parseObject
(
str
);
}
catch
(
Exception
e
)
{
log
.
error
(
"post请求提交失败:"
+
url
,
e
);
}
}
}
catch
(
IOException
e
)
{
log
.
error
(
"post请求提交失败:"
+
url
,
e
);
}
finally
{
httpPost
.
releaseConnection
();
}
return
jsonResult
;
}
public
static
JSONObject
httpPost
(
String
url
,
JSONObject
jsonParam
,
String
token
)
{
// post请求返回结果
...
...
@@ -426,338 +120,4 @@ public class HttpClientUtils {
return
jsonResult
;
}
/**
* post请求传输String参数 例如:name=Jack&sex=1&type=2
* Content-type:application/x-www-form-urlencoded
*
* @param url url地址
* @param strParam 参数
* @return
*/
public
static
JSONObject
httpPost
(
String
url
,
String
strParam
)
{
// post请求返回结果
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
JSONObject
jsonResult
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
url
);
httpPost
.
setConfig
(
requestConfig
);
try
{
if
(
null
!=
strParam
)
{
// 解决中文乱码问题
StringEntity
entity
=
new
StringEntity
(
strParam
,
"utf-8"
);
entity
.
setContentEncoding
(
"UTF-8"
);
entity
.
setContentType
(
"application/x-www-form-urlencoded"
);
httpPost
.
setEntity
(
entity
);
}
CloseableHttpResponse
result
=
httpClient
.
execute
(
httpPost
);
// 请求发送成功,并得到响应
if
(
result
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
String
str
=
""
;
try
{
// 读取服务器返回过来的json字符串数据
str
=
EntityUtils
.
toString
(
result
.
getEntity
(),
"utf-8"
);
// 把json字符串转换成json对象
jsonResult
=
JSONObject
.
parseObject
(
str
);
}
catch
(
Exception
e
)
{
log
.
error
(
"post请求提交失败:"
+
url
,
e
);
}
}
}
catch
(
IOException
e
)
{
log
.
error
(
"post请求提交失败:"
+
url
,
e
);
}
finally
{
httpPost
.
releaseConnection
();
}
return
jsonResult
;
}
/**
* 发送POST请求
*
* @param url
* @param header
* @param parametersBody
* @param timeout
* @return
*/
public
static
JSONObject
postRequest
(
String
url
,
List
<
Header
>
header
,
String
parametersBody
,
Integer
timeout
)
{
log
.
info
(
"请求地址:{}"
,
url
);
log
.
info
(
"请求方式:POST"
);
HttpPost
post
=
new
HttpPost
(
url
);
post
.
addHeader
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
post
.
addHeader
(
"Accept"
,
"application/json"
);
// 设置头参数
if
(
CollectionUtils
.
isNotEmpty
(
header
))
{
for
(
Header
item
:
header
)
{
post
.
setHeader
(
item
.
getName
(),
item
.
getValue
());
log
.
info
(
"请求Header:{}={}"
,
item
.
getName
(),
item
.
getValue
());
}
}
try
{
StringEntity
entity
=
new
StringEntity
(
parametersBody
);
post
.
setEntity
(
entity
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
// 请求参数
if
(
timeout
!=
null
&&
timeout
.
intValue
()
>
0
)
{
RequestConfig
config
=
RequestConfig
.
custom
().
setConnectTimeout
(
timeout
).
setConnectionRequestTimeout
(
timeout
).
setSocketTimeout
(
timeout
).
build
();
post
.
setConfig
(
config
);
}
try
{
log
.
info
(
"请求参数:{}"
,
parametersBody
);
CloseableHttpClient
client
=
HttpClientBuilder
.
create
().
build
();
HttpResponse
response
=
client
.
execute
(
post
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
HttpEntity
entity
=
response
.
getEntity
();
String
s
=
EntityUtils
.
toString
(
entity
);
JSONObject
result
=
(
JSONObject
)
JSONObject
.
parseObject
(
s
);
if
(
code
>=
400
)
{
throw
new
RuntimeException
(
result
.
toJSONString
());
}
log
.
info
(
"请求返回结果:{}"
,
result
);
return
result
;
}
catch
(
ClientProtocolException
e
)
{
throw
new
RuntimeException
(
"postRequest -- Client protocol exception!"
,
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"postRequest -- IO error!"
,
e
);
}
finally
{
post
.
releaseConnection
();
}
}
/**
* 发送POST请求
*
* @param url
* @param headerParams
* @param parametersBody
* @param timeout
* @return
*/
public
static
JSONObject
postJsonRequest
(
String
url
,
Map
<
String
,
String
>
headerParams
,
String
parametersBody
,
Integer
timeout
)
{
log
.
info
(
"请求地址:{}"
,
url
);
log
.
info
(
"请求方式:POST"
);
HttpPost
post
=
new
HttpPost
(
url
);
post
.
addHeader
(
"Content-Type"
,
"text/plain"
);
// 设置头参数
//设置请求头
if
(
headerParams
!=
null
&&
headerParams
.
size
()
>
0
)
{
for
(
Map
.
Entry
<
String
,
String
>
e
:
headerParams
.
entrySet
())
{
String
value
=
e
.
getValue
();
String
key
=
e
.
getKey
();
if
(
StrUtil
.
isNotBlank
(
value
))
{
post
.
setHeader
(
key
,
value
);
}
}
}
try
{
StringEntity
entity
=
new
StringEntity
(
parametersBody
);
entity
.
setContentType
(
"text/plain"
);
entity
.
setContentEncoding
(
"UTF-8"
);
post
.
setEntity
(
entity
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
// 请求参数
if
(
timeout
!=
null
&&
timeout
.
intValue
()
>
0
)
{
RequestConfig
config
=
RequestConfig
.
custom
().
setConnectTimeout
(
timeout
).
setConnectionRequestTimeout
(
timeout
).
setSocketTimeout
(
timeout
).
build
();
post
.
setConfig
(
config
);
}
try
{
log
.
info
(
"请求参数:{}"
,
parametersBody
);
CloseableHttpClient
client
=
HttpClientBuilder
.
create
().
build
();
HttpResponse
response
=
client
.
execute
(
post
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
HttpEntity
entity
=
response
.
getEntity
();
String
s
=
EntityUtils
.
toString
(
entity
);
JSONObject
result
=
(
JSONObject
)
JSONObject
.
parseObject
(
s
);
if
(
code
>=
400
)
{
throw
new
RuntimeException
(
result
.
toJSONString
());
}
log
.
info
(
"请求返回结果:{}"
,
result
);
return
result
;
}
catch
(
ClientProtocolException
e
)
{
throw
new
RuntimeException
(
"postRequest -- Client protocol exception!"
,
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"postRequest -- IO error!"
,
e
);
}
finally
{
post
.
releaseConnection
();
}
}
/**
* get请求,参数放在map里
*
* @param url 请求地址
* @param map 参数map
* @return 响应
*/
public
static
String
getfileMap
(
String
url
,
Map
<
String
,
String
>
map
,
String
fileUrl
,
String
fileName
)
{
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
List
<
NameValuePair
>
pairs
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
map
.
entrySet
())
{
pairs
.
add
(
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
()));
}
CloseableHttpResponse
response
=
null
;
String
filestr
=
null
;
InputStream
inputStream
=
null
;
try
{
URIBuilder
builder
=
new
URIBuilder
(
url
);
builder
.
setParameters
(
pairs
);
HttpGet
get
=
new
HttpGet
(
builder
.
build
());
response
=
httpClient
.
execute
(
get
);
if
(
response
!=
null
&&
response
.
getStatusLine
().
getStatusCode
()
==
200
)
{
inputStream
=
response
.
getEntity
().
getContent
();
Header
[]
headers1
=
response
.
getHeaders
(
"Content-disposition"
);
/* for (int i = 0; i < headers1.length; i++) {
Header header = headers1[0];
String filenameheader = header.getValue();
String[] strings = filenameheader.split(";");
String strs = strings[1];
String str = strs.substring(11, strs.length() - 1);
String[] spstr = str.split("\\.");
String fileend = spstr[1];
log.info("fileend = " + fileend);
}*/
filestr
=
fileUrl
+
fileName
+
".silk"
;
File
file1
=
new
File
(
filestr
);
if
(!
file1
.
exists
())
{
file1
.
createNewFile
();
}
OutputStream
os
=
new
FileOutputStream
(
file1
);
int
read
=
0
;
byte
[]
temp
=
new
byte
[
1024
*
1024
];
while
((
read
=
inputStream
.
read
(
temp
))
>
0
)
{
byte
[]
bytes
=
new
byte
[
read
];
System
.
arraycopy
(
temp
,
0
,
bytes
,
0
,
read
);
os
.
write
(
bytes
);
}
os
.
flush
();
}
}
catch
(
URISyntaxException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClientProtocolException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
httpClient
.
close
();
if
(
response
!=
null
)
{
response
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
filestr
;
}
/**
* 发送POST请求(普通表单形式)
*
* @param url
* @param header
* @param parametersBody
* @param timeout
* @return
*/
public
static
String
postForm
(
String
url
,
List
<
Header
>
header
,
List
<
BasicNameValuePair
>
parametersBody
,
Integer
timeout
)
{
HttpEntity
entity
=
new
UrlEncodedFormEntity
(
parametersBody
,
Charsets
.
UTF_8
);
return
postRequest
(
url
,
"application/x-www-form-urlencoded"
,
header
,
entity
,
timeout
,
true
);
}
/**
* 发送POST请求(JSON形式)
*
* @param url
* @param header 请求header
* @param json 请求body,json格式
* @param timeout 访问超时时间,单位毫秒
* @return
*/
public
static
String
postJSON
(
String
url
,
List
<
Header
>
header
,
String
json
,
Integer
timeout
,
boolean
isSafe
)
{
StringEntity
entity
=
new
StringEntity
(
json
,
Charsets
.
UTF_8
);
return
postRequest
(
url
,
"application/json; charset=utf-8"
,
header
,
entity
,
timeout
,
isSafe
);
}
/**
* 发送POST请求
*
* @param url
* @param mediaType
* @param header
* @param parametersBody
* @param timeout
* @return
*/
private
static
String
postRequest
(
String
url
,
String
mediaType
,
List
<
Header
>
header
,
HttpEntity
parametersBody
,
Integer
timeout
,
boolean
isSafe
)
{
log
.
info
(
"请求地址:{}"
,
url
);
log
.
info
(
"请求方式:POST"
);
HttpPost
post
=
new
HttpPost
(
url
);
post
.
addHeader
(
"Content-Type"
,
mediaType
);
post
.
addHeader
(
"Accept"
,
"application/json"
);
// 设置头参数
if
(
CollectionUtils
.
isNotEmpty
(
header
))
{
for
(
Header
item
:
header
)
{
post
.
setHeader
(
item
.
getName
(),
item
.
getValue
());
log
.
info
(
"请求Header:{}={}"
,
item
.
getName
(),
item
.
getValue
());
}
}
// 请求参数
post
.
setEntity
(
parametersBody
);
if
(
timeout
!=
null
&&
timeout
.
intValue
()
>
0
)
{
RequestConfig
config
=
RequestConfig
.
custom
().
setConnectTimeout
(
timeout
).
setConnectionRequestTimeout
(
timeout
).
setSocketTimeout
(
timeout
).
build
();
post
.
setConfig
(
config
);
}
try
{
log
.
info
(
"请求参数:{}"
,
EntityUtils
.
toString
(
parametersBody
));
CloseableHttpClient
client
=
null
;
if
(
isSafe
){
client
=
HttpClientBuilder
.
create
().
build
();
}
else
{
// 创建一个信任所有证书的SSLContext
SSLContext
sslContext
=
SSLContextBuilder
.
create
()
.
loadTrustMaterial
(
new
TrustStrategy
()
{
@Override
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
// 忽略所有证书验证
}
})
.
build
();
client
=
HttpClientBuilder
.
create
().
setSSLContext
(
sslContext
)
.
setSSLHostnameVerifier
(
new
NoopHostnameVerifier
())
.
build
();
}
HttpResponse
response
=
client
.
execute
(
post
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
());
if
(
code
>=
400
)
{
throw
new
RuntimeException
(
result
);
}
log
.
info
(
"请求返回结果:{}"
,
result
);
return
result
;
}
catch
(
ClientProtocolException
e
)
{
throw
new
RuntimeException
(
"postRequest -- Client protocol exception!"
,
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"postRequest -- IO error!"
,
e
);
}
catch
(
NoSuchAlgorithmException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
KeyStoreException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
KeyManagementException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
post
.
releaseConnection
();
}
}
}
src/main/resources/logback-spring.xml
浏览文件 @
224e70d1
...
...
@@ -120,7 +120,7 @@
</timeBasedFileNamingAndTriggeringPolicy>
<!-- 日志文件保留天数 -->
<maxHistory>
15
7
</maxHistory>
</rollingPolicy>
<!-- 过滤出ERROR级别的日志 -->
...
...
@@ -132,14 +132,13 @@
</appender>
<!-- MyBatis SQL 日志 -->
<logger
name=
"java.sql.Connection"
level=
"
TRACE
"
/>
<logger
name=
"java.sql.Connection"
level=
"
DEBUG
"
/>
<logger
name=
"java.sql.Statement"
level=
"TRACE"
/>
<logger
name=
"java.sql.PreparedStatement"
level=
"TRACE"
/>
<logger
name=
"java.sql.ResultSet"
level=
"TRACE"
/>
<!-- DAO 包路径(替换为你的Mapper接口包名)
-->
<logger
name=
"com.cmeeting.mapper.primary"
level=
"TRACE"
/
>
<logger
name=
"com.cmeeting.mapper.secondary"
level=
"TRACE"
/
>
<!-- <!– DAO 包路径(替换为你的Mapper接口包名) –>
-->
<!-- <logger name="com.cmeeting.mapper.primary" level="DEBUG"/>--
>
<!-- <logger name="com.cmeeting.mapper.secondary" level="DEBUG"/>--
>
<!-- 日志总开关 -->
<root
level=
"info"
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论