Initial commit: backend code

This commit is contained in:
Agent
2026-03-20 04:59:00 +00:00
commit e7c7f3b174
42 changed files with 2855 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
package com.example.building.controller;
import com.example.building.common.Result;
import com.example.building.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 认证控制器
* 支持:手机号验证码登录、微信扫码登录、支付宝扫码登录
*/
@RestController
@RequestMapping("/api/v1/auth")
public class AuthController {
@Autowired
private AuthService authService;
/**
* 发送验证码
*/
@PostMapping("/send-code")
public Result<Void> sendCode(@RequestParam String phone) {
authService.sendCode(phone);
return Result.success();
}
/**
* 手机号验证码登录
*/
@PostMapping("/phone-login")
public Result<Map<String, Object>> phoneLogin(@RequestParam String phone, @RequestParam String code) {
Map<String, Object> result = authService.phoneLogin(phone, code);
return Result.success(result);
}
/**
* 微信登录
*/
@PostMapping("/wechat")
public Result<Map<String, Object>> wechatLogin(@RequestParam String code) {
Map<String, Object> result = authService.wechatLogin(code);
return Result.success(result);
}
/**
* 支付宝登录
*/
@PostMapping("/alipay")
public Result<Map<String, Object>> alipayLogin(@RequestParam String code) {
Map<String, Object> result = authService.alipayLogin(code);
return Result.success(result);
}
/**
* 刷新Token
*/
@PostMapping("/refresh")
public Result<Map<String, Object>> refresh(@RequestParam String refreshToken) {
Map<String, Object> result = authService.refreshToken(refreshToken);
return Result.success(result);
}
/**
* 获取当前用户
*/
@GetMapping("/me")
public Result<Map<String, Object>> me(@RequestHeader("X-User-Id") String userId) {
Map<String, Object> result = authService.getCurrentUser(userId);
return Result.success(result);
}
/**
* 退出登录
*/
@PostMapping("/logout")
public Result<Void> logout(@RequestHeader("Authorization") String token) {
String jwtToken = token.replace("Bearer ", "");
authService.logout(jwtToken);
return Result.success();
}
}