Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
894e1817
Commit
894e1817
authored
May 19, 2022
by
罗长华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整路由回调请求逻辑
parent
9194ccbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
core/src/main/java/com/wecloud/im/service/impl/ImCallbackServiceImpl.java
+14
-12
No files found.
core/src/main/java/com/wecloud/im/service/impl/ImCallbackServiceImpl.java
View file @
894e1817
...
...
@@ -3,6 +3,8 @@ package com.wecloud.im.service.impl;
import
io.geekidea.springbootplus.framework.shiro.signature.SignUtils
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
...
...
@@ -15,7 +17,6 @@ import org.springframework.web.client.RestTemplate;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.lang.id.NanoId
;
import
cn.hutool.core.util.EscapeUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
...
...
@@ -80,12 +81,10 @@ public class ImCallbackServiceImpl implements ImCallbackService {
if
(
StringUtils
.
isNotBlank
(
subscribeUrl
))
{
String
appKey
=
application
.
getAppKey
();
String
appSecret
=
application
.
getAppSecret
();
String
callbackUrl
=
buildCallbackUrl
(
subscribeUrl
,
appKey
,
appSecret
);
try
{
ResponseEntity
<
Object
>
response
=
restTemplate
.
postForEntity
(
callbackUrl
,
buildMsgBody
(
conversation
,
message
),
Object
.
class
);
ResponseEntity
<
Object
>
response
=
restTemplate
.
postForEntity
(
subscribeUrl
,
buildMsgBody
(
conversation
,
message
),
Object
.
class
,
buildUriVariables
(
appKey
,
appSecret
));
// 同步在线状态时需要接收服务提供应答,只要有 HTTP 应答码 200 即认为状态已经同步
if
(
response
.
getStatusCode
().
equals
(
HttpStatus
.
OK
))
{
// do nothing
...
...
@@ -126,8 +125,6 @@ public class ImCallbackServiceImpl implements ImCallbackService {
if
(
StringUtils
.
isNotBlank
(
subscribeUrl
))
{
String
appKey
=
application
.
getAppKey
();
String
appSecret
=
application
.
getAppSecret
();
String
callbackUrl
=
buildCallbackUrl
(
subscribeUrl
,
appKey
,
appSecret
);
ClientOnlineStatusChangeDto
body
=
ClientOnlineStatusChangeDto
.
builder
()
.
userId
(
client
.
getClientId
())
...
...
@@ -137,7 +134,7 @@ public class ImCallbackServiceImpl implements ImCallbackService {
.
clientIp
(
clientIp
)
.
build
();
try
{
ResponseEntity
<
Object
>
response
=
restTemplate
.
postForEntity
(
callbackUrl
,
body
,
Object
.
class
);
ResponseEntity
<
Object
>
response
=
restTemplate
.
postForEntity
(
subscribeUrl
,
body
,
Object
.
class
,
buildUriVariables
(
appKey
,
appSecret
)
);
// 同步在线状态时需要接收服务提供应答,只要有 HTTP 应答码 200 即认为状态已经同步
if
(
response
.
getStatusCode
().
equals
(
HttpStatus
.
OK
))
{
// do nothing
...
...
@@ -158,14 +155,19 @@ public class ImCallbackServiceImpl implements ImCallbackService {
* @param
* @Return
*/
private
String
buildCallbackUrl
(
String
subscribeUrl
,
String
appKey
,
String
appSecret
)
{
private
Map
<
String
,
String
>
buildUriVariables
(
String
appKey
,
String
appSecret
)
{
Map
<
String
,
String
>
uriVariables
=
new
HashMap
<>();
// 计算 Signature (数据签名)
String
nonce
=
NanoId
.
randomNanoId
();
String
date
=
DateUtil
.
formatHttpDate
(
new
Date
());
String
signature
=
SignUtils
.
buildSignature
(
appKey
,
appSecret
,
nonce
,
date
);
String
finalUrl
=
subscribeUrl
+
"?appKey="
+
appKey
+
"&nonce="
+
nonce
+
"&date="
+
date
+
"&signature="
+
EscapeUtil
.
escape
(
signature
);
return
finalUrl
;
uriVariables
.
put
(
"appKey"
,
appKey
);
uriVariables
.
put
(
"nonce"
,
nonce
);
uriVariables
.
put
(
"date"
,
date
);
uriVariables
.
put
(
"signature"
,
signature
);
return
uriVariables
;
}
private
Boolean
isNeedSync
(
ImConversation
conversation
,
ImMessage
message
)
{
...
...
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