+ APICookie
This commit is contained in:
@@ -156,6 +156,8 @@ type GoodsDetail struct {
|
||||
}
|
||||
|
||||
type API struct {
|
||||
platformapi.APICookie
|
||||
|
||||
appKey string
|
||||
secret string
|
||||
client *http.Client
|
||||
@@ -196,22 +198,30 @@ func (a *API) signParams(params url.Values) string {
|
||||
return fmt.Sprintf("%x", sha1.Sum([]byte(finalStr)))
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *ResponseResult, err error) {
|
||||
func (a *API) AccessAPI2(baseURL, action string, params map[string]interface{}) (retVal *ResponseResult, err error) {
|
||||
if params == nil {
|
||||
panic("params is nil!")
|
||||
}
|
||||
|
||||
params2 := utils.Map2URLValues(params)
|
||||
params2.Set("appkey", a.appKey)
|
||||
params2.Set("timestamp", utils.Int64ToStr(utils.GetCurTimestamp()))
|
||||
params2.Set("version", "1.0")
|
||||
params2.Set(signKey, a.signParams(params2))
|
||||
if baseURL == mtpsAPIURL {
|
||||
params2.Set("appkey", a.appKey)
|
||||
params2.Set("timestamp", utils.Int64ToStr(utils.GetCurTimestamp()))
|
||||
params2.Set("version", "1.0")
|
||||
params2.Set(signKey, a.signParams(params2))
|
||||
} else if a.GetCookieCount() == 0 {
|
||||
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
||||
}
|
||||
// baseapi.SugarLogger.Debug(params2.Encode())
|
||||
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodPost, mtpsAPIURL+"/"+action, strings.NewReader(params2.Encode()))
|
||||
request, _ := http.NewRequest(http.MethodPost, baseURL+"/"+action, strings.NewReader(params2.Encode()))
|
||||
request.Header.Set("charset", "UTF-8")
|
||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
if baseURL != mtpsAPIURL {
|
||||
a.FillRequestCookies(request)
|
||||
}
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
@@ -236,6 +246,10 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *ResponseResult, err error) {
|
||||
return a.AccessAPI2(mtpsAPIURL, action, params)
|
||||
}
|
||||
|
||||
func (a *API) result2OrderResponse(result *ResponseResult) (order *OrderResponse) {
|
||||
order = new(OrderResponse)
|
||||
order.MtPeisongID = result.Data["mt_peisong_id"].(string)
|
||||
|
||||
@@ -24,6 +24,8 @@ func init() {
|
||||
api = New("25e816550bc9484480642f19a95f13fd", "r4$HqrKx9~=7?2Jfo,$Z~a7%~k!Au&pEdI2)oPJvSbH2ao@2N0[8wSIvtuumh_J^")
|
||||
// prod
|
||||
// api = New("3c0a05d464c247c19d7ec13accc78605", "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE")
|
||||
|
||||
api.SetCookie("token", "0seqGSJnhbr4XJ0EaIQL6CoOpnaV1ErgS42uOlzNXYIX7PeuLuyCFQQZKKWGExJ7IMTQQQDe5H6YMmVFnxjCkw")
|
||||
}
|
||||
|
||||
func handleError(t *testing.T, err error) {
|
||||
|
||||
17
platformapi/mtpsapi/shop_page.go
Normal file
17
platformapi/mtpsapi/shop_page.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package mtpsapi
|
||||
|
||||
import "fmt"
|
||||
|
||||
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://peisong.meituan.com/api", "haikuiopen/haikui/open/partner/poi/update", params)
|
||||
return err
|
||||
}
|
||||
12
platformapi/mtpsapi/shop_page_test.go
Normal file
12
platformapi/mtpsapi/shop_page_test.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package mtpsapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPagePoiUpdate(t *testing.T) {
|
||||
err := api.PagePoiUpdate("100082", "王海红", "16601189298", "727827081@qq.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user