package com.xuqm.push.controller; import com.xuqm.common.model.ApiResponse; import com.xuqm.push.entity.DeviceTokenEntity; import com.xuqm.push.service.PushAccountService; import com.xuqm.push.service.PushDispatcher; import org.springframework.http.ResponseEntity; 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/push/auth") public class PushAuthController { private final PushAccountService accountService; private final PushDispatcher pushDispatcher; public PushAuthController(PushAccountService accountService, PushDispatcher pushDispatcher) { this.accountService = accountService; this.pushDispatcher = pushDispatcher; } /** * Login with userSig. On success, automatically registers the device push token. * Returns a pushToken (JWT) used to authenticate subsequent push service requests. */ @PostMapping("/login") public ResponseEntity>> login( @RequestParam String appKey, @RequestParam String userId, @RequestParam String userSig, @RequestParam DeviceTokenEntity.Vendor vendor, @RequestParam String token, @RequestParam(required = false) String platform, @RequestParam(required = false) String deviceId, @RequestParam(required = false) String brand, @RequestParam(required = false) String model, @RequestParam(required = false) String osVersion, @RequestParam(required = false) String appVersion) { PushAccountService.LoginResult result = accountService.loginWithUserSig(appKey, userId, userSig); pushDispatcher.registerToken(appKey, userId, vendor, token, platform, deviceId, brand, model, osVersion, appVersion); Map response = Map.of( "pushToken", result.pushToken(), "userId", result.user().getUserId(), "appKey", appKey, "nickname", result.user().getNickname() != null ? result.user().getNickname() : "" ); return ResponseEntity.ok(ApiResponse.success(response)); } }