publish 2.0.0.rc13
This commit is contained in:
@@ -8,7 +8,7 @@ import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.service.TieshengMessageSender;
|
||||
import com.tiesheng.message.service.TsMessageSender;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,7 +30,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "tiesheng.aliyun")
|
||||
public class AliyunSmsSender implements TieshengMessageSender {
|
||||
public class AliyunSmsSender implements TsMessageSender {
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.tiesheng.message.pojos.MessageReqResp;
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
public interface TieshengMessageSender {
|
||||
public interface TsMessageSender {
|
||||
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.tiesheng.message.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.pojos.UserChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@Service
|
||||
public class TsMessageService {
|
||||
|
||||
@Autowired
|
||||
List<TsMessageSender> messageSenderList;
|
||||
|
||||
/**
|
||||
* 发送所有消息
|
||||
*
|
||||
* @param userIds
|
||||
* @param body
|
||||
*/
|
||||
public void all(List<String> userIds, JSONObject body) {
|
||||
messageSenderList.stream().filter(TsMessageSender::support)
|
||||
.forEach(sender -> {
|
||||
for (String user : userIds) {
|
||||
sender.send(user, body);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param channels
|
||||
* @param body
|
||||
* @param channels 消息通道,如果为all时,表示发送全部通道
|
||||
*/
|
||||
public void multiple(List<UserChannel> channels, JSONObject body) {
|
||||
if (ArrayUtil.isEmpty(channels)) {
|
||||
return;
|
||||
}
|
||||
|
||||
messageSenderList.stream().filter(TsMessageSender::support)
|
||||
.forEach(sender -> channels.stream().filter(it -> Objects.equals(it.getChannel(), sender.getChannel()))
|
||||
.forEach(it -> sender.send(it.getUser(), body)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param userChannel
|
||||
* @param body
|
||||
*/
|
||||
public MessageReqResp send(UserChannel userChannel, JSONObject body) {
|
||||
|
||||
if (StrUtil.isEmpty(userChannel.getUser()) || StrUtil.isEmpty(userChannel.getChannel())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TsMessageSender messageSender = CollUtil.findOne(messageSenderList,
|
||||
sender -> Objects.equals(sender.getChannel(), userChannel.getChannel()) && sender.support());
|
||||
if (messageSender != null) {
|
||||
messageSender.send(userChannel.getUser(), body);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user