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 sendCode(@RequestParam String phone) { authService.sendCode(phone); return Result.success(); } /** * 手机号验证码登录 */ @PostMapping("/phone-login") public Result> phoneLogin(@RequestParam String phone, @RequestParam String code) { Map result = authService.phoneLogin(phone, code); return Result.success(result); } /** * 微信登录 */ @PostMapping("/wechat") public Result> wechatLogin(@RequestParam String code) { Map result = authService.wechatLogin(code); return Result.success(result); } /** * 支付宝登录 */ @PostMapping("/alipay") public Result> alipayLogin(@RequestParam String code) { Map result = authService.alipayLogin(code); return Result.success(result); } /** * 刷新Token */ @PostMapping("/refresh") public Result> refresh(@RequestParam String refreshToken) { Map result = authService.refreshToken(refreshToken); return Result.success(result); } /** * 获取当前用户 */ @GetMapping("/me") public Result> me(@RequestHeader("X-User-Id") String userId) { Map result = authService.getCurrentUser(userId); return Result.success(result); } /** * 退出登录 */ @PostMapping("/logout") public Result logout(@RequestHeader("Authorization") String token) { String jwtToken = token.replace("Bearer ", ""); authService.logout(jwtToken); return Result.success(); } }