7
0

mkt新增获取公司列表接口

This commit is contained in:
许 洋 2024-09-03 18:13:37 +08:00
parent f272d5f199
commit f11735110f
3 changed files with 102 additions and 0 deletions

View File

@ -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
}

View File

@ -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)
}

68
services/mkt/subject.go Normal file
View File

@ -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
}