+ APICookie
This commit is contained in:
@@ -34,6 +34,8 @@ type ResponseResult struct {
|
||||
}
|
||||
|
||||
type API struct {
|
||||
platformapi.APICookie
|
||||
|
||||
source string
|
||||
secret string
|
||||
encrypt string
|
||||
|
||||
@@ -34,8 +34,8 @@ func init() {
|
||||
// 京西果园
|
||||
// api = New("35957", "10013fbb7c2ddad7")
|
||||
|
||||
api.SetStoreCookie("WMUSS", "4AAPQCAAB5PF0aUGcBVzoRTCEkOFhFIhx-Yk9vN2EfPHYoLlROKBEsQmAUQjhNUgRt0ADAP5x-RFklwAAdjxGO11iOj8xKXYSSDIJb2BcPghsaklNfQwGS10JOVRFfhAiYElhEXFXIzoJKyloCGdwdFE6Qk9FRxojUFN3FVEHNjJPZJu4Bt9nxQ13cwoMbjA")
|
||||
api.SetStoreCookie("WMSTOKEN", "AcAANQZAABbC04rUBZFc2UYanlocDAaP0dcfzZCeS1SHQ1qJ15ExgAA13A2dGLjdbcitBZJu4Bn6B_g6cZAAA0tyyFm8cdBaNAQAAwug8HTG0xRjwt1UZzbcAAN7ofRO")
|
||||
api.SetCookie("WMUSS", "4AAPQCAAB5PF0aUGcBVzoRTCEkOFhFIhx-Yk9vN2EfPHYoLlROKBEsQmAUQjhNUgRt0ADAP5x-RFklwAAdjxGO11iOj8xKXYSSDIJb2BcPghsaklNfQwGS10JOVRFfhAiYElhEXFXIzoJKyloCGdwdFE6Qk9FRxojUFN3FVEHNjJPZJu4Bt9nxQ13cwoMbjA")
|
||||
api.SetCookie("WMSTOKEN", "AcAANQZAABbC04rUBZFc2UYanlocDAaP0dcfzZCeS1SHQ1qJ15ExgAA13A2dGLjdbcitBZJu4Bn6B_g6cZAAA0tyyFm8cdBaNAQAAwug8HTG0xRjwt1UZzbcAAN7ofRO")
|
||||
}
|
||||
|
||||
func TestTest(t *testing.T) {
|
||||
|
||||
@@ -298,23 +298,8 @@ type PageShopInfo struct {
|
||||
TakeoutPrice int `json:"takeout_price"`
|
||||
}
|
||||
|
||||
func (a *API) SetStoreCookie(key, value string) {
|
||||
a.locker.Lock()
|
||||
defer a.locker.Unlock()
|
||||
a.storeCookies[key] = value
|
||||
}
|
||||
|
||||
func (a *API) GetStoreCookie(key string) string {
|
||||
a.locker.RLock()
|
||||
defer a.locker.RUnlock()
|
||||
return a.storeCookies[key]
|
||||
}
|
||||
|
||||
func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isPost bool, cookies map[string]string) (retVal map[string]interface{}, err error) {
|
||||
a.locker.RLock()
|
||||
storeCookieLen := len(a.storeCookies)
|
||||
a.locker.RUnlock()
|
||||
if storeCookieLen == 0 {
|
||||
if a.GetCookieCount() == 0 {
|
||||
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
||||
}
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
@@ -327,20 +312,13 @@ func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isP
|
||||
request.Header.Set("charset", "UTF-8")
|
||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
a.locker.RLock()
|
||||
for k, v := range a.storeCookies {
|
||||
request.AddCookie(&http.Cookie{
|
||||
Name: k,
|
||||
Value: v,
|
||||
})
|
||||
}
|
||||
a.FillRequestCookies(request)
|
||||
for k, v := range cookies {
|
||||
request.AddCookie(&http.Cookie{
|
||||
Name: k,
|
||||
Value: v,
|
||||
})
|
||||
}
|
||||
a.locker.RUnlock()
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
|
||||
Reference in New Issue
Block a user