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
c9550ee2
Commit
c9550ee2
authored
May 14, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
创建会话,并添加成员
parent
debfa697
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
192 additions
and
50 deletions
+192
-50
bootstrap/src/test/java/io/geekidea/springbootplus/test/SignTest.java
+1
-1
common/src/main/java/com/wecloud/im/controller/ImConversationController.java
+20
-10
common/src/main/java/com/wecloud/im/controller/ImConversationMembersController.java
+11
-19
common/src/main/java/com/wecloud/im/param/add/ImConversationCreate.java
+34
-0
common/src/main/java/com/wecloud/im/service/ImConversationService.java
+5
-0
common/src/main/java/com/wecloud/im/service/impl/ImClientLoginServiceImpl.java
+2
-1
common/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+83
-0
common/src/main/java/com/wecloud/im/tillo/netty/handler/NettyApiRequest.java
+36
-11
framework/src/main/java/io/geekidea/springbootplus/framework/common/api/ApiResult.java
+0
-8
No files found.
bootstrap/src/test/java/io/geekidea/springbootplus/test/SignTest.java
View file @
c9550ee2
...
@@ -32,7 +32,7 @@ public class SignTest {
...
@@ -32,7 +32,7 @@ public class SignTest {
}
}
public
static
void
main
(
String
[]
args
)
throws
JsonProcessingException
{
public
static
void
main
(
String
[]
args
)
throws
JsonProcessingException
{
String
clientId
=
"hahah_3
0
"
;
String
clientId
=
"hahah_3
1
"
;
String
appKey
=
"elLwpel1gWCHDqZy"
;
String
appKey
=
"elLwpel1gWCHDqZy"
;
String
appSecret
=
"68809bb5a9077a83631aeb0b17b5965d6b2302faf2ab3737"
;
String
appSecret
=
"68809bb5a9077a83631aeb0b17b5965d6b2302faf2ab3737"
;
String
timestemp
=
String
.
valueOf
(
new
Date
().
getTime
());
String
timestemp
=
String
.
valueOf
(
new
Date
().
getTime
());
...
...
common/src/main/java/com/wecloud/im/controller/ImConversationController.java
View file @
c9550ee2
package
com
.
wecloud
.
im
.
controller
;
package
com
.
wecloud
.
im
.
controller
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.param.add.ImConversationCreate
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImConversationService
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.controller.BaseController
;
import
io.geekidea.springbootplus.framework.common.controller.BaseController
;
import
io.geekidea.springbootplus.framework.core.validator.groups.Add
;
import
io.geekidea.springbootplus.framework.log.annotation.OperationLog
;
import
io.geekidea.springbootplus.framework.log.annotation.OperationLog
;
import
io.geekidea.springbootplus.framework.log.enums.OperationLogType
;
import
io.geekidea.springbootplus.framework.log.enums.OperationLogType
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -25,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -25,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
*/
@Slf4j
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/
imC
onversation"
)
@RequestMapping
(
"/
c
onversation"
)
@Api
(
value
=
"会话表API"
,
tags
=
{
"会话表"
})
@Api
(
value
=
"会话表API"
,
tags
=
{
"会话表"
})
public
class
ImConversationController
extends
BaseController
{
public
class
ImConversationController
extends
BaseController
{
...
@@ -33,17 +32,28 @@ public class ImConversationController extends BaseController {
...
@@ -33,17 +32,28 @@ public class ImConversationController extends BaseController {
private
ImConversationService
imConversationService
;
private
ImConversationService
imConversationService
;
/**
/**
*
添加会话表
*
创建会话
*/
*/
@PostMapping
(
"/
add
"
)
@PostMapping
(
"/
create
"
)
@OperationLog
(
name
=
"
添加会话表
"
,
type
=
OperationLogType
.
ADD
)
@OperationLog
(
name
=
"
创建会话
"
,
type
=
OperationLogType
.
ADD
)
@ApiOperation
(
value
=
"
添加会话表
"
)
@ApiOperation
(
value
=
"
创建会话
"
)
public
ApiResult
<
Boolean
>
addImConversation
(
@Validated
(
Add
.
class
)
@RequestBody
ImConversation
imConversation
)
throws
Exception
{
public
ApiResult
<
ImConversation
>
createImConversation
(
@RequestBody
ImConversationCreate
imConversationCreate
)
throws
Exception
{
boolean
flag
=
imConversationService
.
saveImConversation
(
imConversation
);
ApiResult
<
ImConversation
>
imConversation
=
imConversationService
.
createImConversation
(
imConversationCreate
);
return
ApiResult
.
result
(
flag
)
;
return
imConversation
;
}
}
// /**
// /**
// * 添加会话表
// */
// @PostMapping("/add")
// @OperationLog(name = "添加会话表", type = OperationLogType.ADD)
// @ApiOperation(value = "添加会话表")
// public ApiResult<Boolean> addImConversation(@Validated(Add.class) @RequestBody ImConversation imConversation) throws Exception {
// boolean flag = imConversationService.saveImConversation(imConversation);
// return ApiResult.result(flag);
// }
// /**
// * 修改会话表
// * 修改会话表
// */
// */
// @PostMapping("/update")
// @PostMapping("/update")
...
...
common/src/main/java/com/wecloud/im/controller/ImConversationMembersController.java
View file @
c9550ee2
package
com
.
wecloud
.
im
.
controller
;
package
com
.
wecloud
.
im
.
controller
;
import
com.wecloud.im.entity.ImConversationMembers
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.controller.BaseController
;
import
io.geekidea.springbootplus.framework.common.controller.BaseController
;
import
io.geekidea.springbootplus.framework.core.validator.groups.Add
;
import
io.geekidea.springbootplus.framework.log.annotation.OperationLog
;
import
io.geekidea.springbootplus.framework.log.enums.OperationLogType
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
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.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -32,16 +23,17 @@ public class ImConversationMembersController extends BaseController {
...
@@ -32,16 +23,17 @@ public class ImConversationMembersController extends BaseController {
@Autowired
@Autowired
private
ImConversationMembersService
imConversationMembersService
;
private
ImConversationMembersService
imConversationMembersService
;
/**
* 添加会话成员表
// /**
*/
// * 添加会话成员表
@PostMapping
(
"/add"
)
// */
@OperationLog
(
name
=
"添加会话成员表"
,
type
=
OperationLogType
.
ADD
)
// @PostMapping("/add")
@ApiOperation
(
value
=
"添加会话成员表"
)
// @OperationLog(name = "添加会话成员表", type = OperationLogType.ADD)
public
ApiResult
<
Boolean
>
addImConversationMembers
(
@Validated
(
Add
.
class
)
@RequestBody
ImConversationMembers
imConversationMembers
)
throws
Exception
{
// @ApiOperation(value = "添加会话成员表")
boolean
flag
=
imConversationMembersService
.
saveImConversationMembers
(
imConversationMembers
);
// public ApiResult<Boolean> addImConversationMembers(@Validated(Add.class) @RequestBody ImConversationMembers imConversationMembers) throws Exception {
return
ApiResult
.
result
(
flag
);
// boolean flag = imConversationMembersService.saveImConversationMembers(imConversationMembers);
}
// return ApiResult.result(flag);
// }
//
//
// /**
// /**
// * 修改会话成员表
// * 修改会话成员表
...
...
common/src/main/java/com/wecloud/im/param/add/ImConversationCreate.java
0 → 100644
View file @
c9550ee2
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
;
import
java.util.List
;
/**
* 会话表
*
* @author wei
* @since 2021-05-07
*/
@Data
@Accessors
(
chain
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"ImConversationCreate"
)
public
class
ImConversationCreate
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
"可选 对话的名字,可为群组命名。"
)
private
String
name
;
@ApiModelProperty
(
"可选 自定义属性,供开发者扩展使用。"
)
private
Object
attributes
;
@ApiModelProperty
(
"可选 邀请加入会话的客户端,如创建单聊,则填入对方的clientId"
)
private
List
<
String
>
clientIds
;
}
common/src/main/java/com/wecloud/im/service/ImConversationService.java
View file @
c9550ee2
...
@@ -3,6 +3,8 @@ package com.wecloud.im.service;
...
@@ -3,6 +3,8 @@ package com.wecloud.im.service;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.param.ImConversationPageParam
;
import
com.wecloud.im.param.ImConversationPageParam
;
import
com.wecloud.im.param.ImConversationQueryVo
;
import
com.wecloud.im.param.ImConversationQueryVo
;
import
com.wecloud.im.param.add.ImConversationCreate
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
...
@@ -23,6 +25,9 @@ public interface ImConversationService extends BaseService<ImConversation> {
...
@@ -23,6 +25,9 @@ public interface ImConversationService extends BaseService<ImConversation> {
*/
*/
boolean
saveImConversation
(
ImConversation
imConversation
)
throws
Exception
;
boolean
saveImConversation
(
ImConversation
imConversation
)
throws
Exception
;
ApiResult
<
ImConversation
>
createImConversation
(
ImConversationCreate
imConversationCreate
);
/**
/**
* 修改
* 修改
*
*
...
...
common/src/main/java/com/wecloud/im/service/impl/ImClientLoginServiceImpl.java
View file @
c9550ee2
...
@@ -88,6 +88,7 @@ public class ImClientLoginServiceImpl implements ImClientLoginService {
...
@@ -88,6 +88,7 @@ public class ImClientLoginServiceImpl implements ImClientLoginService {
if
(
imClient
==
null
)
{
if
(
imClient
==
null
)
{
log
.
debug
(
"client不存在,先走注册流程"
);
log
.
debug
(
"client不存在,先走注册流程"
);
imClient
=
new
ImClient
();
imClient
.
setId
(
new
Snowflake
(
1L
,
1L
).
nextId
());
imClient
.
setId
(
new
Snowflake
(
1L
,
1L
).
nextId
());
imClient
.
setFkAppid
(
imApplication
.
getId
());
imClient
.
setFkAppid
(
imApplication
.
getId
());
imClient
.
setClientId
(
imTokenVerify
.
getClientId
());
imClient
.
setClientId
(
imTokenVerify
.
getClientId
());
...
@@ -98,7 +99,7 @@ public class ImClientLoginServiceImpl implements ImClientLoginService {
...
@@ -98,7 +99,7 @@ public class ImClientLoginServiceImpl implements ImClientLoginService {
String
generateToken
=
JwtUtil
.
generateToken
(
imTokenVerify
.
getClientId
(),
imTokenVerify
.
getAppKey
(),
secret
,
null
);
String
generateToken
=
JwtUtil
.
generateToken
(
imTokenVerify
.
getClientId
(),
imTokenVerify
.
getAppKey
(),
secret
,
null
);
// 保存redis
// 保存redis
redisTemplate
.
opsForValue
().
set
(
"client:"
+
imApplication
.
getAppKey
()
+
":"
+
imTokenVerify
.
getClientId
(),
generateToken
);
//
redisTemplate.opsForValue().set("client:" + imApplication.getAppKey() + ":" + imTokenVerify.getClientId(), generateToken);
JwtToken
jwtToken
=
new
JwtToken
()
JwtToken
jwtToken
=
new
JwtToken
()
.
build
(
generateToken
,
secret
,
jwtProperties
.
getExpireSecond
(),
imClient
.
getClientId
(),
imTokenVerify
.
getAppKey
());
.
build
(
generateToken
,
secret
,
jwtProperties
.
getExpireSecond
(),
imClient
.
getClientId
(),
imTokenVerify
.
getAppKey
());
...
...
common/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
c9550ee2
package
com
.
wecloud
.
im
.
service
.
impl
;
package
com
.
wecloud
.
im
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImConversation
;
import
com.wecloud.im.entity.ImConversationMembers
;
import
com.wecloud.im.mapper.ImConversationMapper
;
import
com.wecloud.im.mapper.ImConversationMapper
;
import
com.wecloud.im.param.ImConversationPageParam
;
import
com.wecloud.im.param.ImConversationPageParam
;
import
com.wecloud.im.param.ImConversationQueryVo
;
import
com.wecloud.im.param.ImConversationQueryVo
;
import
com.wecloud.im.param.add.ImConversationCreate
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImConversationService
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.core.pagination.PageInfo
;
import
io.geekidea.springbootplus.framework.core.pagination.PageInfo
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
io.geekidea.springbootplus.framework.shiro.jwt.JwtToken
;
import
io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.shiro.SecurityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
/**
/**
* 会话表 服务实现类
* 会话表 服务实现类
*
*
...
@@ -29,12 +43,81 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -29,12 +43,81 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Autowired
@Autowired
private
ImConversationMapper
imConversationMapper
;
private
ImConversationMapper
imConversationMapper
;
@Autowired
private
ImConversationMembersService
imConversationMembersService
;
@Autowired
private
ImConversationService
imConversationService
;
@Autowired
private
ImClientService
imClientService
;
@Autowired
private
ImApplicationService
imApplicationService
;
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
boolean
saveImConversation
(
ImConversation
imConversation
)
throws
Exception
{
public
boolean
saveImConversation
(
ImConversation
imConversation
)
throws
Exception
{
return
super
.
save
(
imConversation
);
return
super
.
save
(
imConversation
);
}
}
@Override
public
ApiResult
<
ImConversation
>
createImConversation
(
ImConversationCreate
imConversationCreate
)
{
JwtToken
jwtToken
=
(
JwtToken
)
SecurityUtils
.
getSubject
().
getPrincipal
();
Long
imConversationId
=
SnowflakeUtil
.
getId
();
// 根据appKey查询appid
ImApplication
imApplication
=
imApplicationService
.
getOne
(
new
QueryWrapper
<
ImApplication
>().
lambda
().
eq
(
ImApplication:
:
getAppKey
,
jwtToken
.
getAppKey
())
);
Long
fkAppid
=
imApplication
.
getId
();
ImClient
client
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
fkAppid
)
.
eq
(
ImClient:
:
getClientId
,
jwtToken
.
getClientId
()));
Long
creator
=
client
.
getId
();
// 创建会话
ImConversation
imConversation
=
new
ImConversation
();
imConversation
.
setId
(
imConversationId
);
imConversation
.
setCreateTime
(
new
Date
());
imConversation
.
setLastMessage
(
null
);
imConversation
.
setFkAppid
(
fkAppid
);
imConversation
.
setCreator
(
creator
);
imConversation
.
setName
(
imConversationCreate
.
getName
());
imConversation
.
setAttributes
(
imConversationCreate
.
getAttributes
().
toString
());
imConversation
.
setSystem
(
false
);
imConversationService
.
save
(
imConversation
);
// 将自己添加到会话
Long
imConversationMembersId
=
SnowflakeUtil
.
getId
();
ImConversationMembers
imConversationMembers
=
new
ImConversationMembers
();
imConversationMembers
.
setId
(
imConversationMembersId
);
imConversationMembers
.
setCreateTime
(
new
Date
());
imConversationMembers
.
setFkAppid
(
fkAppid
);
imConversationMembers
.
setFkConversationId
(
imConversationId
);
imConversationMembers
.
setFkClientId
(
creator
);
imConversationMembersService
.
save
(
imConversationMembers
);
// 将他人添加到会话
for
(
String
id
:
imConversationCreate
.
getClientIds
())
{
ImClient
client2
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
fkAppid
)
.
eq
(
ImClient:
:
getClientId
,
id
));
Long
imConversationMembersId2
=
SnowflakeUtil
.
getId
();
ImConversationMembers
imConversationMembers2
=
new
ImConversationMembers
();
imConversationMembers2
.
setId
(
imConversationMembersId2
);
imConversationMembers2
.
setCreateTime
(
new
Date
());
imConversationMembers2
.
setFkAppid
(
fkAppid
);
imConversationMembers2
.
setFkConversationId
(
imConversationId
);
imConversationMembers2
.
setFkClientId
(
client2
.
getId
());
imConversationMembersService
.
save
(
imConversationMembers2
);
}
return
ApiResult
.
ok
(
imConversation
);
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
boolean
updateImConversation
(
ImConversation
imConversation
)
throws
Exception
{
public
boolean
updateImConversation
(
ImConversation
imConversation
)
throws
Exception
{
...
...
common/src/main/java/com/wecloud/im/tillo/netty/handler/NettyApiRequest.java
View file @
c9550ee2
...
@@ -3,8 +3,6 @@ package com.wecloud.im.tillo.netty.handler;
...
@@ -3,8 +3,6 @@ package com.wecloud.im.tillo.netty.handler;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.tillo.app_ws.WsHandler
;
import
com.wecloud.im.tillo.app_ws.WsHandler
;
...
@@ -12,12 +10,16 @@ import com.wecloud.im.tillo.app_ws.model.WsConstants;
...
@@ -12,12 +10,16 @@ import com.wecloud.im.tillo.app_ws.model.WsConstants;
import
com.wecloud.im.tillo.app_ws.service.MangerChannelService
;
import
com.wecloud.im.tillo.app_ws.service.MangerChannelService
;
import
com.wecloud.im.tillo.app_ws.utils.FullHttpRequestUtils
;
import
com.wecloud.im.tillo.app_ws.utils.FullHttpRequestUtils
;
import
io.geekidea.springbootplus.config.constant.CommonConstant
;
import
io.geekidea.springbootplus.config.constant.CommonConstant
;
import
io.geekidea.springbootplus.framework.shiro.jwt.JwtToken
;
import
io.geekidea.springbootplus.framework.shiro.service.ShiroLoginService
;
import
io.geekidea.springbootplus.framework.shiro.util.JwtUtil
;
import
io.geekidea.springbootplus.framework.shiro.util.JwtUtil
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
io.netty.handler.codec.http.FullHttpRequest
;
import
io.netty.handler.codec.http.FullHttpRequest
;
import
io.netty.handler.codec.http.HttpResponseStatus
;
import
io.netty.handler.codec.http.HttpResponseStatus
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -36,6 +38,9 @@ import java.util.Map;
...
@@ -36,6 +38,9 @@ import java.util.Map;
@Slf4j
@Slf4j
public
class
NettyApiRequest
{
public
class
NettyApiRequest
{
@Autowired
private
ShiroLoginService
shiroLoginService
;
@Resource
@Resource
private
MangerChannelService
appUserChannelsService
;
private
MangerChannelService
appUserChannelsService
;
...
@@ -99,18 +104,38 @@ public class NettyApiRequest {
...
@@ -99,18 +104,38 @@ public class NettyApiRequest {
String
clientId
=
(
String
)
jsonObject
.
get
(
CommonConstant
.
CLIENT_ID
);
String
clientId
=
(
String
)
jsonObject
.
get
(
CommonConstant
.
CLIENT_ID
);
// 验签token
// 验签token
ImApplication
imApplication
=
imApplicationService
.
getOne
(
new
QueryWrapper
<
ImApplication
>().
lambda
()
// ImApplication imApplication = imApplicationService.getOne(new QueryWrapper<ImApplication>().lambda()
.
eq
(
ImApplication:
:
getAppKey
,
appKey
));
// .eq(ImApplication::getAppKey, appKey));
if
(!
JwtUtil
.
verifyToken
(
token
,
imApplication
.
getAppSecret
()))
{
// if (!JwtUtil.verifyToken(token, imApplication.getAppSecret())) {
log
.
debug
(
"验签token不通过"
);
// log.debug("验签token不通过");
// }
//
// String redisKey = "client:" + appKey + ":" + clientId;
// String redisToken = redisTemplate.opsForValue().get(redisKey);
//
// // 判断token和redis是否一致
// if (!token.equals(redisToken)) {
// log.debug("token和redis不一致");
// }
if
(
StringUtils
.
isBlank
(
token
))
{
throw
new
AuthenticationException
(
"token不能为空"
);
}
}
if
(
JwtUtil
.
isExpired
(
token
))
{
throw
new
AuthenticationException
(
"JWT Token已过期,token:"
+
token
);
}
// 验签token
JwtToken
jwtToken
=
shiroLoginService
.
getTJwtTokenForRedis
(
token
);
String
redisKey
=
"client:"
+
appKey
+
":"
+
clientId
;
if
(
jwtToken
==
null
)
{
String
redisToken
=
redisTemplate
.
opsForValue
().
get
(
redisKey
);
log
.
error
(
"jwtToken == null ,token和redis不一致"
);
return
;
}
// 判断token和redis是否一致
if
((!
jwtToken
.
getClientId
().
equals
(
clientId
))
||
(!
jwtToken
.
getAppKey
().
equals
(
appKey
)))
{
if
(!
token
.
equals
(
redisToken
))
{
log
.
error
(
"clientId appKey 不一致"
);
log
.
debug
(
"token和redis不一致"
)
;
return
;
}
}
// 设置uri前缀
// 设置uri前缀
...
...
framework/src/main/java/io/geekidea/springbootplus/framework/common/api/ApiResult.java
View file @
c9550ee2
...
@@ -50,7 +50,6 @@ public class ApiResult<T> implements Serializable {
...
@@ -50,7 +50,6 @@ public class ApiResult<T> implements Serializable {
* 响应码
* 响应码
*/
*/
private
int
code
;
private
int
code
;
//
// /**
// /**
// * 是否成功
// * 是否成功
// */
// */
...
@@ -66,15 +65,8 @@ public class ApiResult<T> implements Serializable {
...
@@ -66,15 +65,8 @@ public class ApiResult<T> implements Serializable {
*/
*/
private
T
data
;
private
T
data
;
// /**
// * 响应时间
// */
// @JSONField(format = "yyyy-MM-dd HH:mm:ss")
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// private Date time;
public
ApiResult
()
{
public
ApiResult
()
{
// time = new Date();
}
}
public
static
ApiResult
<
Boolean
>
result
(
boolean
flag
)
{
public
static
ApiResult
<
Boolean
>
result
(
boolean
flag
)
{
...
...
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