jd fake api

This commit is contained in:
gazebo
2020-01-14 17:34:14 +08:00
parent 2245908e18
commit 23b58f605a
3 changed files with 207 additions and 2 deletions

View File

@@ -61,6 +61,7 @@ const (
type API struct {
platformapi.APICookie
baseURL string
token string
appKey string
appSecret string
@@ -134,6 +135,7 @@ func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API
curConfig = *config[0]
}
return &API{
baseURL: prodURL,
token: token,
appKey: appKey,
appSecret: appSecret,
@@ -142,6 +144,12 @@ func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API
}
}
func NewFakeJD(token, baseURL string, config ...*platformapi.APIConfig) *API {
a := New(token, "", "", config...)
a.baseURL = baseURL
return a
}
func NewPageOnly(cookie string, config ...*platformapi.APIConfig) *API {
api := New("", "", "", config...)
api.SetCookie(accessStorePageCookieName, cookie)
@@ -186,11 +194,11 @@ func (a *API) AccessAPI2(apiStr string, jdParams map[string]interface{}, traceIn
params[signKey] = sign
var request *http.Request
if userGet {
fullURL := utils.GenerateGetURL(prodURL, apiStr, params)
fullURL := utils.GenerateGetURL(a.baseURL, apiStr, params)
// baseapi.SugarLogger.Debug(fullURL)
request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
} else {
fullURL := prodURL + "/" + apiStr
fullURL := utils.GenerateGetURL(a.baseURL, apiStr, nil)
// baseapi.SugarLogger.Debug(utils.Map2URLValues(params).Encode())
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
request.Header.Set("charset", "UTF-8")