Codex Assistant
1 天以前 afeeed281e60466b576fbe74d339634cc5d07b82
backend/src/main/java/com/rongyichuang/auth/api/AuthGraphqlApi.java
@@ -1,20 +1,18 @@
package com.rongyichuang.auth.api;
import com.rongyichuang.auth.dto.LoginRequest;
import com.rongyichuang.auth.dto.LoginResponse;
import com.rongyichuang.auth.dto.PhoneDecryptResponse;
import com.rongyichuang.auth.dto.WxLoginRequest;
import com.rongyichuang.auth.dto.WxLoginResponse;
import com.rongyichuang.auth.dto.LoginRequest;
import com.rongyichuang.auth.dto.LoginResponse;
import com.rongyichuang.auth.service.AuthService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.stereotype.Controller;
/**
 * 认证GraphQL API
 * 认证GraphQL API控制器
 */
@Controller
public class AuthGraphqlApi {
@@ -23,29 +21,42 @@
    private AuthService authService;
    /**
     * Web端用户登录
     * 微信登录
     */
    @MutationMapping
    public LoginResponse webLogin(@Argument LoginRequest input) {
        return authService.login(input);
    public WxLoginResponse wxLogin(@Argument WxLoginRequest input) {
        try {
            return authService.wxLogin(input);
        } catch (Exception e) {
            throw new RuntimeException("微信登录失败: " + e.getMessage(), e);
        }
    }
    /**
     * 微信小程序登录
     * Web端登录
     */
    @MutationMapping
    public WxLoginResponse wxLogin(@Argument WxLoginRequest input) throws JsonProcessingException, JsonMappingException {
        return authService.wxLogin(input);
    public LoginResponse webLogin(@Argument LoginRequest input) {
        try {
            return authService.login(input);
        } catch (Exception e) {
            throw new RuntimeException("登录失败: " + e.getMessage(), e);
        }
    }
    /**
     * 解密微信手机号(旧版API)
     */
    @MutationMapping
    public PhoneDecryptResponse decryptPhoneNumber(@Argument String encryptedData,
                                                   @Argument String iv,
                                                   @Argument String sessionKey) {
        return authService.decryptPhoneNumber(encryptedData, iv, sessionKey);
    public PhoneDecryptResponse decryptPhoneNumber(
            @Argument String encryptedData,
            @Argument String iv,
            @Argument String sessionKey) {
        try {
            return authService.decryptPhoneNumber(encryptedData, iv, sessionKey);
        } catch (Exception e) {
            throw new RuntimeException("手机号解密失败: " + e.getMessage(), e);
        }
    }
    /**
@@ -53,6 +64,10 @@
     */
    @MutationMapping
    public PhoneDecryptResponse getPhoneNumberByCode(@Argument String code) {
        return authService.getPhoneNumberByCode(code);
        try {
            return authService.getPhoneNumberByCode(code);
        } catch (Exception e) {
            throw new RuntimeException("获取手机号失败: " + e.getMessage(), e);
        }
    }
}