feat 支持cn coach

This commit is contained in:
timerzz 2024-06-16 10:02:31 +08:00
parent 63f1bd6930
commit a7d6c7c666

View File

@ -12,11 +12,19 @@ import (
"time" "time"
) )
type XMacHeader string
const (
XMac_Coach XMacHeader = "e6d4b3d780db4251bc4b6b54f41ee7b0"
XMac_Outlet XMacHeader = "b55d4769f3e768630046291ee2ee26f0"
)
type CN struct { type CN struct {
c *client.Client c *client.Client
xmac XMacHeader
} }
func CNClient() (cli *CN, err error) { func CNClient(xmac XMacHeader) (cli *CN, err error) {
cli = new(CN) cli = new(CN)
clientCfg := &tls.Config{ clientCfg := &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: true,
@ -25,6 +33,7 @@ func CNClient() (cli *CN, err error) {
client.WithTLSConfig(clientCfg), client.WithTLSConfig(clientCfg),
client.WithDialer(standard.NewDialer()), client.WithDialer(standard.NewDialer()),
) )
cli.xmac = xmac
return return
} }
@ -79,7 +88,7 @@ func (c *CN) ListItems(_ctx context.Context, page, size int) (ItemListData, erro
size = max(size, 50) size = max(size, 50)
req.SetRequestURI("https://ec-api.coach.com.cn/api/v2/item/search") req.SetRequestURI("https://ec-api.coach.com.cn/api/v2/item/search")
req.SetMethod("GET") req.SetMethod("GET")
req.SetHeader("X-Ma-C", " b55d4769f3e768630046291ee2ee26f0") req.SetHeader("X-Ma-C", string(c.xmac))
req.SetHeader("User-Agent", uarand.GetRandom()) req.SetHeader("User-Agent", uarand.GetRandom())
req.SetQueryString(fmt.Sprintf("scope=shop&pageNo=%d&pageSize=%d", page, size)) req.SetQueryString(fmt.Sprintf("scope=shop&pageNo=%d&pageSize=%d", page, size))