美团cookie取消

This commit is contained in:
suyl
2020-05-31 10:30:35 +08:00
17 changed files with 539 additions and 55 deletions

View File

@@ -182,6 +182,7 @@ type API struct {
appKey string
secret string
token string
client *http.Client
config *platformapi.APIConfig
}
@@ -227,9 +228,9 @@ func (a *API) signParams(params url.Values) string {
}
func (a *API) AccessAPI2(baseURL, action string, params map[string]interface{}) (retVal *ResponseResult, err error) {
if params == nil {
panic("params is nil!")
}
// if params == nil {
// panic("params is nil!")
// }
params2 := utils.Map2URLValues(params)
if baseURL == mtpsAPIURL {
@@ -248,6 +249,7 @@ func (a *API) AccessAPI2(baseURL, action string, params map[string]interface{})
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")
if baseURL != mtpsAPIURL {
request.Header.Set("csrfToken", a.token)
a.FillRequestCookies(request)
}
return request

View File

@@ -25,7 +25,7 @@ func init() {
// prod
// api = New("3c0a05d464c247c19d7ec13accc78605", "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE")
api.SetCookie("token", "GsfR99YCT8leEBnY39YxPeWTJiSmetA3NGl8G8u1Mv29V4KLYIA9rH3fhw-uDL7VwM4jKPfNwH8D_vOPg3cRYg")
api.SetCookie("token", "oo3x6pAld4SskzvbEOnSslWUUQwc6w2m7uCfppCEnvRWzHVqctujL0xzLCkro6qj7mowU51zl99ExVUxgJjJ_Q")
}
func handleError(t *testing.T, err error) {

View File

@@ -1,10 +1,58 @@
package mtpsapi
import (
<<<<<<< HEAD
=======
"fmt"
"net/http"
"strings"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi"
>>>>>>> 6b4ee9a49b7be7d021c71cd098aeef6c9e75e5c2
"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) {
<<<<<<< HEAD
// if outerPoiID == "" || contactName == "" || contactPhone == "" || contactEmail == "" {
// return fmt.Errorf("所有参数必须都要有值")
// }
@@ -15,9 +63,32 @@ func (a *API) PagePoiUpdate(outerPoiID, contactName, contactPhone, contactEmail
// "contactEmail": contactEmail,
// }
// _, err = a.AccessAPI2("https://page.peisong.meituan.com/api", "haikuiopen/haikui/open/partner/poi/update", params)
=======
if outerPoiID == "" || contactName == "" || contactPhone == "" || contactEmail == "" {
return fmt.Errorf("所有参数必须都要有值")
}
params := map[string]interface{}{
"outerPoiId": outerPoiID,
"contactName": contactName,
"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)
>>>>>>> 6b4ee9a49b7be7d021c71cd098aeef6c9e75e5c2
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)

View File

@@ -27,3 +27,11 @@ func TestGetStoreStatus(t *testing.T) {
}
t.Log(utils.Format4Output(result, false))
}
func TestRefreshToken(t *testing.T) {
result, err := api.RefreshToken()
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}