+ 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

@@ -37,23 +37,8 @@ type ListShopItem struct {
WmPoiScore int `json:"wmPoiScore"`
}
func (a *API) SetUserCookie(key, value string) {
a.locker.Lock()
defer a.locker.Unlock()
a.userCookies[key] = value
}
func (a *API) GetUserCookie(key string) string {
a.locker.RLock()
defer a.locker.RUnlock()
return a.userCookies[key]
}
func (a *API) AccessUserPage(subURL string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
a.locker.RLock()
storeCookieLen := len(a.userCookies)
a.locker.RUnlock()
if storeCookieLen == 0 {
if a.GetCookieCount() == 0 {
return nil, fmt.Errorf("需要设置User Cookie才能使用此方法")
}
err = platformapi.AccessPlatformAPIWithRetry(a.client,
@@ -66,14 +51,7 @@ func (a *API) AccessUserPage(subURL string, params map[string]interface{}) (retV
request.Header.Set("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1")
request.Header.Set("Pragma", "no-cache")
a.locker.RLock()
for k, v := range a.userCookies {
request.AddCookie(&http.Cookie{
Name: k,
Value: v,
})
}
a.locker.RUnlock()
a.FillRequestCookies(request)
return request
},
a.config,