refactor: remove user-level API methods, keep admin and send only
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -28,7 +28,7 @@ const (
|
|||||||
// 构造方式:
|
// 构造方式:
|
||||||
// - NewServiceClient: 管理端(自动调用 service-token-login 获取 Bearer Token)
|
// - NewServiceClient: 管理端(自动调用 service-token-login 获取 Bearer Token)
|
||||||
// - NewBearerClient: 管理端(使用已有的 Bearer Token)
|
// - NewBearerClient: 管理端(使用已有的 Bearer Token)
|
||||||
// - NewUserTokenClient: 发送端(X-SMS-Token + 请求签名)
|
// - NewUserTokenClient: 发送端(X-SMS-Token + 请求签名,仅可调用发送接口)
|
||||||
type Client struct {
|
type Client struct {
|
||||||
baseURL string
|
baseURL string
|
||||||
mode authMode
|
mode authMode
|
||||||
@@ -73,9 +73,9 @@ func NewServiceClient(baseURL, serviceToken string, opts ...Option) (*Client, er
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBearerClient 创建使用已有 Bearer Token 的客户端。
|
// NewBearerClient 创建使用已有 Bearer Token 的管理端客户端。
|
||||||
//
|
//
|
||||||
// 适用于已通过其他方式获取 Bearer Token 的场景(如用户中心 Token)。
|
// 适用于已通过 service-token-login 等方式获取 Bearer Token 的场景。
|
||||||
func NewBearerClient(baseURL, bearerToken string, opts ...Option) *Client {
|
func NewBearerClient(baseURL, bearerToken string, opts ...Option) *Client {
|
||||||
c := &Client{
|
c := &Client{
|
||||||
baseURL: strings.TrimRight(baseURL, "/"),
|
baseURL: strings.TrimRight(baseURL, "/"),
|
||||||
@@ -92,7 +92,7 @@ func NewBearerClient(baseURL, bearerToken string, opts ...Option) *Client {
|
|||||||
// NewUserTokenClient 创建发送端客户端。
|
// NewUserTokenClient 创建发送端客户端。
|
||||||
//
|
//
|
||||||
// 使用 X-SMS-Token 头认证,POST/PUT 请求体会自动计算 sign 签名。
|
// 使用 X-SMS-Token 头认证,POST/PUT 请求体会自动计算 sign 签名。
|
||||||
// 主要用于调用短信发送接口,也可管理当前用户的签名/模板/Token 等资源。
|
// 仅可调用短信发送接口(SendBatch/SendMulti/ListSendRecords/GetSendStatus)。
|
||||||
func NewUserTokenClient(baseURL, userToken string, opts ...Option) *Client {
|
func NewUserTokenClient(baseURL, userToken string, opts ...Option) *Client {
|
||||||
c := &Client{
|
c := &Client{
|
||||||
baseURL: strings.TrimRight(baseURL, "/"),
|
baseURL: strings.TrimRight(baseURL, "/"),
|
||||||
|
|||||||
@@ -5,27 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 用户接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// ListQuotas 获取当前用户的额度列表(分页)。
|
|
||||||
// GET /api/sms/quota/list
|
|
||||||
func (c *Client) ListQuotas(ctx context.Context, q PaginationQuery) (PaginationResult[SmsQuota], error) {
|
|
||||||
params := paginationParams(q)
|
|
||||||
return get[PaginationResult[SmsQuota]](c, ctx, "/api/sms/quota/list", buildQuery(params))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetQuotaSummary 获取当前用户的额度汇总。
|
|
||||||
// GET /api/sms/quota/summary
|
|
||||||
func (c *Client) GetQuotaSummary(ctx context.Context) (QuotaSummary, error) {
|
|
||||||
return get[QuotaSummary](c, ctx, "/api/sms/quota/summary", nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 管理员接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// AdminListQuotas 管理员获取额度列表,可按 UserID 筛选。
|
// AdminListQuotas 管理员获取额度列表,可按 UserID 筛选。
|
||||||
// GET /api/sms/admin/quota/list
|
// GET /api/sms/admin/quota/list
|
||||||
func (c *Client) AdminListQuotas(ctx context.Context, q QuotaListQuery) (PaginationResult[SmsQuota], error) {
|
func (c *Client) AdminListQuotas(ctx context.Context, q QuotaListQuery) (PaginationResult[SmsQuota], error) {
|
||||||
|
|||||||
@@ -5,53 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 用户接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// CreateSignature 创建短信签名。
|
|
||||||
// POST /api/sms/signature
|
|
||||||
func (c *Client) CreateSignature(ctx context.Context, req CreateSignatureReq) (SmsSignature, error) {
|
|
||||||
return post[SmsSignature](c, ctx, "/api/sms/signature", req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListSignatures 获取当前用户的签名列表(分页)。
|
|
||||||
// GET /api/sms/signature/list
|
|
||||||
func (c *Client) ListSignatures(ctx context.Context, q PaginationQuery) (PaginationResult[SmsSignature], error) {
|
|
||||||
params := paginationParams(q)
|
|
||||||
return get[PaginationResult[SmsSignature]](c, ctx, "/api/sms/signature/list", buildQuery(params))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSignature 获取指定签名详情。
|
|
||||||
// GET /api/sms/signature/:id
|
|
||||||
func (c *Client) GetSignature(ctx context.Context, id uint) (SmsSignature, error) {
|
|
||||||
return get[SmsSignature](c, ctx, fmt.Sprintf("/api/sms/signature/%d", id), nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateSignature 更新指定签名。
|
|
||||||
// PUT /api/sms/signature/:id
|
|
||||||
func (c *Client) UpdateSignature(ctx context.Context, id uint, req UpdateSignatureReq) (SmsSignature, error) {
|
|
||||||
return put[SmsSignature](c, ctx, fmt.Sprintf("/api/sms/signature/%d", id), req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteSignature 删除指定签名。
|
|
||||||
// DELETE /api/sms/signature/:id
|
|
||||||
func (c *Client) DeleteSignature(ctx context.Context, id uint) error {
|
|
||||||
_, err := del[any](c, ctx, fmt.Sprintf("/api/sms/signature/%d", id))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SubmitSignature 提交签名进入审核。
|
|
||||||
// POST /api/sms/signature/:id/submit
|
|
||||||
func (c *Client) SubmitSignature(ctx context.Context, id uint) error {
|
|
||||||
_, err := post[any](c, ctx, fmt.Sprintf("/api/sms/signature/%d/submit", id), nil)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 管理员接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// AdminListSignatures 管理员获取签名列表,可按 UserID、Status 筛选。
|
// AdminListSignatures 管理员获取签名列表,可按 UserID、Status 筛选。
|
||||||
// GET /api/sms/admin/signature/list
|
// GET /api/sms/admin/signature/list
|
||||||
func (c *Client) AdminListSignatures(ctx context.Context, q SignatureListQuery) (PaginationResult[SmsSignature], error) {
|
func (c *Client) AdminListSignatures(ctx context.Context, q SignatureListQuery) (PaginationResult[SmsSignature], error) {
|
||||||
|
|||||||
-54
@@ -5,60 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 用户接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// CreateTemplate 创建短信模板。
|
|
||||||
// POST /api/sms/template
|
|
||||||
func (c *Client) CreateTemplate(ctx context.Context, req CreateTemplateReq) (SmsTemplate, error) {
|
|
||||||
return post[SmsTemplate](c, ctx, "/api/sms/template", req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListTemplates 获取当前用户的模板列表(分页)。
|
|
||||||
// GET /api/sms/template/list
|
|
||||||
func (c *Client) ListTemplates(ctx context.Context, q PaginationQuery) (PaginationResult[SmsTemplate], error) {
|
|
||||||
params := paginationParams(q)
|
|
||||||
return get[PaginationResult[SmsTemplate]](c, ctx, "/api/sms/template/list", buildQuery(params))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTemplate 获取指定模板详情。
|
|
||||||
// GET /api/sms/template/:id
|
|
||||||
func (c *Client) GetTemplate(ctx context.Context, id uint) (SmsTemplate, error) {
|
|
||||||
return get[SmsTemplate](c, ctx, fmt.Sprintf("/api/sms/template/%d", id), nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateTemplate 更新指定模板。
|
|
||||||
// PUT /api/sms/template/:id
|
|
||||||
func (c *Client) UpdateTemplate(ctx context.Context, id uint, req UpdateTemplateReq) (SmsTemplate, error) {
|
|
||||||
return put[SmsTemplate](c, ctx, fmt.Sprintf("/api/sms/template/%d", id), req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteTemplate 删除指定模板。
|
|
||||||
// DELETE /api/sms/template/:id
|
|
||||||
func (c *Client) DeleteTemplate(ctx context.Context, id uint) error {
|
|
||||||
_, err := del[any](c, ctx, fmt.Sprintf("/api/sms/template/%d", id))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SubmitTemplate 提交模板进入审核。
|
|
||||||
// POST /api/sms/template/:id/submit
|
|
||||||
func (c *Client) SubmitTemplate(ctx context.Context, id uint) error {
|
|
||||||
_, err := post[any](c, ctx, fmt.Sprintf("/api/sms/template/%d/submit", id), nil)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListRecommendedTemplates 获取推荐模板列表(分页)。
|
|
||||||
// GET /api/sms/template/recommended
|
|
||||||
func (c *Client) ListRecommendedTemplates(ctx context.Context, q PaginationQuery) (PaginationResult[SmsRecommendedTemplate], error) {
|
|
||||||
params := paginationParams(q)
|
|
||||||
return get[PaginationResult[SmsRecommendedTemplate]](c, ctx, "/api/sms/template/recommended", buildQuery(params))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 管理员接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// AdminListTemplates 管理员获取模板列表,可按 UserID、Status 筛选。
|
// AdminListTemplates 管理员获取模板列表,可按 UserID、Status 筛选。
|
||||||
// GET /api/sms/admin/template/list
|
// GET /api/sms/admin/template/list
|
||||||
func (c *Client) AdminListTemplates(ctx context.Context, q TemplateListQuery) (PaginationResult[SmsTemplate], error) {
|
func (c *Client) AdminListTemplates(ctx context.Context, q TemplateListQuery) (PaginationResult[SmsTemplate], error) {
|
||||||
|
|||||||
@@ -5,53 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 用户接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// CreateUserToken 创建用户令牌。
|
|
||||||
// POST /api/sms/token
|
|
||||||
func (c *Client) CreateUserToken(ctx context.Context, req CreateTokenReq) (SmsUserToken, error) {
|
|
||||||
return post[SmsUserToken](c, ctx, "/api/sms/token", req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListUserTokens 获取当前用户的令牌列表(分页)。
|
|
||||||
// GET /api/sms/token/list
|
|
||||||
func (c *Client) ListUserTokens(ctx context.Context, q PaginationQuery) (PaginationResult[SmsUserToken], error) {
|
|
||||||
params := paginationParams(q)
|
|
||||||
return get[PaginationResult[SmsUserToken]](c, ctx, "/api/sms/token/list", buildQuery(params))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUserToken 获取指定令牌详情。
|
|
||||||
// GET /api/sms/token/:id
|
|
||||||
func (c *Client) GetUserToken(ctx context.Context, id uint) (SmsUserToken, error) {
|
|
||||||
return get[SmsUserToken](c, ctx, fmt.Sprintf("/api/sms/token/%d", id), nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateUserToken 更新指定令牌。
|
|
||||||
// PUT /api/sms/token/:id
|
|
||||||
func (c *Client) UpdateUserToken(ctx context.Context, id uint, req UpdateTokenReq) (SmsUserToken, error) {
|
|
||||||
return put[SmsUserToken](c, ctx, fmt.Sprintf("/api/sms/token/%d", id), req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteUserToken 删除指定令牌。
|
|
||||||
// DELETE /api/sms/token/:id
|
|
||||||
func (c *Client) DeleteUserToken(ctx context.Context, id uint) error {
|
|
||||||
_, err := del[any](c, ctx, fmt.Sprintf("/api/sms/token/%d", id))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToggleUserToken 切换令牌的启用/禁用状态。
|
|
||||||
// POST /api/sms/token/:id/toggle
|
|
||||||
func (c *Client) ToggleUserToken(ctx context.Context, id uint) error {
|
|
||||||
_, err := post[any](c, ctx, fmt.Sprintf("/api/sms/token/%d/toggle", id), nil)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
// 管理员接口
|
|
||||||
// ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
// AdminListUserTokens 管理员获取令牌列表,可按 UserID、Status 筛选。
|
// AdminListUserTokens 管理员获取令牌列表,可按 UserID、Status 筛选。
|
||||||
// GET /api/sms/admin/token/list
|
// GET /api/sms/admin/token/list
|
||||||
func (c *Client) AdminListUserTokens(ctx context.Context, q TokenListQuery) (PaginationResult[SmsUserToken], error) {
|
func (c *Client) AdminListUserTokens(ctx context.Context, q TokenListQuery) (PaginationResult[SmsUserToken], error) {
|
||||||
|
|||||||
@@ -65,22 +65,6 @@ type SmsSignature struct {
|
|||||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateSignatureReq struct {
|
|
||||||
Title string `json:"title"`
|
|
||||||
ApplicantName string `json:"applicant_name"`
|
|
||||||
ApplicantIDCard string `json:"applicant_id_card,omitempty"`
|
|
||||||
ApplicantCompany string `json:"applicant_company,omitempty"`
|
|
||||||
LicenseURL string `json:"license_url,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateSignatureReq struct {
|
|
||||||
Title string `json:"title,omitempty"`
|
|
||||||
ApplicantName string `json:"applicant_name,omitempty"`
|
|
||||||
ApplicantIDCard string `json:"applicant_id_card,omitempty"`
|
|
||||||
ApplicantCompany string `json:"applicant_company,omitempty"`
|
|
||||||
LicenseURL string `json:"license_url,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AdminCreateSignatureReq struct {
|
type AdminCreateSignatureReq struct {
|
||||||
UserID uint `json:"user_id"`
|
UserID uint `json:"user_id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
@@ -130,19 +114,6 @@ type SmsTemplate struct {
|
|||||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateTemplateReq struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Content string `json:"content"`
|
|
||||||
Params []TemplateParam `json:"params,omitempty"`
|
|
||||||
RecommendedID *uint `json:"recommended_id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateTemplateReq struct {
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
Content string `json:"content,omitempty"`
|
|
||||||
Params []TemplateParam `json:"params,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AdminCreateTemplateReq struct {
|
type AdminCreateTemplateReq struct {
|
||||||
UserID uint `json:"user_id"`
|
UserID uint `json:"user_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -203,13 +174,6 @@ type SmsUserToken struct {
|
|||||||
LastUsedIP string `json:"last_used_ip"`
|
LastUsedIP string `json:"last_used_ip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateTokenReq struct {
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
QuotaLimit *int `json:"quota_limit,omitempty"`
|
|
||||||
TemplateIDs []uint `json:"template_ids,omitempty"`
|
|
||||||
ExpireAt string `json:"expire_at,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateTokenReq struct {
|
type UpdateTokenReq struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
QuotaLimit *int `json:"quota_limit,omitempty"`
|
QuotaLimit *int `json:"quota_limit,omitempty"`
|
||||||
|
|||||||
Reference in New Issue
Block a user