refactor: 重构项目结构,迁移后端至 mengyastore-backend-go,新增 Java 后端、前端功能更新及部署文档

This commit is contained in:
2026-03-27 15:10:53 +08:00
parent 84874707f5
commit 63781358b2
71 changed files with 2123 additions and 250 deletions

View File

@@ -0,0 +1,66 @@
package auth
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"time"
)
const defaultAuthAPIURL = "https://auth.api.shumengya.top"
type SproutGateClient struct {
apiURL string
httpClient *http.Client
}
type VerifyResult struct {
Valid bool `json:"valid"`
User *SproutGateUser `json:"user"`
}
type SproutGateUser struct {
Account string `json:"account"`
Username string `json:"username"`
AvatarURL string `json:"avatarUrl"`
Level int `json:"level"`
Email string `json:"email"`
}
func NewSproutGateClient(apiURL string) *SproutGateClient {
if apiURL == "" {
apiURL = defaultAuthAPIURL
}
return &SproutGateClient{
apiURL: apiURL,
httpClient: &http.Client{Timeout: 10 * time.Second},
}
}
func (c *SproutGateClient) VerifyToken(token string) (*VerifyResult, error) {
body, _ := json.Marshal(map[string]string{"token": token})
resp, err := c.httpClient.Post(c.apiURL+"/api/auth/verify", "application/json", bytes.NewReader(body))
if err != nil {
log.Printf("[SproutGate] 验证请求失败: %v", err)
return nil, fmt.Errorf("验证请求失败: %w", err)
}
defer resp.Body.Close()
rawBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("[SproutGate] 读取响应体失败: %v", err)
return nil, fmt.Errorf("读取验证响应失败: %w", err)
}
log.Printf("[SproutGate] verify response status=%d body=%s", resp.StatusCode, string(rawBody))
var result VerifyResult
if err := json.Unmarshal(rawBody, &result); err != nil {
log.Printf("[SproutGate] 解析响应失败: %v", err)
return nil, fmt.Errorf("解析验证响应失败: %w", err)
}
return &result, nil
}