XuqmGroup-Server/im-service/src/main/java/com/xuqm/im/controller/AuthController.java
XuqmGroup 763c097289 feat(chat): 添加聊天功能相关API接口、本地缓存和数据仓库
- 添加DemoApi接口定义用户认证和资料管理API
- 实现LocalImCache用于本地存储IM对话和消息历史
- 添加MessageContent模型处理多媒体消息内容
- 创建AttachmentRepository处理图片视频音频文件发送
- 实现AuthRepository管理用户登录注册和会话
- 添加VoiceRecorder支持语音录制功能
- 创建AppDependencies依赖注入容器
- 添加ChatScreen界面组件实现聊天UI逻辑
2026-04-28 09:45:20 +08:00

45 行
1.9 KiB
Java

package com.xuqm.im.controller;
import com.xuqm.common.model.ApiResponse;
import com.xuqm.im.service.ImAccountService;
import jakarta.validation.constraints.NotBlank;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/api/im/auth")
public class AuthController {
private final ImAccountService accountService;
public AuthController(ImAccountService accountService) {
this.accountService = accountService;
}
@PostMapping("/login")
public ResponseEntity<ApiResponse<Map<String, Object>>> login(
@RequestParam @NotBlank String appId,
@RequestParam @NotBlank String userId,
@RequestParam(required = false) String nickname,
@RequestParam(required = false) String avatar,
@RequestHeader(value = "X-App-Timestamp", required = false) String timestamp,
@RequestHeader(value = "X-App-Nonce", required = false) String nonce,
@RequestHeader(value = "X-App-Signature", required = false) String signature) {
if (timestamp == null || nonce == null || signature == null) {
return ResponseEntity.status(401).body(ApiResponse.error(401, "Missing app signature"));
}
accountService.validateSignature(appId, userId, nickname, avatar, timestamp, nonce, signature);
ImAccountService.LoginResult result = accountService.loginOrRegister(appId, userId, nickname, avatar);
return ResponseEntity.ok(ApiResponse.success(Map.of(
"token", result.token(),
"expiresAt", result.expiresAt()
)));
}
}