Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
491630bf
Commit
491630bf
authored
Aug 25, 2021
by
kongfm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
集成联通CTI相关代码
parent
a249edcc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
737 additions
and
0 deletions
+737
-0
HttpUtils.java
...ava/com/yeejoin/amos/boot/biz/common/utils/HttpUtils.java
+244
-0
RedisKey.java
...java/com/yeejoin/amos/boot/biz/common/utils/RedisKey.java
+2
-0
CtiDto.java
...java/com/yeejoin/amos/boot/module/tzs/api/dto/CtiDto.java
+59
-0
VoiceRecordFileDto.java
...join/amos/boot/module/tzs/api/dto/VoiceRecordFileDto.java
+3
-0
ICtiService.java
...yeejoin/amos/boot/module/tzs/api/service/ICtiService.java
+41
-0
CtiController.java
...in/amos/boot/module/tzs/biz/controller/CtiController.java
+94
-0
VoiceRecordFileController.java
.../module/tzs/biz/controller/VoiceRecordFileController.java
+67
-0
CtiServiceImpl.java
...amos/boot/module/tzs/biz/service/impl/CtiServiceImpl.java
+222
-0
HttpUtils.java
...com/yeejoin/amos/boot/module/tzs/biz/utils/HttpUtils.java
+0
-0
pom.xml
amos-boot-module/amos-boot-module-biz/pom.xml
+5
-0
No files found.
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/common/utils/HttpUtils.java
0 → 100644
View file @
491630bf
package
com
.
yeejoin
.
amos
.
boot
.
biz
.
common
.
utils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.TrustStrategy
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSession
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.Charset
;
import
java.security.GeneralSecurityException
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
HttpUtils
{
private
static
PoolingHttpClientConnectionManager
connMgr
;
private
static
RequestConfig
requestConfig
;
private
static
final
int
MAX_TIMEOUT
=
50000
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpUtils
.
class
);
static
{
// 设置连接池
connMgr
=
new
PoolingHttpClientConnectionManager
();
// 设置连接池大小
connMgr
.
setMaxTotal
(
100
);
connMgr
.
setDefaultMaxPerRoute
(
connMgr
.
getMaxTotal
());
// Validate connections after 1 sec of inactivity
connMgr
.
setValidateAfterInactivity
(
5000
);
RequestConfig
.
Builder
configBuilder
=
RequestConfig
.
custom
();
// 设置连接超时
configBuilder
.
setConnectTimeout
(
MAX_TIMEOUT
);
// 设置读取超时
configBuilder
.
setSocketTimeout
(
MAX_TIMEOUT
);
// 设置从连接池获取连接实例的超时
configBuilder
.
setConnectionRequestTimeout
(
MAX_TIMEOUT
);
requestConfig
=
configBuilder
.
build
();
}
/**
* 发送 GET 请求(HTTP),不带输入数据
*
* @param url
* @return
*/
public
static
String
doGet
(
String
url
)
{
return
doGet
(
url
,
new
HashMap
<
String
,
Object
>());
}
/**
* 发送 GET 请求(HTTP),K-V形式
*
* @param url
* @param params
* @return
*/
public
static
String
doGet
(
String
url
,
Map
<
String
,
Object
>
params
)
{
String
apiUrl
=
url
;
StringBuffer
param
=
new
StringBuffer
();
int
i
=
0
;
for
(
String
key
:
params
.
keySet
())
{
if
(
i
==
0
)
param
.
append
(
"?"
);
else
param
.
append
(
"&"
);
param
.
append
(
key
).
append
(
"="
).
append
(
params
.
get
(
key
));
i
++;
}
apiUrl
+=
param
;
String
result
=
null
;
HttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
())
.
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
try
{
HttpGet
httpGet
=
new
HttpGet
(
apiUrl
);
HttpResponse
response
=
httpClient
.
execute
(
httpGet
);
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
InputStream
instream
=
entity
.
getContent
();
result
=
IOUtils
.
toString
(
instream
,
"UTF-8"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
/**
* 发送 POST 请求(HTTP),不带输入数据
*
* @param apiUrl
* @return
*/
public
static
String
doPost
(
String
apiUrl
)
{
return
doPost
(
apiUrl
,
new
HashMap
<
String
,
Object
>());
}
/**
* 发送 POST 请求,K-V形式
*
* @param apiUrl
* API接口URL
* @param params
* 参数map
* @return
*/
public
static
String
doPost
(
String
apiUrl
,
Map
<
String
,
Object
>
params
)
{
CloseableHttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
())
.
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
String
httpStr
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
apiUrl
);
CloseableHttpResponse
response
=
null
;
try
{
httpPost
.
setConfig
(
requestConfig
);
List
<
NameValuePair
>
pairList
=
new
ArrayList
<>(
params
.
size
());
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
params
.
entrySet
())
{
NameValuePair
pair
=
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
()!=
null
?
entry
.
getValue
().
toString
():
""
);
pairList
.
add
(
pair
);
}
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
pairList
,
Charset
.
forName
(
"UTF-8"
)));
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
httpStr
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
)
{
try
{
EntityUtils
.
consume
(
response
.
getEntity
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
httpStr
;
}
/**
* 发送 POST 请求,JSON形式,接收端需要支持json形式,否则取不到数据
*
* @param apiUrl
* @param json
* json对象
* @return
*/
public
static
String
doPost
(
String
apiUrl
,
String
json
)
{
CloseableHttpClient
httpClient
=
null
;
if
(
apiUrl
.
startsWith
(
"https"
))
{
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
createSSLConnSocketFactory
()).
setConnectionManager
(
connMgr
).
setDefaultRequestConfig
(
requestConfig
).
build
();
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
String
httpStr
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
apiUrl
);
CloseableHttpResponse
response
=
null
;
try
{
httpPost
.
setConfig
(
requestConfig
);
StringEntity
stringEntity
=
new
StringEntity
(
json
,
"UTF-8"
);
// 解决中文乱码问题
stringEntity
.
setContentEncoding
(
"UTF-8"
);
stringEntity
.
setContentType
(
"application/json"
);
httpPost
.
setEntity
(
stringEntity
);
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
httpStr
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
)
{
try
{
EntityUtils
.
consume
(
response
.
getEntity
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
httpStr
;
}
/**
* 创建SSL安全连接
*
* @return
*/
private
static
SSLConnectionSocketFactory
createSSLConnSocketFactory
()
{
SSLConnectionSocketFactory
sslsf
=
null
;
try
{
SSLContext
sslContext
=
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustStrategy
()
{
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
}
}).
build
();
sslsf
=
new
SSLConnectionSocketFactory
(
sslContext
,
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
arg0
,
SSLSession
arg1
)
{
return
true
;
}
});
}
catch
(
GeneralSecurityException
e
)
{
e
.
printStackTrace
();
}
return
sslsf
;
}
}
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/common/utils/RedisKey.java
View file @
491630bf
...
...
@@ -28,6 +28,8 @@ public class RedisKey {
public
static
final
String
ALERTCALLED_ID
=
"alertcalled_id_"
;
/**特种设备根据警情id查询警情详情记录*/
public
static
final
String
TZS_ALERTCALLED_ID
=
"tzs_alertcalled_id_"
;
/**联通CTI token */
public
static
final
String
CTI_TOKEN
=
"cti_token"
;
/** 驼峰转下划线(简单写法,效率低于{@link #humpToLine2(String)}) */
public
static
String
humpToLine
(
String
str
)
{
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/dto/CtiDto.java
0 → 100644
View file @
491630bf
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
api
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.util.Map
;
/**
* 联通回调方法传入参数
* @author fengwang
* @date 2021-08-06.
*/
@Data
@Accessors
(
chain
=
true
)
@ApiModel
(
value
=
"CtiDto"
,
description
=
"CtiDto"
)
public
class
CtiDto
{
@ApiModelProperty
(
value
=
"企业ID"
)
private
Integer
cid
;
@ApiModelProperty
(
value
=
"呼叫类型(1:呼入;2:呼出)"
)
private
String
call_type
;
@ApiModelProperty
(
value
=
"外呼主叫(呼入时为呼入的热线号码)"
)
private
String
sysphone
;
@ApiModelProperty
(
value
=
"客户号码"
)
private
String
telephone
;
@ApiModelProperty
(
value
=
"客户ID"
)
private
String
cusid
;
@ApiModelProperty
(
value
=
"呼叫时间"
)
private
String
call_time
;
@ApiModelProperty
(
value
=
"服务工号"
)
private
String
empcode
;
@ApiModelProperty
(
value
=
"挂机时间"
)
private
String
hangup_time
;
@ApiModelProperty
(
value
=
"挂机方(1:坐席挂机;2:客户挂机)"
)
private
String
hangup_flag
;
@ApiModelProperty
(
value
=
"按键值(按键的数值,如果多个按键用-连接,如1-2)"
)
private
String
press_key
;
@ApiModelProperty
(
value
=
"按键值名称(press_key中按键的含义,多个按键用-连接,如:转组-转人工)"
)
private
String
press_key_name
;
@ApiModelProperty
(
value
=
"客户呼叫流水号"
)
private
String
connection_id
;
@ApiModelProperty
(
value
=
"坐席呼叫流水号"
)
private
String
service_connection_id
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/dto/VoiceRecordFileDto.java
View file @
491630bf
...
...
@@ -51,4 +51,7 @@ public class VoiceRecordFileDto extends BaseDto {
@ApiModelProperty
(
value
=
"通话时长"
)
private
String
telTime
;
@ApiModelProperty
(
value
=
"通话记录id"
)
private
String
connectId
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/service/ICtiService.java
0 → 100644
View file @
491630bf
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
api
.
service
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.Map
;
/**
* 联通cti 服务类
*
* @author system_generator
* @date 2021-08-03
*/
public
interface
ICtiService
{
/**
* 获取token
* @return
*/
String
getAccessToken
();
/**
* 获取登陆人坐席信息
* @return
*/
JSONObject
getLoginInfo
();
/**
* 根据话单id 查询话单详细信息
* @param connectionid
* @return
*/
JSONArray
getCallInfo
(
String
connectionid
);
/**
* 根据connectionid 下载录音 key 为录音地址 value 为录音名称
* @return
*/
Map
<
String
,
String
>
downLoadRecordFile
(
String
connectionid
);
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/controller/CtiController.java
0 → 100644
View file @
491630bf
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
biz
.
controller
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.boot.biz.common.controller.BaseController
;
import
com.yeejoin.amos.boot.biz.common.utils.RedisKey
;
import
com.yeejoin.amos.boot.biz.common.utils.RedisUtils
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.CtiDto
;
import
com.yeejoin.amos.boot.module.tzs.api.service.ICtiService
;
import
com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.exception.instance.BadRequest
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.security.MessageDigest
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 联通API controller
*
* @author kongfm
* @date 2021-08-25
*/
@RestController
@Api
(
tags
=
"联通CTIApi"
)
@RequestMapping
(
value
=
"/cti"
)
public
class
CtiController
extends
BaseController
{
@Autowired
private
ICtiService
ctiService
;
/**
* 获取坐席登陆信息
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@GetMapping
(
value
=
"/getCtiInfo"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"获取坐席登陆信息"
,
notes
=
"获取坐席登陆信息"
)
public
ResponseModel
<
JSONObject
>
getCtiInfo
()
{
JSONObject
loginData
=
ctiService
.
getLoginInfo
();
return
ResponseHelper
.
buildResponse
(
loginData
);
}
/**
* 获取坐席登陆信息
* 暴露公网
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
ANONYMOUS
,
needAuth
=
false
)
@PostMapping
(
value
=
"/ctiBack"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"获取电话结束后回调信息"
,
notes
=
"获取电话结束后回调信息"
)
public
JSONObject
ctiBack
(
@RequestBody
CtiDto
ctiDto
)
{
System
.
out
.
println
(
"===================================="
);
System
.
out
.
println
(
ctiDto
);
JSONObject
result
=
new
JSONObject
();
result
.
put
(
"code"
,
"0"
);
result
.
put
(
"message"
,
"调用成功"
);
return
result
;
}
/**
* 获取坐席登陆信息
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@GetMapping
(
value
=
"/info/{connectId}"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"获取通话话单详情"
,
notes
=
"获取通话话单详情"
)
public
ResponseModel
<
JSONObject
>
getCallInfo
(
@PathVariable
String
connectId
)
{
JSONArray
recordInfos
=
ctiService
.
getCallInfo
(
connectId
);
JSONObject
recordInfo
=
recordInfos
.
getJSONObject
(
0
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
);
return
ResponseHelper
.
buildResponse
(
recordInfo
);
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/controller/VoiceRecordFileController.java
View file @
491630bf
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
biz
.
controller
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.yeejoin.amos.boot.biz.common.controller.BaseController
;
import
com.yeejoin.amos.boot.biz.common.utils.DateUtils
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledFormDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.VoiceRecordFileDto
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.VoiceRecordFile
;
import
com.yeejoin.amos.boot.module.tzs.api.service.ICtiService
;
import
com.yeejoin.amos.boot.module.tzs.biz.service.impl.AlertCalledServiceImpl
;
import
com.yeejoin.amos.boot.module.tzs.biz.service.impl.VoiceRecordFileServiceImpl
;
import
io.swagger.annotations.Api
;
...
...
@@ -25,9 +28,13 @@ import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
/**
...
...
@@ -47,6 +54,9 @@ public class VoiceRecordFileController extends BaseController {
@Autowired
AlertCalledServiceImpl
iAlertCalledService
;
@Autowired
ICtiService
ctiService
;
/**
* 新增通话记录附件
*
...
...
@@ -103,4 +113,61 @@ public class VoiceRecordFileController extends BaseController {
});
return
ResponseHelper
.
buildResponse
(
dtoList
);
}
/**
* 新增通话记录
*
* @return
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@PostMapping
(
value
=
"/saveRecord"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"新增通话记录附件"
,
notes
=
"新增通话记录附件"
)
public
ResponseModel
<
VoiceRecordFileDto
>
saveRecord
(
@RequestBody
VoiceRecordFileDto
model
)
{
if
(
ValidationUtil
.
isEmpty
(
model
.
getAlertId
())
||
ValidationUtil
.
isEmpty
(
model
.
getConnectId
())){
throw
new
BadRequest
(
"参数校验失败."
);
}
// 获取通话人信息
JSONArray
recordInfos
=
ctiService
.
getCallInfo
(
model
.
getConnectId
());
if
(
recordInfos
==
null
||
recordInfos
.
size
()
==
0
)
{
throw
new
BadRequest
(
"未找到通话详单信息"
);
}
JSONObject
recordInfo
=
recordInfos
.
getJSONObject
(
0
);
model
.
setTel
(
recordInfo
.
getString
(
"telephone"
));
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
);
Date
telStartTime
=
null
;
Date
telEndTime
=
null
;
try
{
telStartTime
=
sdf
.
parse
(
recordInfo
.
getString
(
"connectTime"
));
telEndTime
=
sdf
.
parse
(
recordInfo
.
getString
(
"hangupTime"
));
}
catch
(
ParseException
e
)
{
throw
new
BadRequest
(
"日期转换错误"
);
}
model
.
setTelStartTime
(
telStartTime
);
model
.
setTelEndTime
(
telEndTime
);
if
(
1
==
recordInfo
.
getInteger
(
"callType"
))
{
model
.
setFileType
(
"客户呼入"
);
}
else
if
(
2
==
recordInfo
.
getInteger
(
"callType"
))
{
model
.
setFileType
(
"坐席呼出"
);
}
// 获取附件
Map
<
String
,
String
>
downloadFile
=
ctiService
.
downLoadRecordFile
(
model
.
getConnectId
());
if
(
downloadFile
.
isEmpty
())
{
throw
new
BadRequest
(
"未找到附件文件"
);
}
for
(
Map
.
Entry
<
String
,
String
>
file
:
downloadFile
.
entrySet
())
{
model
.
setFilePath
(
file
.
getKey
());
}
AlertCalledFormDto
alertDto
=
iAlertCalledService
.
selectAlertCalledByIdNoCache
(
model
.
getAlertId
());
if
(
alertDto
==
null
||
alertDto
.
getAlertCalledDto
()
==
null
)
{
throw
new
BadRequest
(
"未找到相关警情"
);
}
model
.
setAlertStage
(
alertDto
.
getAlertCalledDto
().
getAlertStage
());
model
.
setAlertStageCode
(
alertDto
.
getAlertCalledDto
().
getAlertStageCode
());
model
.
setSourceId
(-
1
l
);
model
=
voiceRecordFileServiceImpl
.
createWithModel
(
model
);
return
ResponseHelper
.
buildResponse
(
model
);
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/service/impl/CtiServiceImpl.java
0 → 100644
View file @
491630bf
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
biz
.
service
.
impl
;
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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.google.common.collect.Maps
;
import
com.yeejoin.amos.boot.biz.common.utils.DateUtils
;
import
com.yeejoin.amos.boot.biz.common.utils.RedisKey
;
import
com.yeejoin.amos.boot.biz.common.utils.RedisUtils
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledFormDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledObjsDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledQueryDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.FormValue
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.AlertCalled
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.AlertFormValue
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.Elevator
;
import
com.yeejoin.amos.boot.module.tzs.api.enums.AlertStageEnums
;
import
com.yeejoin.amos.boot.module.tzs.api.enums.DispatchPaperEnums
;
import
com.yeejoin.amos.boot.module.tzs.api.mapper.AlertCalledMapper
;
import
com.yeejoin.amos.boot.module.tzs.api.service.IAlertCalledService
;
import
com.yeejoin.amos.boot.module.tzs.api.service.ICtiService
;
import
com.yeejoin.amos.boot.module.tzs.biz.utils.BeanDtoVoUtils
;
import
com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.feign.privilege.model.AgencyUserModel
;
import
com.yeejoin.amos.feign.systemctl.Systemctl
;
import
com.yeejoin.amos.feign.systemctl.model.FileInfoModel
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.FileItemFactory
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
org.typroject.tyboot.core.rdbms.service.BaseService
;
import
org.typroject.tyboot.core.restful.exception.instance.BadRequest
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.security.MessageDigest
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 联通cti 服务实现类
*
* @author kongfm
* @date 2021-08-25
*/
@Service
public
class
CtiServiceImpl
implements
ICtiService
{
@Autowired
RedisUtils
redisUtils
;
/**
* token 过期时间, cti 系统为7200 ,tzs 系统小于7200 防止获取到无效token
*/
private
long
time
=
6000
l
;
private
final
String
APP_KEY
=
"4e805006-3fef-ae43-3915-a153731007c4"
;
private
final
String
SECRET_KEY
=
"7bd29115-99ee-4f7d-1fb1-7c4719d5f43a"
;
private
String
ctiUrl
=
"http://36.46.151.113:8000"
;
@Override
public
String
getAccessToken
()
{
if
(
redisUtils
.
hasKey
(
RedisKey
.
CTI_TOKEN
)){
Object
obj
=
redisUtils
.
get
(
RedisKey
.
CTI_TOKEN
);
return
obj
.
toString
();
}
else
{
String
tokenAccessUrl
=
ctiUrl
+
"/openauth/getAccessToken"
;
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"appKey"
,
APP_KEY
);
String
randomStr
=
System
.
currentTimeMillis
()
+
""
;
params
.
put
(
"randomStr"
,
randomStr
);
String
signStr
=
APP_KEY
+
randomStr
+
SECRET_KEY
;
String
sign
=
encrypt32
(
signStr
).
toLowerCase
();
params
.
put
(
"sign"
,
sign
);
String
responseStr
=
HttpUtils
.
doPost
(
tokenAccessUrl
,
params
);
JSONObject
response
=
null
;
try
{
response
=
JSONObject
.
parseObject
(
responseStr
);
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"获取token 出错:"
+
e
.
getMessage
());
}
if
(
response
.
getInteger
(
"code"
)
==
0
)
{
// 获取token 成功
try
{
String
token
=
response
.
getJSONObject
(
"data"
).
getString
(
"accessToken"
);
redisUtils
.
set
(
RedisKey
.
CTI_TOKEN
,
token
,
time
);
return
token
;
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"获取token 出错:"
+
e
.
getMessage
());
}
}
else
{
throw
new
BadRequest
(
"获取token 出错:"
+
response
.
getString
(
"msg"
));
}
}
}
@Override
public
JSONObject
getLoginInfo
()
{
String
token
=
this
.
getAccessToken
();
// gid code extphone 目前写死 后面根据用户获取
String
gid
=
"61,默认,0"
;
String
code
=
"1001"
;
String
extphone
=
"10001001"
;
String
loginUrl
=
ctiUrl
+
"/cti/login"
+
"?accessToken="
+
token
;
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"accessToken"
,
token
);
params
.
put
(
"gid"
,
gid
);
params
.
put
(
"code"
,
code
);
params
.
put
(
"extphone"
,
extphone
);
String
responseStr
=
HttpUtils
.
doPost
(
loginUrl
,
params
);
JSONObject
response
=
null
;
try
{
response
=
JSONObject
.
parseObject
(
responseStr
);
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"登陆出错:"
+
e
.
getMessage
());
}
if
(
response
.
getInteger
(
"code"
)
==
0
)
{
// 登陆成功
try
{
JSONObject
loginData
=
response
.
getJSONObject
(
"loginData"
);
return
loginData
;
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"获取loginData 出错:"
+
e
.
getMessage
());
}
}
else
{
//登陆失败
throw
new
BadRequest
(
"登陆失败出错:"
+
response
.
getString
(
"message"
));
}
}
@Override
public
JSONArray
getCallInfo
(
String
connectionid
)
{
String
token
=
this
.
getAccessToken
();
String
url
=
ctiUrl
+
"/onOpenAuth/cti/openApi/querycalllist1"
;
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"connectionid"
,
connectionid
);
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"accessToken"
,
token
);
String
responseStr
=
HttpUtils
.
doPostWithHeader
(
url
,
params
.
toJSONString
(),
header
);
JSONObject
response
=
null
;
try
{
response
=
JSONObject
.
parseObject
(
responseStr
);
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"获取话单出错:"
+
e
.
getMessage
());
}
if
(
response
.
getInteger
(
"code"
)
==
0
)
{
// 登陆成功
try
{
JSONArray
loginData
=
response
.
getJSONArray
(
"data"
);
return
loginData
;
}
catch
(
Exception
e
)
{
throw
new
BadRequest
(
"获取loginData 出错:"
+
e
.
getMessage
());
}
}
else
{
//登陆失败
throw
new
BadRequest
(
"获取话单出错:"
+
response
.
getString
(
"msg"
));
}
}
@Override
public
Map
<
String
,
String
>
downLoadRecordFile
(
String
connectionid
)
{
String
token
=
this
.
getAccessToken
();
String
url
=
ctiUrl
+
"/onOpenAuth/cti/openApi/downloadvoice"
;
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"connectionid"
,
connectionid
);
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"accessToken"
,
token
);
byte
[]
bytes
=
HttpUtils
.
doPostWithHeaderDownload
(
url
,
params
.
toJSONString
(),
header
);
if
(
bytes
==
null
||
bytes
.
length
==
0
)
{
throw
new
BadRequest
(
"获取录音失败"
);
}
else
{
MultipartFile
file
=
new
MockMultipartFile
(
"录音.MP3"
,
"录音.MP3"
,
"application/octet-stream"
,
bytes
);
FeignClientResult
<
Map
<
String
,
String
>>
result
=
Systemctl
.
fileStorageClient
.
updateCommonFile
(
file
);
Map
<
String
,
String
>
map
=
result
.
getResult
();
return
map
;
}
}
/**
* 获取MD加密串
* @param encryptStr
* @return
*/
private
String
encrypt32
(
String
encryptStr
)
{
MessageDigest
md5
;
try
{
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
md5Bytes
=
md5
.
digest
(
encryptStr
.
getBytes
());
StringBuffer
hexValue
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
md5Bytes
.
length
;
i
++)
{
int
val
=
((
int
)
md5Bytes
[
i
])
&
0xff
;
if
(
val
<
16
)
hexValue
.
append
(
"0"
);
hexValue
.
append
(
Integer
.
toHexString
(
val
));
}
encryptStr
=
hexValue
.
toString
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
return
encryptStr
;
}
}
\ No newline at end of file
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/utils/HttpUtils.java
0 → 100644
View file @
491630bf
This diff is collapsed.
Click to expand it.
amos-boot-module/amos-boot-module-biz/pom.xml
View file @
491630bf
...
...
@@ -28,6 +28,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-mock
</artifactId>
<version>
2.0.8
</version>
</dependency>
</dependencies>
<modules>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment