From f11735110ff3e3f91218bc1f4598fd37247656a0 Mon Sep 17 00:00:00 2001 From: xuyang Date: Tue, 3 Sep 2024 18:13:37 +0800 Subject: [PATCH] =?UTF-8?q?mkt=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=85=AC=E5=8F=B8=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/mkt/client.go | 12 +++++++ services/mkt/client_test.go | 22 ++++++++++++ services/mkt/subject.go | 68 +++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 services/mkt/client_test.go create mode 100644 services/mkt/subject.go diff --git a/services/mkt/client.go b/services/mkt/client.go index 53023b7..9c03d71 100644 --- a/services/mkt/client.go +++ b/services/mkt/client.go @@ -29,3 +29,15 @@ func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err = client.InitWithAccessKey(accesskey, secrect, source) return } + +func NewClient() (client *Client, err error) { + client = new(Client) + err = client.Init() + return +} + +func (c *Client) SubjectList(req *SubjectListRequest) (response *SubjectListResponse, err error) { + response = CreateSubjectListResponse() + err = c.DoAction(req, response) + return +} diff --git a/services/mkt/client_test.go b/services/mkt/client_test.go new file mode 100644 index 0000000..721a581 --- /dev/null +++ b/services/mkt/client_test.go @@ -0,0 +1,22 @@ +package mkt + +import ( + "fmt" + "testing" +) + +func TestSubjectList(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + + req := CreateSubjectListRequest(0) + req.Port = "9090" + list, err := client.SubjectList(req) + if err != nil { + panic(err) + } + + fmt.Println(list.Status, list.Code, list.Msg, list.Data) +} diff --git a/services/mkt/subject.go b/services/mkt/subject.go new file mode 100644 index 0000000..8177248 --- /dev/null +++ b/services/mkt/subject.go @@ -0,0 +1,68 @@ +package mkt + +import ( + "crypto/md5" + "encoding/hex" + "fmt" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" + "time" +) + +const appKey = "fc1f841#@de!!08" + +type SubjectListRequest struct { + *requests.RpcRequest +} + +type SubjectListResponse struct { + *responses.BaseResponse + Status bool `json:"status"` + Code int `json:"code"` + Msg string `json:"msg"` + Data struct { + List map[int]Data `json:"list"` + } `json:"data"` +} + +type Data struct { + Abbr string `json:"abbr"` + AbbrSign string `json:"abbr_sign"` + Id int `json:"id"` + Name string `json:"name"` + State int `json:"state"` + System string `json:"system"` + Type int `json:"type"` +} + +// CreateSubjectListRequest 公司列表请求 +func CreateSubjectListRequest(state int) (req *SubjectListRequest) { + ts := time.Now().Unix() + hash := md5.New() + hash.Write([]byte(fmt.Sprintf("%v%v", ts, appKey))) + hashBytes := hash.Sum(nil) + + token := hex.EncodeToString(hashBytes) + + req = &SubjectListRequest{ + RpcRequest: &requests.RpcRequest{}, + } + + req.InitWithApiInfo(HOST, VERSION, fmt.Sprintf("/api/subject/list")) + + req.FormParams = map[string]string{ + "token": token, + "ts": fmt.Sprintf("%v", ts), + "state": fmt.Sprintf("%v", state), + } + req.Method = requests.POST + return +} + +// CreateSubjectListResponse 公司列表请求响应 +func CreateSubjectListResponse() (response *SubjectListResponse) { + response = &SubjectListResponse{ + BaseResponse: &responses.BaseResponse{}, + } + return +}