美团配送cookie设置
This commit is contained in:
@@ -2,10 +2,52 @@ package mtpsapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
||||
if a.GetCookieCount() == 0 {
|
||||
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
||||
}
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
var request *http.Request
|
||||
if isPost {
|
||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(bizParams).Encode()))
|
||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||
request.Header.Set("Referer", "https://page.peisong.meituan.com/open/admin/poilist")
|
||||
} else {
|
||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", bizParams), nil)
|
||||
}
|
||||
a.FillRequestCookies(request)
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
if strings.Contains(bodyStr, "登录") || strings.Contains(bodyStr, "访问的内容") {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("cookie可能过期了!")
|
||||
}
|
||||
if err == nil {
|
||||
if jsonResult1["error_response"] != nil {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
err = utils.NewErrorCode(jsonResult1["error_response"].(map[string]interface{})["zh_desc"].(string), jsonResult1["error_response"].(map[string]interface{})["code"].(string))
|
||||
baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
return errLevel, err
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func (a *API) PagePoiUpdate(outerPoiID, contactName, contactPhone, contactEmail string) (err error) {
|
||||
if outerPoiID == "" || contactName == "" || contactPhone == "" || contactEmail == "" {
|
||||
return fmt.Errorf("所有参数必须都要有值")
|
||||
@@ -16,10 +58,21 @@ func (a *API) PagePoiUpdate(outerPoiID, contactName, contactPhone, contactEmail
|
||||
"contactPhone": contactPhone,
|
||||
"contactEmail": contactEmail,
|
||||
}
|
||||
if token, err := a.RefreshToken(); err == nil {
|
||||
a.token = token
|
||||
}
|
||||
_, err = a.AccessAPI2("https://page.peisong.meituan.com/api", "haikuiopen/haikui/open/partner/poi/update", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RefreshToken() (token string, err error) {
|
||||
result, err := a.AccessStorePage("https://peisong.meituan.com/api/haikuiopen/haikui/open/auth/csrf/token/refresh", nil, true)
|
||||
if err == nil {
|
||||
token = result["tokens"].(map[string]interface{})["csrfToken"].(string)
|
||||
}
|
||||
return token, err
|
||||
}
|
||||
|
||||
func (a *API) GetAccountDetail() (err error) {
|
||||
params := map[string]interface{}{}
|
||||
_, err = a.AccessAPI2("https://peisong.meituan.com/api", "haikuiopen/haikui/open/partner/base/detail", params)
|
||||
|
||||
Reference in New Issue
Block a user