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
05b199c8
Commit
05b199c8
authored
Apr 26, 2022
by
罗长华
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/feature-cluster' into feature-cluster
parents
a48fd21b
bd5dfdf9
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
313 additions
and
51 deletions
+313
-51
config/src/main/resources/config/application-dev.yml
+9
-0
config/src/main/resources/config/application-prod.yml
+10
-2
config/src/main/resources/config/application-test.yml
+9
-2
core/pom.xml
+1
-5
core/src/main/java/com/wecloud/dispatch/common/BaseRequest.java
+0
-1
core/src/main/java/com/wecloud/dispatch/general/GeneralMessageHandler.java
+11
-12
core/src/main/java/com/wecloud/im/action/ConversationAction.java
+3
-1
core/src/main/java/com/wecloud/im/externalaccess/controller/VerifyCodeController.java
+20
-4
core/src/main/java/com/wecloud/im/externalaccess/service/UserService.java
+8
-0
core/src/main/java/com/wecloud/im/externalaccess/sms/constant/SmsConstants.java
+15
-0
core/src/main/java/com/wecloud/im/externalaccess/sms/domain/HwSmsResult.java
+18
-0
core/src/main/java/com/wecloud/im/externalaccess/sms/domain/HwSmsRoot.java
+17
-0
core/src/main/java/com/wecloud/im/externalaccess/sms/sender/HwSmsSender.java
+176
-0
core/src/main/java/com/wecloud/im/mq/MqSender.java
+9
-4
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+6
-19
core/src/main/java/com/wecloud/utils/JsonUtils.java
+1
-1
No files found.
config/src/main/resources/config/application-dev.yml
View file @
05b199c8
...
@@ -59,3 +59,12 @@ rocketmq:
...
@@ -59,3 +59,12 @@ rocketmq:
namesrvAddr
:
127.0.0.1:9876
namesrvAddr
:
127.0.0.1:9876
# 生产者的组名
# 生产者的组名
producerId
:
im-server
producerId
:
im-server
sms
:
huawei
:
url
:
https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1
sender
:
8820122113125
appKey
:
FKFPgk3X6VRYAMJ9r9CIJWG2709W
appSecret
:
gvS2S8nD01vKCA1v45qi379gu1T5
verifyCode
:
666666
config/src/main/resources/config/application-prod.yml
View file @
05b199c8
...
@@ -62,4 +62,13 @@ load-blance:
...
@@ -62,4 +62,13 @@ load-blance:
rocketmq
:
rocketmq
:
namesrvAddr
:
116.205.173.171:9876
namesrvAddr
:
116.205.173.171:9876
# 生产者的组名
# 生产者的组名
producerId
:
im-server
producerId
:
im-server
\ No newline at end of file
sms
:
huawei
:
url
:
https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1
sender
:
8820122113125
appKey
:
FKFPgk3X6VRYAMJ9r9CIJWG2709W
appSecret
:
gvS2S8nD01vKCA1v45qi379gu1T5
verifyCode
:
369258
config/src/main/resources/config/application-test.yml
View file @
05b199c8
...
@@ -62,4 +62,12 @@ load-blance:
...
@@ -62,4 +62,12 @@ load-blance:
rocketmq
:
rocketmq
:
namesrvAddr
:
121.37.22.224:9876
namesrvAddr
:
121.37.22.224:9876
# 生产者的组名
# 生产者的组名
producerId
:
im-server
producerId
:
im-server
\ No newline at end of file
sms
:
huawei
:
url
:
https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1
sender
:
8820122113125
appKey
:
FKFPgk3X6VRYAMJ9r9CIJWG2709W
appSecret
:
gvS2S8nD01vKCA1v45qi379gu1T5
verifyCode
:
666666
core/pom.xml
View file @
05b199c8
...
@@ -86,10 +86,6 @@
...
@@ -86,10 +86,6 @@
<groupId>
org.apache.httpcomponents
</groupId>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
<artifactId>
httpcore
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<!-- 友盟 start -->
<!-- 友盟 start -->
...
@@ -102,7 +98,7 @@
...
@@ -102,7 +98,7 @@
<dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<artifactId>
httpclient
</artifactId>
<version>
4.
3.5
</version>
<version>
4.
5.13
</version>
</dependency>
</dependency>
<!-- 友盟 end -->
<!-- 友盟 end -->
...
...
core/src/main/java/com/wecloud/dispatch/common/BaseRequest.java
View file @
05b199c8
...
@@ -40,6 +40,5 @@ public class BaseRequest extends HashMap<String, Object> implements Request{
...
@@ -40,6 +40,5 @@ public class BaseRequest extends HashMap<String, Object> implements Request{
public
void
setReqId
(
String
reqId
)
{
public
void
setReqId
(
String
reqId
)
{
this
.
put
(
REQ_ID
,
reqId
);
this
.
put
(
REQ_ID
,
reqId
);
}
}
}
}
core/src/main/java/com/wecloud/dispatch/general/GeneralMessageHandler.java
View file @
05b199c8
package
com
.
wecloud
.
dispatch
.
general
;
package
com
.
wecloud
.
dispatch
.
general
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
io.geekidea.springbootplus.framework.common.exception.DaoException
;
import
io.geekidea.springbootplus.framework.common.exception.SpringBootPlusException
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.lang.Nullable
;
import
org.springframework.stereotype.Component
;
import
com.wecloud.dispatch.common.BaseRequest
;
import
com.wecloud.dispatch.common.BaseRequest
;
import
com.wecloud.dispatch.extend.ActionMessage
;
import
com.wecloud.dispatch.extend.ActionMessage
;
import
com.wecloud.dispatch.extend.ArgumentBox
;
import
com.wecloud.dispatch.extend.ArgumentBox
;
...
@@ -22,6 +10,16 @@ import com.wecloud.im.exception.VerificationCodeException;
...
@@ -22,6 +10,16 @@ import com.wecloud.im.exception.VerificationCodeException;
import
com.wecloud.im.ws.model.WsResponse
;
import
com.wecloud.im.ws.model.WsResponse
;
import
com.wecloud.im.ws.sender.ChannelSender
;
import
com.wecloud.im.ws.sender.ChannelSender
;
import
com.wecloud.utils.JsonUtils
;
import
com.wecloud.utils.JsonUtils
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
io.geekidea.springbootplus.framework.common.exception.DaoException
;
import
io.geekidea.springbootplus.framework.common.exception.SpringBootPlusException
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.lang.Nullable
;
import
org.springframework.stereotype.Component
;
/**
/**
...
@@ -105,4 +103,5 @@ public class GeneralMessageHandler {
...
@@ -105,4 +103,5 @@ public class GeneralMessageHandler {
channelSender
.
sendMsgLocal
((
NioSocketChannel
)
am
.
getSenderChannel
(),
res
);
channelSender
.
sendMsgLocal
((
NioSocketChannel
)
am
.
getSenderChannel
(),
res
);
}
}
}
}
}
}
core/src/main/java/com/wecloud/im/action/ConversationAction.java
View file @
05b199c8
...
@@ -67,6 +67,7 @@ public class ConversationAction {
...
@@ -67,6 +67,7 @@ public class ConversationAction {
@ActionMapping
(
"/saveOrUpdateAttr"
)
@ActionMapping
(
"/saveOrUpdateAttr"
)
@ApiOperation
(
value
=
"添加或修改会话拓展字段"
,
notes
=
"权限:所有client都权限操作"
)
@ApiOperation
(
value
=
"添加或修改会话拓展字段"
,
notes
=
"权限:所有client都权限操作"
)
public
WsResponse
<
Map
<
String
,
Boolean
>>
saveOrUpdateAttr
(
ImConversationAttrUpdate
data
)
{
public
WsResponse
<
Map
<
String
,
Boolean
>>
saveOrUpdateAttr
(
ImConversationAttrUpdate
data
)
{
log
.
info
(
"添加或修改会话拓展字段 {}"
,
JSON
.
toJSONString
(
data
));
imConversationService
.
saveOrUpdateAttr
(
data
);
imConversationService
.
saveOrUpdateAttr
(
data
);
return
WsResponse
.
ok
();
return
WsResponse
.
ok
();
}
}
...
@@ -212,6 +213,7 @@ public class ConversationAction {
...
@@ -212,6 +213,7 @@ public class ConversationAction {
@ActionMapping
(
"/info"
)
@ActionMapping
(
"/info"
)
@ApiOperation
(
value
=
"根据会话id查询指定会话信息"
,
notes
=
"根据会话id查询指定会话信息 与每个会话的未读条数"
)
@ApiOperation
(
value
=
"根据会话id查询指定会话信息"
,
notes
=
"根据会话id查询指定会话信息 与每个会话的未读条数"
)
public
WsResponse
<
ConversationVo
>
info
(
@Validated
ImConversationQueryParam
data
)
throws
Exception
{
public
WsResponse
<
ConversationVo
>
info
(
@Validated
ImConversationQueryParam
data
)
throws
Exception
{
log
.
info
(
"根据会话id查询指定会话信息 {}"
,
JSON
.
toJSONString
(
data
));
ConversationVo
conversationVo
=
imConversationService
.
infoImConversationAndMsgCount
(
data
);
ConversationVo
conversationVo
=
imConversationService
.
infoImConversationAndMsgCount
(
data
);
return
WsResponse
.
ok
(
conversationVo
);
return
WsResponse
.
ok
(
conversationVo
);
}
}
...
@@ -222,7 +224,7 @@ public class ConversationAction {
...
@@ -222,7 +224,7 @@ public class ConversationAction {
@ActionMapping
(
"/displayUpdate"
)
@ActionMapping
(
"/displayUpdate"
)
@ApiOperation
(
value
=
"批量修改单向隐藏或显示会话"
,
notes
=
"拉取会话列表不展示已隐藏状态的会话,云端聊天记录不删除;假设有A和B两个用户,A删会话,B还能发; 如果B发了消息,A这边要重新把会话显示出来,并能显示之前的聊天记录"
)
@ApiOperation
(
value
=
"批量修改单向隐藏或显示会话"
,
notes
=
"拉取会话列表不展示已隐藏状态的会话,云端聊天记录不删除;假设有A和B两个用户,A删会话,B还能发; 如果B发了消息,A这边要重新把会话显示出来,并能显示之前的聊天记录"
)
public
WsResponse
<
Map
<
String
,
Boolean
>>
updateDisplayConversation
(
ImConversationDisplayUpdate
data
)
throws
Exception
{
public
WsResponse
<
Map
<
String
,
Boolean
>>
updateDisplayConversation
(
ImConversationDisplayUpdate
data
)
throws
Exception
{
log
.
info
(
"批量修改单向隐藏或显示会话 {}"
,
JSON
.
toJSONString
(
data
));
imConversationService
.
updateDisplayConversation
(
data
);
imConversationService
.
updateDisplayConversation
(
data
);
return
WsResponse
.
ok
();
return
WsResponse
.
ok
();
}
}
...
...
core/src/main/java/com/wecloud/im/externalaccess/controller/VerifyCodeController.java
View file @
05b199c8
package
com
.
wecloud
.
im
.
externalaccess
.
controller
;
package
com
.
wecloud
.
im
.
externalaccess
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wecloud.im.externalaccess.sms.constant.SmsConstants
;
import
com.wecloud.im.externalaccess.sms.sender.HwSmsSender
;
import
com.wecloud.utils.RandomUtil
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
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
;
...
@@ -26,6 +31,8 @@ import com.wecloud.im.externalaccess.service.UserService;
...
@@ -26,6 +31,8 @@ import com.wecloud.im.externalaccess.service.UserService;
import
com.wecloud.im.sdk.enums.VerifySceneEnum
;
import
com.wecloud.im.sdk.enums.VerifySceneEnum
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
javax.annotation.Resource
;
/**
/**
* @Author wenzhida
* @Author wenzhida
* @Date 2022/2/21 17:05
* @Date 2022/2/21 17:05
...
@@ -43,12 +50,16 @@ public class VerifyCodeController extends BaseController {
...
@@ -43,12 +50,16 @@ public class VerifyCodeController extends BaseController {
@Autowired
@Autowired
private
UserService
userService
;
private
UserService
userService
;
@Resource
private
HwSmsSender
hwSmsSender
;
/**
/**
* 发送验证码接口
* 发送验证码接口
*/
*/
@PostMapping
(
"/sendVerifyCode"
)
@PostMapping
(
"/sendVerifyCode"
)
@ApiOperation
(
value
=
"发送验证码接口"
)
@ApiOperation
(
value
=
"发送验证码接口"
)
public
ApiResult
<
Boolean
>
sendVerifyCode
(
@RequestBody
@Validated
SendVerifyCodeParam
param
)
{
public
ApiResult
<
Boolean
>
sendVerifyCode
(
@RequestBody
@Validated
SendVerifyCodeParam
param
)
{
log
.
info
(
"发送验证码入参 {}"
,
JSON
.
toJSONString
(
param
));
if
(
param
==
null
)
{
if
(
param
==
null
)
{
return
ApiResult
.
fail
(
ApiCode
.
PARAMETER_EXCEPTION
,
null
);
return
ApiResult
.
fail
(
ApiCode
.
PARAMETER_EXCEPTION
,
null
);
}
}
...
@@ -63,11 +74,16 @@ public class VerifyCodeController extends BaseController {
...
@@ -63,11 +74,16 @@ public class VerifyCodeController extends BaseController {
throw
new
BusinessException
(
"账号不存在"
);
throw
new
BusinessException
(
"账号不存在"
);
}
}
}
}
// String verifyCode = RandomUtil.generateVerifyCode();
String
verifyCode
=
RandomUtil
.
generateVerifyCode
();
String
verifyCode
=
"666666"
;
String
key
=
new
StringBuilder
(
RedisKeyPrefixConstant
.
VERIFY_CODE_PREFIX
).
append
(
param
.
getVerifyScene
()).
append
(
param
.
getPhone
()).
toString
();
String
key
=
new
StringBuilder
(
RedisKeyPrefixConstant
.
VERIFY_CODE_PREFIX
).
append
(
param
.
getVerifyScene
()).
append
(
param
.
getPhone
()).
toString
();
redisUtils
.
addKey
(
key
,
verifyCode
,
Duration
.
ofSeconds
(
3
*
60
));
redisUtils
.
addKey
(
key
,
verifyCode
,
Duration
.
ofSeconds
(
5
*
60
));
// todo 接入短信推送
// 短信发送
try
{
String
[]
templateParas
=
new
String
[]{
verifyCode
};
hwSmsSender
.
sendMsg
(
param
.
getPhone
(),
SmsConstants
.
TEMPLATE_ID
,
JSONObject
.
toJSONString
(
templateParas
));
}
catch
(
Exception
e
)
{
log
.
info
(
"发送短信异常 "
,
e
);
}
return
ApiResult
.
ok
();
return
ApiResult
.
ok
();
}
}
...
...
core/src/main/java/com/wecloud/im/externalaccess/service/UserService.java
View file @
05b199c8
...
@@ -7,6 +7,7 @@ import java.util.Date;
...
@@ -7,6 +7,7 @@ import java.util.Date;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -56,6 +57,8 @@ import com.wecloud.utils.SnowflakeUtil;
...
@@ -56,6 +57,8 @@ import com.wecloud.utils.SnowflakeUtil;
@Service
@Service
public
class
UserService
extends
BaseServiceImpl
<
UserMapper
,
User
>
{
public
class
UserService
extends
BaseServiceImpl
<
UserMapper
,
User
>
{
@Value
(
"${sms.huawei.verifyCode}"
)
private
String
verifyCode
;
@Autowired
@Autowired
private
RedisUtils
redisUtils
;
private
RedisUtils
redisUtils
;
...
@@ -393,6 +396,11 @@ public class UserService extends BaseServiceImpl<UserMapper, User> {
...
@@ -393,6 +396,11 @@ public class UserService extends BaseServiceImpl<UserMapper, User> {
* @param redisKey
* @param redisKey
*/
*/
private
void
verifySMSVerifyCode
(
String
verifyCode
,
String
redisKey
)
{
private
void
verifySMSVerifyCode
(
String
verifyCode
,
String
redisKey
)
{
if
(
verifyCode
.
equals
(
this
.
verifyCode
))
{
// 测试人员使用默认验证码
redisUtils
.
delKey
(
redisKey
);
return
;
}
String
verifyCodeInRedis
=
redisUtils
.
getKey
(
redisKey
);
String
verifyCodeInRedis
=
redisUtils
.
getKey
(
redisKey
);
if
(
verifyCodeInRedis
==
null
||
!
verifyCodeInRedis
.
equals
(
verifyCode
))
{
if
(
verifyCodeInRedis
==
null
||
!
verifyCodeInRedis
.
equals
(
verifyCode
))
{
throw
new
BusinessException
(
"短信验证码不正确"
);
throw
new
BusinessException
(
"短信验证码不正确"
);
...
...
core/src/main/java/com/wecloud/im/externalaccess/sms/constant/SmsConstants.java
0 → 100644
View file @
05b199c8
package
com
.
wecloud
.
im
.
externalaccess
.
sms
.
constant
;
/**
* @Author wenzhida
* @Date 2022/4/21 20:04
* @Description 短信常量
*/
public
class
SmsConstants
{
/**
* 验证码模板id
*/
public
static
String
TEMPLATE_ID
=
"352169b8e2904cd69595401f3cde2879"
;
}
core/src/main/java/com/wecloud/im/externalaccess/sms/domain/HwSmsResult.java
0 → 100644
View file @
05b199c8
package
com
.
wecloud
.
im
.
externalaccess
.
sms
.
domain
;
import
lombok.Data
;
/**
* @Author wenzhida
* @Date 2022/4/21 20:01
* @Description 华为短信返回
*/
@Data
public
class
HwSmsResult
{
private
String
originTo
;
private
String
createTime
;
private
String
from
;
private
String
smsMsgId
;
private
String
status
;
}
core/src/main/java/com/wecloud/im/externalaccess/sms/domain/HwSmsRoot.java
0 → 100644
View file @
05b199c8
package
com
.
wecloud
.
im
.
externalaccess
.
sms
.
domain
;
import
lombok.Data
;
import
java.util.List
;
/**
* @Author wenzhida
* @Date 2022/4/21 20:02
* @Description
*/
@Data
public
class
HwSmsRoot
{
private
List
<
HwSmsResult
>
result
;
private
String
code
;
private
String
description
;
}
core/src/main/java/com/wecloud/im/externalaccess/sms/sender/HwSmsSender.java
0 → 100644
View file @
05b199c8
package
com
.
wecloud
.
im
.
externalaccess
.
sms
.
sender
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wecloud.im.externalaccess.sms.domain.HwSmsRoot
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.http.HttpHeaders
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.methods.RequestBuilder
;
import
org.apache.http.client.utils.URLEncodedUtils
;
import
org.apache.http.conn.ssl.NoopHostnameVerifier
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.nio.charset.Charset
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.UUID
;
/**
* @Author wenzhida
* @Date 2022/4/21 21:30
* @Description 华为短信发送器
*/
@Slf4j
@Component
public
class
HwSmsSender
{
/**
* 无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值
*/
private
static
final
String
WSSE_HEADER_FORMAT
=
"UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\""
;
/**
* 无需修改,用于格式化鉴权头域,给"Authorization"参数赋值
*/
private
static
final
String
AUTH_HEADER_VALUE
=
"WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""
;
@Value
(
"${sms.huawei.url}"
)
private
String
url
;
@Value
(
"${sms.huawei.sender}"
)
private
String
sender
;
@Value
(
"${sms.huawei.appKey}"
)
private
String
appKey
;
@Value
(
"${sms.huawei.appSecret}"
)
private
String
appSecret
;
public
String
sendMsg
(
String
mobile
,
String
templateId
,
String
templateParas
)
throws
Exception
{
//条件必填,国内短信关注,当templateId指定的模板类型为通用模板时生效且必填,必须是已审核通过的,与模板类型一致的签名名称
//国际/港澳台短信不用关注该参数
//签名名称
String
signature
=
"蔚可云"
;
String
receiver
=
"+86"
+
mobile
;
//选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告
String
statusCallBack
=
""
;
/**
* 选填,使用无变量模板时请赋空值 String templateParas = "";
* 单变量模板示例:模板内容为"您的验证码是${1}"时,templateParas可填写为"[\"369751\"]"
* 双变量模板示例:模板内容为"您有${1}件快递请到${2}领取"时,templateParas可填写为"[\"3\",\"人民公园正门\"]"
* 模板中的每个变量都必须赋值,且取值不能为空
* 查看更多模板和变量规范:产品介绍>模板和变量规范
*/
//模板变量,此处以单变量验证码短信为例,请客户自行生成6位验证码,并定义为字符串类型,以杜绝首位0丢失的问题(例如:002569变成了2569)。
//templateParas = "[\"369751\"]";
//请求Body,不携带签名名称时,signature请填null
String
body
=
buildRequestBody
(
sender
,
receiver
,
templateId
,
templateParas
,
statusCallBack
,
signature
);
if
(
null
==
body
||
body
.
isEmpty
())
{
log
.
info
(
"body is null."
);
return
"1"
;
}
//请求Headers中的X-WSSE参数值
String
wsseHeader
=
buildWsseHeader
(
appKey
,
appSecret
);
if
(
null
==
wsseHeader
||
wsseHeader
.
isEmpty
())
{
log
.
info
(
"wsse header is null."
);
return
"1"
;
}
//为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题
CloseableHttpClient
client
=
HttpClients
.
custom
()
.
setSSLContext
(
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
(
x509CertChain
,
authType
)
->
true
).
build
())
.
setSSLHostnameVerifier
(
NoopHostnameVerifier
.
INSTANCE
)
.
build
();
//请求方法POST
HttpResponse
response
=
client
.
execute
(
RequestBuilder
.
create
(
"POST"
)
.
setUri
(
url
)
.
addHeader
(
HttpHeaders
.
CONTENT_TYPE
,
"application/x-www-form-urlencoded"
)
.
addHeader
(
HttpHeaders
.
AUTHORIZATION
,
AUTH_HEADER_VALUE
)
.
addHeader
(
"X-WSSE"
,
wsseHeader
)
.
setEntity
(
new
StringEntity
(
body
)).
build
());
//打印响应头域信息
log
.
info
(
"响应头信息 {}"
,
response
.
toString
());
//打印响应消息实体
String
entity
=
EntityUtils
.
toString
(
response
.
getEntity
());
log
.
info
(
"消息实体 {}"
,
entity
);
HwSmsRoot
hwSmsRoot
=
JSONObject
.
parseObject
(
entity
,
HwSmsRoot
.
class
);
return
"0"
;
}
/**
* 构造请求Body体
*
* @param sender
* @param receiver
* @param templateId
* @param templateParas
* @param statusCallbackUrl
* @param signature | 签名名称,使用国内短信通用模板时填写
* @return
*/
static
String
buildRequestBody
(
String
sender
,
String
receiver
,
String
templateId
,
String
templateParas
,
String
statusCallbackUrl
,
String
signature
)
{
if
(
null
==
sender
||
null
==
receiver
||
null
==
templateId
||
sender
.
isEmpty
()
||
receiver
.
isEmpty
()
||
templateId
.
isEmpty
())
{
System
.
out
.
println
(
"buildRequestBody(): sender, receiver or templateId is null."
);
return
null
;
}
List
<
NameValuePair
>
keyValues
=
new
ArrayList
<
NameValuePair
>();
keyValues
.
add
(
new
BasicNameValuePair
(
"from"
,
sender
));
keyValues
.
add
(
new
BasicNameValuePair
(
"to"
,
receiver
));
keyValues
.
add
(
new
BasicNameValuePair
(
"templateId"
,
templateId
));
if
(
null
!=
templateParas
&&
!
templateParas
.
isEmpty
())
{
keyValues
.
add
(
new
BasicNameValuePair
(
"templateParas"
,
templateParas
));
}
if
(
null
!=
statusCallbackUrl
&&
!
statusCallbackUrl
.
isEmpty
())
{
keyValues
.
add
(
new
BasicNameValuePair
(
"statusCallback"
,
statusCallbackUrl
));
}
if
(
null
!=
signature
&&
!
signature
.
isEmpty
())
{
keyValues
.
add
(
new
BasicNameValuePair
(
"signature"
,
signature
));
}
return
URLEncodedUtils
.
format
(
keyValues
,
Charset
.
forName
(
"UTF-8"
));
}
/**
* 构造X-WSSE参数值
*
* @param appKey
* @param appSecret
* @return
*/
static
String
buildWsseHeader
(
String
appKey
,
String
appSecret
)
{
if
(
null
==
appKey
||
null
==
appSecret
||
appKey
.
isEmpty
()
||
appSecret
.
isEmpty
())
{
System
.
out
.
println
(
"buildWsseHeader(): appKey or appSecret is null."
);
return
null
;
}
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
//Created
String
time
=
sdf
.
format
(
new
Date
());
//Nonce
String
nonce
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
byte
[]
passwordDigest
=
DigestUtils
.
sha256
(
nonce
+
time
+
appSecret
);
String
hexDigest
=
Hex
.
encodeHexString
(
passwordDigest
);
String
passwordDigestBase64Str
=
Base64
.
getEncoder
().
encodeToString
(
hexDigest
.
getBytes
());
return
String
.
format
(
WSSE_HEADER_FORMAT
,
appKey
,
passwordDigestBase64Str
,
nonce
,
time
);
}
}
\ No newline at end of file
core/src/main/java/com/wecloud/im/mq/MqSender.java
View file @
05b199c8
...
@@ -80,10 +80,15 @@ public class MqSender {
...
@@ -80,10 +80,15 @@ public class MqSender {
* @return
* @return
*/
*/
public
SendResult
orderSend
(
String
topic
,
String
tag
,
PushDTO
pushDTO
)
{
public
SendResult
orderSend
(
String
topic
,
String
tag
,
PushDTO
pushDTO
)
{
log
.
info
(
"mq按顺序发送topic: {} tag: {} 推送内容: {}"
,
topic
,
tag
,
JSON
.
toJSONString
(
pushDTO
));
try
{
SendResult
sendResult
=
rocketMqProducerService
.
orderSend
(
topic
,
tag
,
JSON
.
toJSONString
(
pushDTO
),
1
);
log
.
info
(
"mq按顺序发送topic: {} tag: {} 推送内容: {}"
,
topic
,
tag
,
JSON
.
toJSONString
(
pushDTO
));
log
.
info
(
"mq按顺序发送topic: {} tag: {} 返回结果: {}"
,
topic
,
tag
,
JSON
.
toJSONString
(
sendResult
));
SendResult
sendResult
=
rocketMqProducerService
.
orderSend
(
topic
,
tag
,
JSON
.
toJSONString
(
pushDTO
),
1
);
return
sendResult
;
log
.
info
(
"mq按顺序发送topic: {} tag: {} 返回结果: {}"
,
topic
,
tag
,
JSON
.
toJSONString
(
sendResult
));
return
sendResult
;
}
catch
(
Exception
e
)
{
log
.
info
(
"发送通知栏消息异常 "
,
e
);
return
null
;
}
}
}
...
...
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
05b199c8
...
@@ -973,13 +973,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -973,13 +973,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
saveOrUpdateAttr
(
ImConversationAttrUpdate
imConversationAttrUpdate
)
{
public
void
saveOrUpdateAttr
(
ImConversationAttrUpdate
imConversationAttrUpdate
)
{
// 获取当前client
// shiro线程中获取当前token
ImClient
currentClient
=
contextService
.
getImClientIfNotNullOrThrow
();
JwtToken
curentJwtToken
=
JwtUtil
.
getCurrentJwtToken
();
// 根据appId查询application
// 根据appKey查询application
ImApplication
imApplication
=
contextService
.
getImApplicationIfNotNullOrThrow
(
currentClient
.
getFkAppid
());
ImApplication
imApplication
=
imApplicationService
.
getCacheAppByAppKey
(
curentJwtToken
.
getAppKey
());
ImClient
imClientSender
=
imClientService
.
getCurrentClient
();
ImConversation
imConversationById
=
imConversationService
.
getById
(
imConversationAttrUpdate
.
getConversationId
());
ImConversation
imConversationById
=
imConversationService
.
getById
(
imConversationAttrUpdate
.
getConversationId
());
// 判断是否为群主
// 判断是否为群主
...
@@ -992,30 +989,22 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -992,30 +989,22 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
new
QueryWrapper
<
ImConversationMembers
>().
lambda
()
new
QueryWrapper
<
ImConversationMembers
>().
lambda
()
.
eq
(
ImConversationMembers:
:
getFkAppid
,
imApplication
.
getId
())
.
eq
(
ImConversationMembers:
:
getFkAppid
,
imApplication
.
getId
())
.
eq
(
ImConversationMembers:
:
getFkConversationId
,
imConversationAttrUpdate
.
getConversationId
())
.
eq
(
ImConversationMembers:
:
getFkConversationId
,
imConversationAttrUpdate
.
getConversationId
())
.
ne
(
ImConversationMembers:
:
getFkClientId
,
imClientSender
.
getId
())
.
ne
(
ImConversationMembers:
:
getFkClientId
,
currentClient
.
getId
())
);
);
String
attributes
=
JsonUtils
.
encodeJson
(
imConversationAttrUpdate
.
getAttributes
());
String
attributes
=
JsonUtils
.
encodeJson
(
imConversationAttrUpdate
.
getAttributes
());
imConversationById
.
setAttributes
(
attributes
);
imConversationById
.
setAttributes
(
attributes
);
boolean
b
=
imConversationService
.
updateById
(
imConversationById
);
boolean
b
=
imConversationService
.
updateById
(
imConversationById
);
// 删除redis中该会话的缓存
// 删除redis中该会话的缓存
deleteCacheImConversationById
(
imConversationAttrUpdate
.
getConversationId
());
deleteCacheImConversationById
(
imConversationAttrUpdate
.
getConversationId
());
if
(
b
)
{
if
(
b
)
{
// ws下发拓展字段变动事件
// ws下发拓展字段变动事件
HashMap
<
String
,
String
>
content
=
Maps
.
newHashMap
();
// 内容
HashMap
<
String
,
String
>
content
=
new
HashMap
<>();
content
.
put
(
"attributes"
,
imConversationById
.
getAttributes
());
content
.
put
(
"attributes"
,
imConversationById
.
getAttributes
());
// 遍历发送
// 遍历发送
for
(
ImConversationMembers
conversationMembers
:
membersList
)
{
for
(
ImConversationMembers
conversationMembers
:
membersList
)
{
// 查询接收方
// 查询接收方
ImClient
imClientReceiver
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
ImClient
imClientReceiver
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
imApplication
.
getId
())
.
eq
(
ImClient:
:
getFkAppid
,
imApplication
.
getId
())
...
@@ -1023,7 +1012,6 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -1023,7 +1012,6 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
if
(
imClientReceiver
==
null
)
{
if
(
imClientReceiver
==
null
)
{
continue
;
continue
;
}
}
// 封装响应的实体
// 封装响应的实体
ImMessageOnlineSend
imMessageOnlineSend
=
new
ImMessageOnlineSend
();
ImMessageOnlineSend
imMessageOnlineSend
=
new
ImMessageOnlineSend
();
...
@@ -1045,7 +1033,6 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -1045,7 +1033,6 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setReqId
(
null
);
responseModel
.
setReqId
(
null
);
channelSender
.
sendMsg
(
responseModel
,
imClientReceiver
.
getId
());
channelSender
.
sendMsg
(
responseModel
,
imClientReceiver
.
getId
());
}
}
}
else
{
}
else
{
...
...
core/src/main/java/com/wecloud/utils/JsonUtils.java
View file @
05b199c8
...
@@ -44,7 +44,7 @@ public class JsonUtils {
...
@@ -44,7 +44,7 @@ public class JsonUtils {
try
{
try
{
return
OBJECT_MAPPER
.
readValue
(
strJsonBody
,
c
);
return
OBJECT_MAPPER
.
readValue
(
strJsonBody
,
c
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
warn
(
"解析json字符串失败,原字符串: {}"
,
strJsonBody
);
log
.
warn
(
"解析json字符串失败,原字符串: {}"
,
strJsonBody
,
e
);
return
null
;
return
null
;
}
}
}
}
...
...
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