OpenIMApiClient 替换
This commit is contained in:
@@ -5,7 +5,7 @@ import com.tailbet.mapper.UserMapper;
|
||||
import com.tailbet.mapper.DigitWhiteMapper;
|
||||
import com.tailbet.model.entity.DigitWhite;
|
||||
import com.tailbet.model.entity.User;
|
||||
import com.tailbet.openim.OpenIMClient;
|
||||
import com.tailbet.openim.OpenIMApiClient;
|
||||
import com.tailbet.service.IPushService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -24,7 +24,8 @@ public class PushServiceImpl implements IPushService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final DigitWhiteMapper digitWhiteMapper;
|
||||
private final OpenIMClient openIMClient;
|
||||
private final OpenIMApiClient openIMApiClient;
|
||||
private final com.tailbet.config.OpenIMProperties openIMProperties;
|
||||
|
||||
/**
|
||||
* 推送尾数试算完成通知给白名单用户
|
||||
@@ -94,8 +95,13 @@ public class PushServiceImpl implements IPushService {
|
||||
}
|
||||
|
||||
// 通过OpenIM单聊发送(生产环境可扩展FCM/APNs离线推送)
|
||||
openIMClient.sendUserMessage(String.valueOf(user.getId()),
|
||||
message.getTitle() + " - " + message.getContent());
|
||||
openIMApiClient.sendMsg(
|
||||
openIMProperties.getAdminUserId(),
|
||||
String.valueOf(user.getId()),
|
||||
1, // sessionType 1=单聊
|
||||
101, // contentType 101=文本
|
||||
java.util.Map.of("content", message.getTitle() + " - " + message.getContent())
|
||||
);
|
||||
|
||||
log.info("推送发送成功: userId={}, type={}", message.getUserId(), message.getType());
|
||||
} catch (Exception e) {
|
||||
@@ -110,9 +116,14 @@ public class PushServiceImpl implements IPushService {
|
||||
@Override
|
||||
public void broadcastToGroup(Long groupId, IPushService.PushMessage message) {
|
||||
try {
|
||||
// 通过OpenIM群消息发送
|
||||
openIMClient.sendGroupMessage(String.valueOf(groupId),
|
||||
message.getContent());
|
||||
// 通过OpenIM群消息发送(使用管理员身份发送)
|
||||
openIMApiClient.sendMsg(
|
||||
openIMProperties.getAdminUserId(),
|
||||
String.valueOf(groupId),
|
||||
3, // sessionType 3=群聊
|
||||
101, // contentType 101=文本
|
||||
java.util.Map.of("content", message.getContent())
|
||||
);
|
||||
log.info("群广播发送成功: groupId={}, type={}", groupId, message.getType());
|
||||
} catch (Exception e) {
|
||||
log.error("群广播发送失败: groupId={}, type={}, error={}",
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tailbet.model.entity.User;
|
||||
import com.tailbet.mapper.UserMapper;
|
||||
import com.tailbet.model.dto.UpdateUserDTO;
|
||||
import com.tailbet.openim.OpenIMClient;
|
||||
import com.tailbet.openim.OpenIMApiClient;
|
||||
import com.tailbet.service.IUserService;
|
||||
import com.tailbet.util.JwtUtil;
|
||||
import com.tailbet.util.PasswordUtil;
|
||||
@@ -26,8 +26,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final PasswordUtil passwordUtil;
|
||||
private final JwtUtil jwtUtil;
|
||||
private final OpenIMClient openIMClient;
|
||||
private final OpenIMApiClient openIMApiClient;
|
||||
|
||||
|
||||
/**
|
||||
@@ -59,9 +58,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
userMapper.insert(user);
|
||||
|
||||
// 在OpenIM创建用户
|
||||
boolean openIMResult = openIMClient.createUser(String.valueOf(user.getId()), user.getNickname());
|
||||
if (!openIMResult) {
|
||||
log.warn("OpenIM用户创建失败: userId={}, username={}", user.getId(), username);
|
||||
try {
|
||||
openIMApiClient.userRegister(String.valueOf(user.getId()), user.getNickname(), null);
|
||||
} catch (Exception e) {
|
||||
log.warn("OpenIM用户创建失败: userId={}, username={}, error={}", user.getId(), username, e.getMessage());
|
||||
throw new RuntimeException("OpenIM用户创建失败,请稍后再试!");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user