|
|
@ -1,27 +1,19 @@ |
|
|
|
package com.cloud.kicc.commonbiz.service.impl; |
|
|
|
package com.cloud.kicc.commonbiz.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil; |
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil; |
|
|
|
import cn.hutool.core.util.BooleanUtil; |
|
|
|
import cn.hutool.core.util.BooleanUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.extra.servlet.ServletUtil; |
|
|
|
import cn.hutool.extra.servlet.ServletUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.cloud.kicc.common.core.api.R; |
|
|
|
|
|
|
|
import com.cloud.kicc.common.core.constant.SecurityConstants; |
|
|
|
|
|
|
|
import com.cloud.kicc.common.core.exception.CheckedException; |
|
|
|
import com.cloud.kicc.common.core.exception.CheckedException; |
|
|
|
import com.cloud.kicc.commonbiz.api.entity.*; |
|
|
|
import com.cloud.kicc.commonbiz.api.entity.*; |
|
|
|
import com.cloud.kicc.commonbiz.mapper.PushApplicationMapper; |
|
|
|
import com.cloud.kicc.commonbiz.mapper.PushApplicationMapper; |
|
|
|
import com.cloud.kicc.commonbiz.service.*; |
|
|
|
import com.cloud.kicc.commonbiz.service.*; |
|
|
|
import com.cloud.kicc.commonbiz.util.PushClientUtil; |
|
|
|
import com.cloud.kicc.commonbiz.util.PushClientUtil; |
|
|
|
import com.cloud.kicc.system.api.entity.User; |
|
|
|
|
|
|
|
import com.cloud.kicc.system.api.feign.RemoteUserService; |
|
|
|
|
|
|
|
import io.lettuce.core.api.push.PushMessage; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import okhttp3.OkHttpClient; |
|
|
|
import okhttp3.OkHttpClient; |
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
@ -48,97 +40,102 @@ import java.util.stream.Collectors; |
|
|
|
public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMapper, PushApplication> implements IPushApplicationService { |
|
|
|
public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMapper, PushApplication> implements IPushApplicationService { |
|
|
|
|
|
|
|
|
|
|
|
private final OkHttpClient okHttpClient; |
|
|
|
private final OkHttpClient okHttpClient; |
|
|
|
//private final IPushUserManageService iPushUserManageService;
|
|
|
|
private final IPushConcernFanService iPushConcernFanService; |
|
|
|
//private final IPushMessageService iPushMessageService;
|
|
|
|
private final IPushBlacklistService iPushBlacklistService; |
|
|
|
private final RemoteUserService remoteUserService; |
|
|
|
private final IPushChatMessageService iPushChatMessageService; |
|
|
|
//private final IPushCustomTypeService iPushCustomTypeService;
|
|
|
|
private final IPushConcernFanTypeService iPushConcernFanTypeService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void messageSend(PushChatMessage pushChatMessage) { |
|
|
|
public void enterpriseMessageSend(PushChatMessage pushChatMessage) { |
|
|
|
|
|
|
|
|
|
|
|
/*if (StrUtil.isBlank(pushChatMessage.getPushUserId()) || StrUtil.isBlank(pushChatMessage.getMessageSecret())) { |
|
|
|
if (StrUtil.isBlank(pushChatMessage.getUserId()) || StrUtil.isBlank(pushChatMessage.getMessageSecret())) { |
|
|
|
throw new CheckedException("当前发送方用户ID与推送应用密钥必填!"); |
|
|
|
throw new CheckedException("当前推送方用户ID与推送应用密钥必填!"); |
|
|
|
}*/ |
|
|
|
|
|
|
|
R<User> result = remoteUserService.selectByUserId(pushChatMessage.getPushTypeId(), SecurityConstants.FROM_IN); |
|
|
|
|
|
|
|
if (result == null || result.getData() == null) { |
|
|
|
|
|
|
|
throw new CheckedException("用户不存在"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// 第三方发送前较验数据
|
|
|
|
|
|
|
|
if (result.getData().getUserType().equals("9")) { |
|
|
|
|
|
|
|
PushApplication pushApplication = baseMapper.selectOne(Wrappers.<PushApplication>lambdaQuery() |
|
|
|
PushApplication pushApplication = baseMapper.selectOne(Wrappers.<PushApplication>lambdaQuery() |
|
|
|
.eq(PushApplication::getMessageSecret, pushChatMessage.getMessageSecret()).eq(PushApplication::getStatus, "0")); |
|
|
|
.eq(PushApplication::getMessageSecret, pushChatMessage.getMessageSecret()) |
|
|
|
|
|
|
|
.eq(PushApplication::getCreateById, pushChatMessage.getUserId()) |
|
|
|
|
|
|
|
.eq(PushApplication::getStatus, "0")); |
|
|
|
pushApplication = Optional.of(pushApplication).orElseThrow(() -> new CheckedException("你当前没有权限发送消息,请联系管理员!")); |
|
|
|
pushApplication = Optional.of(pushApplication).orElseThrow(() -> new CheckedException("你当前没有权限发送消息,请联系管理员!")); |
|
|
|
|
|
|
|
|
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
|
|
|
// 如果ip地址存在即验证发送方ip
|
|
|
|
// 如果ip地址存在即验证发送方ip
|
|
|
|
if (StrUtil.isNotBlank(pushApplication.getIgnoreIp()) && !StrUtil.contains(pushApplication.getIgnoreIp(), ServletUtil.getClientIP(request))) { |
|
|
|
if (StrUtil.isNotBlank(pushApplication.getIgnoreIp()) && !StrUtil.contains(pushApplication.getIgnoreIp(), ServletUtil.getClientIP(request))) { |
|
|
|
throw new CheckedException("你的ip地址不正确,请检查消息应用中设置的ip地址!"); |
|
|
|
throw new CheckedException("你的ip地址不正确,请检查消息应用中设置的ip地址!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询当前用户设置的自定义快捷方式消息提醒属性
|
|
|
|
// 配置推送用户
|
|
|
|
/*PushCustomType pushCustomType = iPushCustomTypeService.getOne(Wrappers.<PushCustomType>lambdaQuery() |
|
|
|
if (StrUtil.isBlank(pushChatMessage.getAlias())) { |
|
|
|
.eq(PushCustomType::getId, pushChatMessage.getPushTypeId()).eq(PushCustomType::getCreateById, pushChatMessage.getFromUserId())); |
|
|
|
List<PushConcernFan> pushConcernFanList = iPushConcernFanService.list(Wrappers.<PushConcernFan>lambdaQuery().eq(PushConcernFan::getFanUserId, pushChatMessage.getUserId())); |
|
|
|
if (ObjectUtil.isNotEmpty(pushCustomType)) { |
|
|
|
pushChatMessage.setAlias(pushConcernFanList.stream().map(item -> item.getConcernUserId()).collect(Collectors.joining())); |
|
|
|
pushMessage.setPlaySound(pushCustomType.getPlaySound()); |
|
|
|
|
|
|
|
pushMessage.setPlayVibrate(pushCustomType.getPlayVibrate()); |
|
|
|
|
|
|
|
pushMessage.setPlayLights(pushCustomType.getPlayLights()); |
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(pushCustomType.getCustomPlayFileName())) pushMessage.setCustomPlayFileName(pushCustomType.getCustomPlayFileName()); |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> blacklist = CollectionUtil.newArrayList(); /*iPushPassListService.list(Wrappers.<PushPassList>lambdaQuery() |
|
|
|
|
|
|
|
.eq(PushPassList::getFromPushId, pushMessage.getFromUserId()).eq(PushPassList::getType, "0")) |
|
|
|
|
|
|
|
.stream().map(item -> item.getToPushId()).collect(Collectors.toList());*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> whitelist = CollectionUtil.newArrayList(); /*iPushPassListService.list(Wrappers.<PushPassList>lambdaQuery() |
|
|
|
|
|
|
|
.eq(PushPassList::getFromPushId, pushMessage.getFromUserId()).eq(PushPassList::getType, "1")) |
|
|
|
|
|
|
|
.stream().map(item -> item.getToPushId()).collect(Collectors.toList());*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*List<PushUserManage> pushList = iPushUserManageService.list(Wrappers.<PushUserManage>lambdaQuery() |
|
|
|
|
|
|
|
.eq(PushUserManage::getFromUserId, pushMessage.getFromUserId()).eq(PushUserManage::getStatus, "1")) |
|
|
|
|
|
|
|
.stream().filter(item -> !blacklist.contains(item.getToUserId()) || !whitelist.contains(item.getToUserId())).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pushList.forEach(item -> send(pushMessage, item.getToUserId(), item.getPlaySound(), item.getPlayVibrate(), item.getPlayLights())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
whitelist.forEach(item -> { |
|
|
|
|
|
|
|
pushMessage.setPlaySound("0"); |
|
|
|
|
|
|
|
pushMessage.setPlayVibrate("0"); |
|
|
|
|
|
|
|
pushMessage.setPlayLights("0"); |
|
|
|
|
|
|
|
send(pushMessage, item, pushMessage.getPlaySound(), pushMessage.getPlayVibrate(), pushMessage.getPlayLights()); |
|
|
|
|
|
|
|
});*/ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤掉黑名单用户
|
|
|
|
|
|
|
|
List<PushBlacklist> pushBlacklists = iPushBlacklistService.list(Wrappers.<PushBlacklist>lambdaQuery().eq(PushBlacklist::getFanUserId, pushChatMessage.getUserId())); |
|
|
|
|
|
|
|
pushBlacklists.forEach(item -> pushChatMessage.getAlias().replaceAll(item.getConcernUserId() + ",|$", "")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询推送用户设置的推送类型,如果参数中没有指定则采用默认的推送类型
|
|
|
|
|
|
|
|
List<PushConcernFanType> pushConcernFanTypeList = iPushConcernFanTypeService.list(Wrappers.<PushConcernFanType>lambdaQuery() |
|
|
|
|
|
|
|
.eq(PushConcernFanType::getFanUserId, pushChatMessage.getUserId()) |
|
|
|
|
|
|
|
.eq(StrUtil.isNotBlank(pushChatMessage.getPushTypeId()), PushConcernFanType::getTypeId, pushChatMessage.getPushTypeId()) |
|
|
|
|
|
|
|
.eq(StrUtil.isBlank(pushChatMessage.getPushTypeId()), PushConcernFanType::getDefaultType, "1")); |
|
|
|
|
|
|
|
|
|
|
|
private void send(PushMessage pushMessage, String toUserId, String playSound, String playVibrate, String playLights) { |
|
|
|
|
|
|
|
/*// 设置默认数据
|
|
|
|
// 推送消息
|
|
|
|
pushMessage.setType("customizedcast"); |
|
|
|
StrUtil.split(pushChatMessage.getAlias(), ",").forEach(concernUserId -> { |
|
|
|
pushMessage.setDisplayType("notification"); |
|
|
|
Optional<PushConcernFanType> pushConcernFanTypeOptional = pushConcernFanTypeList.stream().filter(item -> item.getConcernUserId().equals(concernUserId)).findFirst(); |
|
|
|
pushMessage.setAliasType(PushClientUtil.uPushUserAliasType); |
|
|
|
if (pushConcernFanTypeOptional.isPresent()) { |
|
|
|
pushMessage.setAlias(toUserId); |
|
|
|
PushConcernFanType pushConcernFanType = pushConcernFanTypeOptional.get(); |
|
|
|
|
|
|
|
pushChatMessage.setPushTypeId(pushConcernFanType.getTypeId()); |
|
|
|
|
|
|
|
pushChatMessage.setPlayLights(pushConcernFanType.getPlayLights()); |
|
|
|
|
|
|
|
pushChatMessage.setPlaySound(pushConcernFanType.getPlaySound()); |
|
|
|
|
|
|
|
pushChatMessage.setPlayVibrate(pushConcernFanType.getPlayVibrate()); |
|
|
|
|
|
|
|
pushChatMessage.setPlayToText(pushConcernFanType.getPlayToText()); |
|
|
|
|
|
|
|
pushChatMessage.setSound(pushConcernFanType.getOfflineRingtone()); |
|
|
|
|
|
|
|
pushChatMessage.setOnlineRingtone(pushConcernFanType.getOnlineRingtone()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pushChatMessage.setType("customizedcast"); |
|
|
|
|
|
|
|
pushChatMessage.setDisplayType("notification"); |
|
|
|
|
|
|
|
pushChatMessage.setAliasType(PushClientUtil.uPushUserAliasType); |
|
|
|
|
|
|
|
pushChatMessage.setAlias(concernUserId); |
|
|
|
JSONObject custom = new JSONObject(); |
|
|
|
JSONObject custom = new JSONObject(); |
|
|
|
custom.put("sendUserId", pushMessage.getFromUserId()); |
|
|
|
custom.put("fanUserId", pushChatMessage.getUserId()); |
|
|
|
custom.put("customPlayFileName", pushMessage.getCustomPlayFileName()); |
|
|
|
custom.put("offlineRingtone", pushChatMessage.getSound()); |
|
|
|
custom.put("playSound", BooleanUtil.toBoolean(playSound)); |
|
|
|
custom.put("onlineRingtone", pushChatMessage.getOnlineRingtone()); |
|
|
|
custom.put("playVibrate", BooleanUtil.toBoolean(playVibrate)); |
|
|
|
custom.put("playToText", BooleanUtil.toBoolean(pushChatMessage.getPlayToText())); |
|
|
|
custom.put("playLights", BooleanUtil.toBoolean(playLights)); |
|
|
|
custom.put("playSound", BooleanUtil.toBoolean(pushChatMessage.getPlaySound())); |
|
|
|
pushMessage.setCustom(custom.toString()); |
|
|
|
custom.put("playVibrate", BooleanUtil.toBoolean(pushChatMessage.getPlayVibrate())); |
|
|
|
|
|
|
|
custom.put("playLights", BooleanUtil.toBoolean(pushChatMessage.getPlayLights())); |
|
|
|
|
|
|
|
pushChatMessage.setCustom(custom.toString()); |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("production_mode", PushClientUtil.PRODUCTION_MODE); |
|
|
|
jsonObject.put("production_mode", PushClientUtil.PRODUCTION_MODE); |
|
|
|
jsonObject.put("type", pushMessage.getType()); |
|
|
|
jsonObject.put("type", pushChatMessage.getType()); |
|
|
|
jsonObject.put("description", pushMessage.getRemarks()); |
|
|
|
jsonObject.put("description", pushChatMessage.getRemarks()); |
|
|
|
jsonObject.put("alias_type", pushMessage.getAliasType()); |
|
|
|
jsonObject.put("alias_type", pushChatMessage.getAliasType()); |
|
|
|
jsonObject.put("alias", pushMessage.getAlias()); |
|
|
|
jsonObject.put("alias", pushChatMessage.getAlias()); |
|
|
|
JSONObject payload = new JSONObject(); |
|
|
|
JSONObject payload = new JSONObject(); |
|
|
|
payload.put("display_type", pushMessage.getDisplayType()); |
|
|
|
payload.put("display_type", pushChatMessage.getDisplayType()); |
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
body.put("ticker", pushMessage.getTitle()); |
|
|
|
body.put("ticker", pushChatMessage.getTitle()); |
|
|
|
body.put("text", pushMessage.getText()); |
|
|
|
body.put("text", pushChatMessage.getText()); |
|
|
|
body.put("title", pushMessage.getTitle()); |
|
|
|
body.put("title", pushChatMessage.getTitle()); |
|
|
|
body.put("sound", pushMessage.getSound()); |
|
|
|
body.put("sound", pushChatMessage.getSound()); |
|
|
|
body.put("after_open", "go_custom"); |
|
|
|
body.put("after_open", "go_custom"); |
|
|
|
body.put("custom", pushMessage.getCustom()); |
|
|
|
body.put("custom", pushChatMessage.getCustom()); |
|
|
|
body.put("play_sound", BooleanUtil.toBoolean(playSound) ? false : !BooleanUtil.toBoolean(pushMessage.getPlaySound())); |
|
|
|
|
|
|
|
body.put("play_vibrate", BooleanUtil.toBoolean(playVibrate) ? false : !BooleanUtil.toBoolean(pushMessage.getPlayVibrate())); |
|
|
|
if (BooleanUtil.toBoolean(pushChatMessage.getPlaySound())) { |
|
|
|
body.put("play_lights", BooleanUtil.toBoolean(playLights) ? false : !BooleanUtil.toBoolean(pushMessage.getPlayLights())); |
|
|
|
body.put("play_sound", true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (BooleanUtil.toBoolean(pushChatMessage.getPlayVibrate())) { |
|
|
|
|
|
|
|
body.put("play_vibrate", true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (BooleanUtil.toBoolean(pushChatMessage.getPlayLights())) { |
|
|
|
|
|
|
|
body.put("play_lights", true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
payload.put("body", body); |
|
|
|
payload.put("body", body); |
|
|
|
jsonObject.put("payload", payload); |
|
|
|
jsonObject.put("payload", payload); |
|
|
|
JSONObject policy = new JSONObject(); |
|
|
|
JSONObject policy = new JSONObject(); |
|
|
@ -148,10 +145,12 @@ public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMappe |
|
|
|
try { |
|
|
|
try { |
|
|
|
PushClientUtil pushClientUtil = new PushClientUtil(okHttpClient); |
|
|
|
PushClientUtil pushClientUtil = new PushClientUtil(okHttpClient); |
|
|
|
pushClientUtil.send(jsonObject); |
|
|
|
pushClientUtil.send(jsonObject); |
|
|
|
iPushMessageService.save(pushMessage); |
|
|
|
iPushChatMessageService.save(pushChatMessage); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|