You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pinduoduo/client.go

73 lines
1.8 KiB

2 years ago
package pinduoduo
import (
2 years ago
"go.dtapp.net/godecimal"
2 years ago
"go.dtapp.net/golog"
"go.dtapp.net/gorequest"
"strings"
)
2 years ago
// ClientConfig 实例配置
type ClientConfig struct {
2 years ago
ClientId string // POP分配给应用的client_id
ClientSecret string // POP分配给应用的client_secret
MediaId string // 媒体ID
Pid string // 推广位
2 years ago
}
2 years ago
// Client 实例
2 years ago
type Client struct {
2 years ago
requestClient *gorequest.App // 请求服务
config struct {
clientId string // POP分配给应用的client_id
clientSecret string // POP分配给应用的client_secret
mediaId string // 媒体ID
pid string // 推广位
}
log struct {
2 years ago
status bool // 状态
2 years ago
client *golog.ApiClient // 日志服务
2 years ago
}
2 years ago
}
2 years ago
// NewClient 创建实例化
2 years ago
func NewClient(config *ClientConfig) (*Client, error) {
2 years ago
2 years ago
c := &Client{}
2 years ago
c.config.clientId = config.ClientId
c.config.clientSecret = config.ClientSecret
c.config.mediaId = config.MediaId
c.config.pid = config.Pid
2 years ago
2 years ago
c.requestClient = gorequest.NewHttp()
c.requestClient.Uri = apiUrl
2 years ago
2 years ago
return c, nil
2 years ago
}
type ErrResp struct {
ErrorResponse struct {
ErrorMsg string `json:"error_msg"`
SubMsg string `json:"sub_msg"`
SubCode interface{} `json:"sub_code"`
ErrorCode int `json:"error_code"`
RequestId string `json:"request_id"`
} `json:"error_response"`
}
type CustomParametersResult struct {
Sid string `json:"sid"`
Uid string `json:"uid"`
}
2 years ago
func (c *Client) SalesTipParseInt64(salesTip string) int64 {
2 years ago
if strings.Contains(salesTip, "万+") {
return godecimal.NewString(strings.Replace(salesTip, "万+", "0000", -1)).Int64()
} else if strings.Contains(salesTip, "万") {
return godecimal.NewString(strings.Replace(salesTip, "万", "000", -1)).Int64()
2 years ago
} else {
2 years ago
return godecimal.NewString(salesTip).Int64()
2 years ago
}
}