+ APICookie

This commit is contained in:
gazebo
2019-07-24 16:18:11 +08:00
parent 74c07ba61e
commit 32b53c9c9e
14 changed files with 168 additions and 121 deletions

View File

@@ -59,6 +59,8 @@ const (
)
type API struct {
platformapi.APICookie
token string
appKey string
appSecret string

View File

@@ -27,7 +27,9 @@ func init() {
// 天天果园
// api = New("84541069-fbe2-424b-b625-9b2ba1d4c9e6", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26")
api.SetStoreCookie("YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHDYZP7PPVMRGO4VWG2JRBMKFTOGIWZ5L2XHXC3SXQ4OLX7EL4RKUPZQT6GOH63KE3EVK37L5LG7TGSDGXFQP4377YK72UB5YZG6IJH6PY25YLLCJYPMDSHKPGYBUFJ4MMMKGN6MWB37CP7XVDBBZJ3U462ENTEXH744AWCQCIG2AAE2PKYVHC")
const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHDYZP7PPVMRGO4VWG2JRBMKFTOGIWZ5L2XHXC3SXQ4OLX7EL4RKUPZQT6GOH63KE3EVK37L5LG7TGSDGXFQP4377YK72UB5YZG6IJH6PY25YLLCJYPMDSHKPGYBUFJ4MMMKGN6MWB37CP7XVDBBZJ3U462ENTEXH744AWCQCIG2AAE2PKYVHC"
api.SetCookie(accessStorePageCookieName, cookieValue)
api.SetCookie(accessStorePageCookieName2, cookieValue)
}
func TestTest(t *testing.T) {

View File

@@ -140,21 +140,8 @@ var (
monthSaleNumReg = regexp.MustCompile(`(\d+)([千|万])`)
)
func (a *API) SetStoreCookie(storeCookie string) {
a.locker.Lock()
defer a.locker.Unlock()
a.storeCookie = storeCookie
}
func (a *API) GetStoreCookie() string {
a.locker.RLock()
defer a.locker.RUnlock()
return a.storeCookie
}
func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
storeCookie := a.GetStoreCookie()
if storeCookie == "" {
if a.GetCookieCount() == 0 {
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
}
err = platformapi.AccessPlatformAPIWithRetry(a.client,
@@ -170,14 +157,7 @@ func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isP
if err != nil {
return nil
}
request.AddCookie(&http.Cookie{
Name: accessStorePageCookieName,
Value: storeCookie,
})
request.AddCookie(&http.Cookie{
Name: accessStorePageCookieName2,
Value: storeCookie,
})
a.FillRequestCookies(request)
return request
},
a.config,