Files
baseapi/platformapi/mtpsapi/shop_page.go
2020-05-31 10:31:54 +08:00

108 lines
4.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package mtpsapi
import (
"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("所有参数必须都要有值")
// }
// params := map[string]interface{}{
// "outerPoiId": outerPoiID,
// "contactName": contactName,
// "contactPhone": contactPhone,
// "contactEmail": contactEmail,
// }
// _, 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)
return err
}
type GetStoreStatusResult struct {
PoiID int `json:"poiId"`
OuterPoiID string `json:"outerPoiId"`
AppkeyID int `json:"appkeyId"`
PoiName string `json:"poiName"`
CityID int `json:"cityId"`
CityName string `json:"cityName"`
ContactPhone string `json:"contactPhone"`
ContactName interface{} `json:"contactName"`
ContactEmail interface{} `json:"contactEmail"`
Address string `json:"address"`
AddressDetail interface{} `json:"addressDetail"`
OpenType int `json:"openType"`
CategoryID int `json:"categoryId"`
SecondCategoryID int `json:"secondCategoryId"`
PoiLat int `json:"poiLat"`
PoiLng int `json:"poiLng"`
SubBrandID int `json:"subBrandId"`
PoiType int `json:"poiType"`
}
func (a *API) GetStoreStatus(poiName string) (getStoreStatusResult *GetStoreStatusResult, err error) {
params := map[string]interface{}{
"poiName": poiName,
"openType": -1,
"cityId": -1,
"pageNum": 1,
"pageSize": 20,
}
result, err := a.AccessAPI2("https://page.peisong.meituan.com/api", "haikuiopen/haikui/open/partner/poi/search", params)
if err == nil {
utils.Map2StructByJson(result.Data, &getStoreStatusResult, false)
}
return getStoreStatusResult, err
}