From 25ba002da23f82302f4452d25f95e9722bcd9556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=81=92?= <2390904403@qq.com> Date: Fri, 17 Oct 2025 15:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B3=BB=E7=BB=9F=E7=9B=B8?= =?UTF-8?q?=E5=85=B3&=E8=8A=82=E5=81=87=E6=97=A5=E7=9B=B8=E5=85=B3&?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9B=B8=E5=85=B3RPC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/rpc/holiday.go | 33 +++++++++++++++++++++++++++++++++ pkg/rpc/system.go | 31 +++++++++++++++++++++++++++++++ pkg/rpc/type.go | 15 +++++++++++++++ pkg/rpc/user.go | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 pkg/rpc/holiday.go create mode 100644 pkg/rpc/system.go create mode 100644 pkg/rpc/user.go diff --git a/pkg/rpc/holiday.go b/pkg/rpc/holiday.go new file mode 100644 index 0000000..13fe7e0 --- /dev/null +++ b/pkg/rpc/holiday.go @@ -0,0 +1,33 @@ +package rpc + +import ( + "fmt" + "time" +) + +// 节假日相关RPC +type Holiday struct{} + +// 判断某个日期是否是节假日 +func (h *Holiday) IsHoliday(date time.Time) (*bool, error) { + body := map[string]any{ + "date": date.Format(time.DateOnly), + } + result := &Result[bool]{} + if err := GetRequest().Send("holiday.is_holiday", body, result); err != nil { + return nil, err + } + if result.Code != 0 { + return nil, fmt.Errorf("%s", result.Message) + } + return &result.Data, nil +} + +var holiday *Holiday + +func GetHoliday() *Holiday { + if holiday == nil { + holiday = &Holiday{} + } + return holiday +} diff --git a/pkg/rpc/system.go b/pkg/rpc/system.go new file mode 100644 index 0000000..fa930b0 --- /dev/null +++ b/pkg/rpc/system.go @@ -0,0 +1,31 @@ +package rpc + +import "fmt" + +// 系统相关RPC +type System struct{} + +// 获取系统位置 +func (s *System) GetSystemLocation() (*SystemLocation, error) { + body := map[string]any{ + "key": "system_location", + } + result := &Result[SystemLocation]{} + if err := GetRequest().Send("system.get_config", body, result); err != nil { + return nil, err + } + if result.Code != 0 { + return nil, fmt.Errorf("%s", result.Message) + } + return &result.Data, nil +} + +var system *System + +// 获取系统相关RPC +func GetSystem() *System { + if system == nil { + system = &System{} + } + return system +} diff --git a/pkg/rpc/type.go b/pkg/rpc/type.go index f07c15b..d69c4e2 100644 --- a/pkg/rpc/type.go +++ b/pkg/rpc/type.go @@ -153,3 +153,18 @@ type AutomationTask struct { ConditionList []AutomationCondition `json:"condition_list"` // 条件列表 ActionList []AutomationAction `json:"action_list"` // 动作列表 } + +// 系统位置 +type SystemLocation struct { + Longitude float64 `json:"longitude,string"` // 经度 + Latitude float64 `json:"latitude,string"` // 维度 +} + +// 用户详情 +type UserDetail struct { + Mobile *string `json:"mobile,omitempty"` // 手机号 + Email *string `json:"email,omitempty"` // 邮箱 + Nickname *string `json:"nickname,omitempty"` // 昵称 + QQ *string `json:"qq,omitempty"` // QQ + Status uint8 `json:"status"` // 状态 +} diff --git a/pkg/rpc/user.go b/pkg/rpc/user.go new file mode 100644 index 0000000..eedbced --- /dev/null +++ b/pkg/rpc/user.go @@ -0,0 +1,32 @@ +package rpc + +import "fmt" + +// 用户相关RPC +type User struct{} + +// 获取用户详情 +func (u *User) GetDetail(userId uint32) (*UserDetail, error) { + body := map[string]any{ + "user_id": userId, + "field_list": []string{"mobile", "email", "nickname", "qq", "status"}, + } + result := &Result[UserDetail]{} + if err := GetRequest().Send("user.get_detail", body, result); err != nil { + return nil, err + } + if result.Code != 0 { + return nil, fmt.Errorf("%s", result.Message) + } + return &result.Data, nil +} + +var user *User + +// 获取用户相关RPC +func GetUser() *User { + if user == nil { + user = &User{} + } + return user +}