银豹api增加cookie判断

This commit is contained in:
苏尹岚
2020-03-30 11:11:02 +08:00
parent cea0ff95cf
commit bac5ec2659

View File

@@ -57,6 +57,10 @@ func (a *API) AccessStorePage(action string, bizParams map[string]interface{}) (
return retVal, err
}
func IsErrCookie(err error) (isExist bool) {
return utils.IsErrMatch(err, "-1", []string{"银豹Cookie可能失效了"})
}
type LoadSubStoresByUserIdDDLJsonResult struct {
Balance float64 `json:"balance"`
Storewebsite interface{} `json:"storewebsite"`
@@ -360,3 +364,45 @@ func (a *API) SaveProduct(userId, keyword string) (err error) {
//Sec-Fetch-Site: same-origin
//User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
//X-Requested-With: XMLHttpRequest
func (a *API) TryGetCookie() (cookie string, err error) {
params := map[string]interface{}{
"userName": 18048531223,
"password": "Rosy201507",
"returnUrl": "",
"screenSize": "1600*900",
}
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, "https://beta27.pospal.cn/account/SignIn?noLog=", strings.NewReader(utils.Map2URLValues(params).Encode()))
request.Header.Set("Accept", "application/json, text/javascript, */*; q=0.01")
request.Header.Set("Accept-Encoding", "gzip, deflate, br")
request.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
request.Header.Set("Connection", "keep-alive")
request.Header.Set("Content-Length", "56")
request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
request.Header.Set("Host", "beta27.pospal.cn")
request.Header.Set("Origin", "https://beta27.pospal.cn")
request.Header.Set("Referer", "https://beta27.pospal.cn/account/signin")
request.Header.Set("Sec-Fetch-Mode", "cors")
request.Header.Set("Sec-Fetch-Site", "same-origin")
request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36")
request.Header.Set("X-Requested-With", "XMLHttpRequest")
return request
},
a.config,
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
cookies := response.Cookies()
fmt.Println(utils.Format4Output(cookies, false))
for _, v := range cookies {
if v.Name == ".POSPALAUTH30220" && v.Value != "" {
return v.Value, err
}
}
return errLevel, err
})
return "", err
}
func isErrCookie(err error) {
}