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
51116217
Commit
51116217
authored
Feb 25, 2022
by
hewei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'upay-test' into 'upay-prod'
Upay test See merge request
!29
parents
bcbb68a2
1a8cfb67
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
406 additions
and
59 deletions
+406
-59
common/src/main/java/com/wecloud/im/controller/ImConversationController.java
+11
-0
common/src/main/java/com/wecloud/im/controller/serverapi/ApiImMessageController.java
+29
-4
common/src/main/java/com/wecloud/im/mapper/ImConversationMapper.java
+2
-0
common/src/main/java/com/wecloud/im/param/add/ImMsgSendRestApi.java
+6
-8
common/src/main/java/com/wecloud/im/param/add/ImMsgSendRestResult.java
+27
-0
common/src/main/java/com/wecloud/im/service/ImConversationService.java
+7
-1
common/src/main/java/com/wecloud/im/service/ImMessageService.java
+6
-3
common/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+21
-0
common/src/main/java/com/wecloud/im/service/impl/ImMessageServiceImpl.java
+208
-15
common/src/main/resources/mapper/ImConversationMapper.xml
+27
-0
docs/md/内部/wecloud-im服务端REST API对接文档.md
+62
-28
No files found.
common/src/main/java/com/wecloud/im/controller/ImConversationController.java
View file @
51116217
...
...
@@ -15,9 +15,11 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
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.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
...
...
@@ -37,6 +39,15 @@ public class ImConversationController extends BaseController {
@Autowired
private
ImConversationService
imConversationService
;
/**
* 获取会话表详情
*/
@GetMapping
(
"/info"
)
@ApiOperation
(
value
=
"会话表详情"
)
public
ApiResult
<
MyConversationListVo
>
getImConversation
(
@RequestParam
(
"id"
)
Long
id
)
throws
Exception
{
MyConversationListVo
imConversationQueryVo
=
imConversationService
.
getImConversationInfoById
(
id
);
return
ApiResult
.
ok
(
imConversationQueryVo
);
}
/**
* 添加或修改会话名称
...
...
common/src/main/java/com/wecloud/im/controller/serverapi/ApiImMessageController.java
View file @
51116217
package
com
.
wecloud
.
im
.
controller
.
serverapi
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.param.add.ImMsgSendToOnlineClient
;
import
com.wecloud.im.param.add.ImMsgSendRestApi
;
import
com.wecloud.im.param.add.ImMsgSendRestResult
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImMessageService
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
...
...
@@ -34,12 +35,36 @@ public class ApiImMessageController extends BaseController {
@Autowired
private
ImMessageService
imMessageService
;
/**
* 向会话中的client下发消息
*/
@PostMapping
(
"/send"
)
@ApiOperation
(
value
=
"向会话中的client下发消息"
,
notes
=
"应用服务端向某会话中所有client下发消息, 会保存进离线消息, 在线和离线client能收到,离线有系统推送"
)
public
ApiResult
<
ImMsgSendRestResult
>
restApiImMessageSendChat
(
@RequestBody
ImMsgSendRestApi
imMsgSendRestApi
,
@RequestHeader
String
appkey
,
@RequestHeader
String
appSecret
)
throws
Exception
{
// 根据appKey从数据库查询密钥
ImApplication
imApplication
=
imApplicationService
.
getOneByAppKey
(
appkey
);
if
(
imApplication
==
null
)
{
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
null
);
}
// 校验appkey 和appSecret
if
(!
imApplication
.
getAppSecret
().
equals
(
appSecret
))
{
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
null
);
}
return
imMessageService
.
restApiImMessageSend
(
imMsgSendRestApi
,
imApplication
);
}
/**
* 向会话中在线client,下发透传消息
*/
@PostMapping
(
"/sendToOnline
Client
"
)
@PostMapping
(
"/sendToOnline"
)
@ApiOperation
(
value
=
"向会话中在线client,下发透传消息"
,
notes
=
"应用服务端向某会话中所有client下发透传消息, 不会保存进离线消息, 仅在线client能收到"
)
public
ApiResult
<
Boolean
>
restApiImMessageSend
(
@RequestBody
ImMsgSendToOnlineClient
imMsgSendToOnlineClient
,
@RequestHeader
String
appkey
,
@RequestHeader
String
appSecret
)
throws
Exception
{
public
ApiResult
<
ImMsgSendRestResult
>
restApiImMessageSend
(
@RequestBody
ImMsgSendRestApi
imMsgSendRestApi
,
@RequestHeader
String
appkey
,
@RequestHeader
String
appSecret
)
throws
Exception
{
// return imMessageService.updateMsgWithdrawById(imMsgRecall);
...
...
@@ -55,7 +80,7 @@ public class ApiImMessageController extends BaseController {
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
null
);
}
return
imMessageService
.
restApiImMessageSend
(
imMsgSendToOnlineClient
,
imApplication
);
return
imMessageService
.
restApiImMessageSend
Online
(
imMsgSendRestApi
,
imApplication
);
}
...
...
common/src/main/java/com/wecloud/im/mapper/ImConversationMapper.java
View file @
51116217
...
...
@@ -48,6 +48,8 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> {
*/
List
<
MyConversationListVo
>
getMyImConversationListAndMsgCount
(
@Param
(
"clientId"
)
Long
clientId
);
MyConversationListVo
getImConversationAndMsgCountById
(
@Param
(
"clientId"
)
Long
clientId
,
@Param
(
"conversationId"
)
Long
conversationId
);
/**
* 查询用户加入的所有会话
*
...
...
common/src/main/java/com/wecloud/im/param/add/ImMsgSend
ToOnlineClient
.java
→
common/src/main/java/com/wecloud/im/param/add/ImMsgSend
RestApi
.java
View file @
51116217
...
...
@@ -18,19 +18,17 @@ import java.util.HashMap;
@Accessors
(
chain
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"ImMsgSendToOnlineClient"
)
public
class
ImMsgSend
ToOnlineClient
extends
BaseEntity
{
public
class
ImMsgSend
RestApi
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
// @ApiModelProperty(value = "自定义透传内容
", required = true)
// private String cont
ent;
@ApiModelProperty
(
value
=
"发送者id
"
,
required
=
true
)
private
String
senderCli
ent
;
@ApiModelProperty
(
value
=
"自定义透传内容 ,为任意参数名称和类型的对象,供开发者扩展使用。"
,
required
=
true
)
@ApiModelProperty
(
value
=
"自定义内容 ,为任意参数名称和类型的对象,供开发者扩展使用。"
,
required
=
true
)
private
HashMap
content
;
@ApiModelProperty
(
value
=
"会话id"
,
required
=
true
)
private
Long
conversationId
;
// @ApiModelProperty(value = "会话id", required = true)
// private Long conversationId;
}
common/src/main/java/com/wecloud/im/param/add/ImMsgSendRestResult.java
0 → 100644
View file @
51116217
package
com
.
wecloud
.
im
.
param
.
add
;
import
io.geekidea.springbootplus.framework.common.entity.BaseEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* 服务端api消息下发
*
* @author wei
*/
@Data
@Accessors
(
chain
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"ImMsgSendRestResult"
)
public
class
ImMsgSendRestResult
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"消息id"
,
required
=
true
)
private
Long
msgId
;
}
common/src/main/java/com/wecloud/im/service/ImConversationService.java
View file @
51116217
...
...
@@ -103,6 +103,11 @@ public interface ImConversationService extends BaseService<ImConversation> {
*/
ImConversationQueryVo
getImConversationById
(
Long
id
)
throws
Exception
;
MyConversationListVo
getImConversationAndMsgCountById
(
Long
clientId
,
Long
conversationId
);
MyConversationListVo
getImConversationInfoById
(
Long
id
)
throws
Exception
;
/**
* 获取分页对象
*
...
...
@@ -110,7 +115,8 @@ public interface ImConversationService extends BaseService<ImConversation> {
* @return
* @throws Exception
*/
Paging
<
ImConversationQueryVo
>
getImConversationPageList
(
ImConversationPageParam
imConversationPageParam
)
throws
Exception
;
Paging
<
ImConversationQueryVo
>
getImConversationPageList
(
ImConversationPageParam
imConversationPageParam
)
throws
Exception
;
/**
...
...
common/src/main/java/com/wecloud/im/service/ImMessageService.java
View file @
51116217
...
...
@@ -5,7 +5,8 @@ import com.wecloud.im.entity.ImClient;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.param.ImHistoryMessagePageParam
;
import
com.wecloud.im.param.add.ImMsgRecall
;
import
com.wecloud.im.param.add.ImMsgSendToOnlineClient
;
import
com.wecloud.im.param.add.ImMsgSendRestApi
;
import
com.wecloud.im.param.add.ImMsgSendRestResult
;
import
com.wecloud.im.param.add.ImMsgUpdate
;
import
com.wecloud.im.vo.ImMessageOfflineListVo
;
import
com.wecloud.im.vo.OfflineMsgDto
;
...
...
@@ -27,10 +28,12 @@ public interface ImMessageService extends BaseService<ImMessage> {
/**
* 下发透传消息
*
* @param imMsgSend
ToOnlineClient
* @param imMsgSend
RestApi
* @return
*/
ApiResult
<
Boolean
>
restApiImMessageSend
(
ImMsgSendToOnlineClient
imMsgSendToOnlineClient
,
ImApplication
imApplication
);
ApiResult
<
ImMsgSendRestResult
>
restApiImMessageSendOnline
(
ImMsgSendRestApi
imMsgSendRestApi
,
ImApplication
imApplication
);
ApiResult
<
ImMsgSendRestResult
>
restApiImMessageSend
(
ImMsgSendRestApi
imMsgSendRestApi
,
ImApplication
imApplication
);
ImMessage
saveImMessage
(
ImApplication
imApplication
,
ImClient
imClientSender
,
Long
toConversationId
,
long
messageId
,
String
content
);
...
...
common/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
51116217
...
...
@@ -786,6 +786,27 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
return
imConversationMapper
.
getImConversationById
(
id
);
}
@Override
public
MyConversationListVo
getImConversationAndMsgCountById
(
Long
clientId
,
Long
conversationId
)
{
return
imConversationMapper
.
getImConversationAndMsgCountById
(
clientId
,
conversationId
);
}
@Override
public
MyConversationListVo
getImConversationInfoById
(
Long
id
)
throws
Exception
{
ImClient
client
=
imClientService
.
getCurentClient
();
MyConversationListVo
imConversationAndMsgCountById
=
this
.
getImConversationAndMsgCountById
(
client
.
getId
(),
id
);
JsonMapper
jsonMapper
=
new
JsonMapper
();
HashMap
attributess
=
jsonMapper
.
readValue
(
imConversationAndMsgCountById
.
getAttribute
(),
HashMap
.
class
);
imConversationAndMsgCountById
.
setAttributes
(
attributess
);
return
imConversationAndMsgCountById
;
}
@Override
public
Paging
<
ImConversationQueryVo
>
getImConversationPageList
(
ImConversationPageParam
imConversationPageParam
)
throws
Exception
{
Page
<
ImConversationQueryVo
>
page
=
new
PageInfo
<>(
imConversationPageParam
,
OrderItem
.
desc
(
getLambdaColumn
(
ImConversation:
:
getCreateTime
)));
...
...
common/src/main/java/com/wecloud/im/service/impl/ImMessageServiceImpl.java
View file @
51116217
...
...
@@ -11,17 +11,21 @@ import com.wecloud.im.entity.ImApplication;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImConversationMembers
;
import
com.wecloud.im.entity.ImInbox
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImMessageOnlineSend
;
import
com.wecloud.im.mapper.ImMessageMapper
;
import
com.wecloud.im.param.ImHistoryMessagePageParam
;
import
com.wecloud.im.param.add.ImMsgRecall
;
import
com.wecloud.im.param.add.ImMsgSendToOnlineClient
;
import
com.wecloud.im.param.add.ImMsgSendRestApi
;
import
com.wecloud.im.param.add.ImMsgSendRestResult
;
import
com.wecloud.im.param.add.ImMsgUpdate
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImClientBlacklistService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImInboxService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.vo.ImMessageOfflineListVo
;
import
com.wecloud.im.vo.OfflineMsgDto
;
...
...
@@ -35,6 +39,7 @@ import io.geekidea.springbootplus.framework.common.api.ApiResult;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.core.pagination.PageInfo
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -43,6 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
/**
...
...
@@ -57,44 +63,80 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
// private static final JsonMapper JSON_MAPPER = new JsonMapper();
public
static
final
String
PUSH_KEY
=
"push"
;
public
static
final
String
MSG_ID
=
"msgId"
;
private
static
final
String
TO_CONVERSATION_KEY
=
"toConversation"
;
private
static
final
JsonMapper
JSON_MAPPER
=
new
JsonMapper
();
@Autowired
private
Im
MessageMapper
imMessageMapper
;
private
Im
ClientBlacklistService
imClientBlacklistService
;
@Autowired
private
ImClientService
imClient
Service
;
private
WriteDataService
writeData
Service
;
@Autowired
private
Im
ConversationService
imConversation
Service
;
private
Im
MessageService
imMessage
Service
;
@Autowired
private
PushTask
pushTask
;
private
ImInboxService
imInboxService
;
@Autowired
private
ImApplicationService
imApplicationService
;
@Autowired
private
ImConversationMembersService
imConversationMembersService
;
@Autowired
private
WriteDataService
writeDataService
;
private
ImClientService
imClientService
;
@Autowired
private
PushTask
systemPush
;
@Autowired
private
ImMessageMapper
imMessageMapper
;
@Autowired
private
ImConversationService
imConversationService
;
@Autowired
private
PushTask
pushTask
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ApiResult
<
Boolean
>
restApiImMessageSend
(
ImMsgSendToOnlineClient
imMsgSendToOnlineClient
,
ImApplication
imApplication
)
{
public
ApiResult
<
ImMsgSendRestResult
>
restApiImMessageSendOnline
(
ImMsgSendRestApi
imMsgSendRestApi
,
ImApplication
imApplication
)
{
if
(
imApplication
==
null
)
{
log
.
info
(
"imApplication为空"
);
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
// 查询发送者client
ImClient
imClientSender
=
getClientSender
(
imMsgSendRestApi
.
getSenderClient
(),
imApplication
);
if
(
imClientSender
==
null
)
{
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
// 获取会话id
if
(
imMsgSendRestApi
.
getContent
().
get
(
TO_CONVERSATION_KEY
)
==
null
)
{
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
Long
toConversationId
=
Long
.
valueOf
(
imMsgSendRestApi
.
getContent
().
get
(
TO_CONVERSATION_KEY
).
toString
());
// 查询该会话所有成员
List
<
ImConversationMembers
>
membersList
=
imConversationMembersService
.
list
(
new
QueryWrapper
<
ImConversationMembers
>().
lambda
()
.
eq
(
ImConversationMembers:
:
getFkConversationId
,
imMsgSendToOnlineClient
.
getConversationId
())
.
eq
(
ImConversationMembers:
:
getFkConversationId
,
toConversationId
)
.
notIn
(
ImConversationMembers:
:
getFkClientId
,
imClientSender
.
getId
())
);
if
(
membersList
.
isEmpty
())
{
log
.
info
(
"membersList为空,toConversationId:"
+
imMsgSendToOnlineClient
.
getConversationId
());
return
ApiResult
.
fail
();
log
.
info
(
"membersList为空,toConversationId:"
+
toConversationId
);
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
imMsgSendRestApi
.
getContent
().
remove
(
TO_CONVERSATION_KEY
);
ImApiMessageOnlineSend
imApiMessageOnlineSend
=
new
ImApiMessageOnlineSend
();
imApiMessageOnlineSend
.
setCreateTime
(
new
Date
());
...
...
@@ -102,14 +144,15 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
JsonMapper
jsonMapper
=
new
JsonMapper
();
try
{
String
attributes
=
jsonMapper
.
writeValueAsString
(
imMsgSend
ToOnlineClient
.
getContent
());
String
attributes
=
jsonMapper
.
writeValueAsString
(
imMsgSend
RestApi
.
getContent
());
imApiMessageOnlineSend
.
setContent
(
attributes
);
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
return
ApiResult
.
fail
();
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
imApiMessageOnlineSend
.
setConversationId
(
imMsgSendToOnlineClient
.
getConversationId
()
);
imApiMessageOnlineSend
.
setConversationId
(
toConversationId
);
// 遍历发送
...
...
@@ -136,9 +179,159 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
}
ImMsgSendRestResult
data
=
new
ImMsgSendRestResult
();
data
.
setMsgId
(
1L
);
return
ApiResult
.
ok
(
data
);
}
private
ImClient
getClientSender
(
String
clientUniId
,
ImApplication
imApplication
)
{
ImClient
imClientSender
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
imApplication
.
getId
())
.
eq
(
ImClient:
:
getClientId
,
clientUniId
));
if
(
imClientSender
==
null
)
{
log
.
info
(
"imClientSender为空"
);
return
null
;
}
return
imClientSender
;
}
@Override
public
ApiResult
<
ImMsgSendRestResult
>
restApiImMessageSend
(
ImMsgSendRestApi
imMsgSendRestApi
,
ImApplication
imApplication
)
{
if
(
imApplication
==
null
)
{
log
.
info
(
"imApplication为空"
);
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
// 查询发送者client
ImClient
imClientSender
=
getClientSender
(
imMsgSendRestApi
.
getSenderClient
(),
imApplication
);
if
(
imClientSender
==
null
)
{
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
// 获取会话id
HashMap
dataHashMap
=
imMsgSendRestApi
.
getContent
();
if
(
dataHashMap
.
get
(
TO_CONVERSATION_KEY
)
==
null
)
{
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
Long
toConversationId
=
Long
.
valueOf
(
dataHashMap
.
get
(
TO_CONVERSATION_KEY
).
toString
());
// 查询该会话所有成员
List
<
ImConversationMembers
>
membersList
=
imConversationMembersService
.
list
(
new
QueryWrapper
<
ImConversationMembers
>().
lambda
()
.
eq
(
ImConversationMembers:
:
getFkConversationId
,
toConversationId
)
.
notIn
(
ImConversationMembers:
:
getFkClientId
,
imClientSender
.
getId
())
);
if
(
membersList
.
isEmpty
())
{
log
.
info
(
"membersList为空,toConversationId:"
+
toConversationId
);
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
dataHashMap
.
remove
(
TO_CONVERSATION_KEY
);
// 获取自定义推送字段
HashMap
<
String
,
Object
>
pushMap
=
null
;
if
(
dataHashMap
.
get
(
PUSH_KEY
)
!=
null
)
{
pushMap
=
(
HashMap
<
String
,
Object
>)
dataHashMap
.
get
(
PUSH_KEY
);
dataHashMap
.
remove
(
PUSH_KEY
);
}
String
content
=
null
;
try
{
content
=
JSON_MAPPER
.
writeValueAsString
(
imMsgSendRestApi
.
getContent
());
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
}
// 判断为单聊
if
(
membersList
.
size
()
==
1
)
{
// 拉黑逻辑
if
(
black
(
imClientSender
,
membersList
))
{
return
ApiResult
.
result
(
ApiCode
.
FAIL
,
new
ImMsgSendRestResult
());
}
}
// 生成消息id
long
messageId
=
SnowflakeUtil
.
getId
();
// 保存消息至消息表
ImMessage
imMessage
=
imMessageService
.
saveImMessage
(
imApplication
,
imClientSender
,
toConversationId
,
messageId
,
content
);
// 封装响应的实体
ImMessageOnlineSend
imMessageOnlineSend
=
new
ImMessageOnlineSend
();
BeanUtils
.
copyProperties
(
imMessage
,
imMessageOnlineSend
);
imMessageOnlineSend
.
setMsgId
(
imMessage
.
getId
());
imMessageOnlineSend
.
setSender
(
imMsgSendRestApi
.
getSenderClient
());
imMessageOnlineSend
.
setContent
(
dataHashMap
);
imMessageOnlineSend
.
setConversationId
(
toConversationId
);
// 遍历发送
for
(
ImConversationMembers
conversationMembers
:
membersList
)
{
// 保存收件箱
long
imInboxId
=
SnowflakeUtil
.
getId
();
ImInbox
imInbox
=
new
ImInbox
();
imInbox
.
setId
(
imInboxId
);
imInbox
.
setCreateTime
(
new
Date
());
imInbox
.
setFkAppid
(
imApplication
.
getId
());
imInbox
.
setReceiver
(
conversationMembers
.
getFkClientId
());
imInbox
.
setFkMsgId
(
messageId
);
imInbox
.
setReadMsgStatus
(
0
);
imInbox
.
setReceiverMsgStatus
(
0
);
imInbox
.
setFkConversationId
(
toConversationId
);
imInboxService
.
save
(
imInbox
);
// 查询接收方
ImClient
imClientReceiver
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
imApplication
.
getId
())
.
eq
(
ImClient:
:
getId
,
conversationMembers
.
getFkClientId
()));
if
(
imClientReceiver
==
null
)
{
continue
;
}
// 向接收方推送
WsResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
WsResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
imApplication
.
getAppKey
(),
imClientReceiver
.
getClientId
());
// 异步推送系统通知消息
systemPush
.
push
(
pushMap
,
imClientReceiver
,
imApplication
);
}
ImMsgSendRestResult
data
=
new
ImMsgSendRestResult
();
data
.
setMsgId
(
messageId
);
return
ApiResult
.
ok
(
data
);
}
private
boolean
black
(
ImClient
imClientSender
,
List
<
ImConversationMembers
>
membersList
)
{
// 判断是否被拉黑
boolean
beBlack
=
imClientBlacklistService
.
isBeBlack
(
membersList
.
get
(
0
).
getFkClientId
(),
imClientSender
.
getId
());
if
(
beBlack
)
{
log
.
info
(
"被对方拉黑了"
);
return
true
;
}
// 是否把对方拉黑
boolean
black
=
imClientBlacklistService
.
isBeBlack
(
imClientSender
.
getId
(),
membersList
.
get
(
0
).
getFkClientId
());
if
(
black
)
{
log
.
info
(
"你把对方拉黑了"
);
return
true
;
}
return
false
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
...
...
common/src/main/resources/mapper/ImConversationMapper.xml
View file @
51116217
...
...
@@ -109,5 +109,32 @@
WHERE im_conversation_members.fk_client_id = #{clientId1}
HAVING members_count = 2 LIMIT 1
</select>
<select
id=
"getImConversationAndMsgCountById"
resultType=
"com.wecloud.im.vo.MyConversationListVo"
>
SELECT imConversation.id,
imConversation.create_time,
imConversation.`name`,
imConversation.attributes AS attribute,
imConversation.system,
im_client.client_id AS creator,
(SELECT COUNT(im_inbox.id)
FROM im_inbox
WHERE im_inbox.fk_conversation_id = imConversation.id
AND im_inbox.receiver = #{clientId}
AND im_inbox.read_msg_status = 0) AS msg_not_read_count,
(
SELECT GROUP_CONCAT(im_client.client_id)
FROM im_conversation_members AS im_conversation_members
INNER JOIN im_client AS im_client ON im_client.id = im_conversation_members.fk_client_id
WHERE im_conversation_members.fk_conversation_id = imConversation.id
) AS members,
(SELECT COUNT(*)
FROM im_conversation_members
WHERE fk_conversation_id = imConversation.id) AS memberCount
FROM im_conversation AS imConversation
INNER JOIN im_client AS im_client ON im_client.id = imConversation.creator
WHERE imConversation.id = #{conversationId}
GROUP BY imConversation.id
</select>
</mapper>
docs/md/内部/wecloud-im服务端REST API对接文档.md
View file @
51116217
# wec
loud-im服务端REST API对接文档
# wec
loud-im服务端REST API对接文档
...
...
@@ -2,31 +2,15 @@
## 本地API文档地址
http://192.168.1.
110
:8082/api/doc.html#/home
http://192.168.1.
89
:8082/api/doc.html#/home
账号密码admin admin
以上只包含api接口文档 websocket对接说明在此文档中
## 测试外网
文档:
```
https://wstest.im199.com/api/doc.html#/home
```
__
_
测试外网请求示例:
```
https://wstest.im199.com/api/imApplication/add
```
以上只包含api接口文档 websocket对接说明在此文档中
____
__
_
## 测试外网
...
...
@@ -57,7 +41,7 @@ _______
## 鉴权方式
### 方式一(
正在开发
):
### 方式一(
开发完成
):
对于 POST 和 PUT 请求,请求的主体必须是 JSON 格式,而且 HTTP header 的 Content-Type 需要设置为
`application/json`
。
...
...
@@ -65,13 +49,15 @@ _______
**示例**
: rest-api-会话成员表分页列表
#### **示例**:
rest-api-会话成员表分页列表
-
Request URL: http://192.168.1.89:8082/api/restApi/imConversationMembers/findList
-
Request Method: POST
**请求头
部
**
**请求头
参数
**
```
appkey: D13ug9jsWbJbeVx1
...
...
@@ -81,11 +67,25 @@ appSecret: c92edcc7ba0c68b9b1da4cec6f3511876b2302faf2ab3737
**请求body**
**请求body
示例
**
```
{
"conversationId": 1442742976269914112
"senderClient": "client_2",
"content": {
"reqId":"1231223123",
"cmd":1,
"data":{
"diyAbcd":"aaaa自已定2义字段的值",
"toConversation":1495943481078714368,
"type":-1,
"text":"发给12312123213这是一123个纯文本消息,发给12312123213这是一123个纯文本消息发给12312123213这是一123个纯文本消息",
"attrs":{
"a":"attrs 阿道夫123123是用来213存储用户自定义的一些键值对,ttrs 阿道夫123123是用来213存储用户自定义的一些键值对",
"b":"attrs 阿道夫123123是用来213存储用户自定义的一些键值对,ttrs 阿道夫123123是用来213存储用户自定义的一些键值对"
}
}
}
}
```
...
...
@@ -94,7 +94,23 @@ appSecret: c92edcc7ba0c68b9b1da4cec6f3511876b2302faf2ab3737
**响应数据**
```
{"code":200,"message":"成功","data":[{"clientId":"1442742442803503105"},{"clientId":"1435497966619996162"}]}
{
"senderClient": "client_2",
"content": {
"reqId":"1231223123",
"cmd":1,
"data":{
"diyAbcd":"aaaa自已定2义字段的值",
"toConversation":1495943481078714368,
"type":-1,
"text":"发给12312123213这是一123个纯文本消息,发给12312123213这是一123个纯文本消息发给12312123213这是一123个纯文本消息",
"attrs":{
"a":"attrs 阿道夫123123是用来213存储用户自定义的一些键值对,ttrs 阿道夫123123是用来213存储用户自定义的一些键值对",
"b":"attrs 阿道夫123123是用来213存储用户自定义的一些键值对,ttrs 阿道夫123123是用来213存储用户自定义的一些键值对"
}
}
}
}
```
...
...
@@ -143,7 +159,19 @@ curl -X PUT \
一个请求是否成功是由 HTTP 状态码标明的。一个 2XX 的状态码表示成功,而一个 4XX 表示请求失败。当一个请求失败时响应的主体仍然是一个 JSON 对象,但是总是会包含
`code`
和
`error`
这两个字段,你可以用它们来进行调试。举个例子,如果尝试用非法的属性名来保存一个对象会得到如下信息:
## 单聊、群聊
### 服务端发消息
文档: 服务端rest-API-消息 - > 向会话中的client下发消息
文档地址
http://192.168.1.89:8082/api/doc.html#/app/%E6%9C%8D%E5%8A%A1%E7%AB%AFrest-API-%E6%B6%88%E6%81%AF/restApiImMessageSendChatUsingPOST
### 创建对话
...
...
@@ -159,7 +187,13 @@ curl -X PUT \
### 查询成员
### 单聊、群聊-发消息
### 查询历史消息
...
...
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