mtwmapi.OrderModityTips and GetDistributeOrderDetail
This commit is contained in:
@@ -1,20 +1,9 @@
|
|||||||
package mtwmapi
|
package mtwmapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi"
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
orderURL = "https://shangoue.meituan.com/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DistributeOrderDetail struct {
|
type DistributeOrderDetail struct {
|
||||||
WmOrderID int `json:"wm_order_id"`
|
WmOrderID int `json:"wm_order_id"`
|
||||||
WmPoiID int `json:"wm_poi_id"`
|
WmPoiID int `json:"wm_poi_id"`
|
||||||
@@ -49,74 +38,32 @@ type DistributeOrderDetail struct {
|
|||||||
DelayPushSecond int `json:"delay_push_second"`
|
DelayPushSecond int `json:"delay_push_second"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) AccessOrderPage(subURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
|
||||||
if a.GetCookieCount() == 0 {
|
|
||||||
return nil, fmt.Errorf("需要设置User Cookie才能使用此方法")
|
|
||||||
}
|
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
|
||||||
func() *http.Request {
|
|
||||||
var request *http.Request
|
|
||||||
if !isPost {
|
|
||||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(orderURL, subURL, params), nil)
|
|
||||||
} else {
|
|
||||||
fullURL := utils.GenerateGetURL(orderURL, subURL, nil)
|
|
||||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
|
||||||
}
|
|
||||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
|
||||||
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("Pragma", "no-cache")
|
|
||||||
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
retVal = jsonResult1
|
|
||||||
code := int(utils.MustInterface2Int64(jsonResult1["code"]))
|
|
||||||
if code == ResponseCodeSuccess {
|
|
||||||
retVal, _ = jsonResult1["data"].(map[string]interface{})
|
|
||||||
return platformapi.ErrLevelSuccess, nil
|
|
||||||
}
|
|
||||||
newErr := utils.NewErrorIntCode(jsonResult1["msg"].(string), code)
|
|
||||||
baseapi.SugarLogger.Debugf("mt AccessStorePage failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
|
||||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
|
||||||
})
|
|
||||||
return retVal, err
|
|
||||||
}
|
|
||||||
|
|
||||||
//美团骑手修改小费,单位为元,最多小数点后一位
|
//美团骑手修改小费,单位为元,最多小数点后一位
|
||||||
//order/receive/processed/w/distribute/tipAmount/v2?ignoreSetRouterProxy=true
|
//order/receive/processed/w/distribute/tipAmount/v2?ignoreSetRouterProxy=true
|
||||||
func (a *API) OrderModityTips(orderID, poiID string, tipAmount float64) (err error) {
|
func (a *API) OrderModityTips(orderID, poiCode string, tipAmount float64) (err error) {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"wmOrderViewId": orderID,
|
"wmOrderViewId": orderID,
|
||||||
"wmPoiId": poiID,
|
"wmPoiId": poiCode,
|
||||||
"tipAmount": tipAmount,
|
"tipAmount": tipAmount,
|
||||||
}
|
}
|
||||||
_, err = a.AccessOrderPage("order/receive/processed/w/distribute/tipAmount/v2", params, true)
|
_, err = a.AccessUserPage2("order/receive/processed/w/distribute/tipAmount/v2", params, true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取美团订单小费
|
//获取美团订单小费
|
||||||
//https://shangoue.meituan.com/v2/order/receive/processed/r/distribute/list/v2
|
//https://shangoue.meituan.com/v2/order/receive/processed/r/distribute/list/v2
|
||||||
func (a *API) GetDistributeOrderDetail(orderID, poiID string) (distributeOrderDetail *DistributeOrderDetail, err error) {
|
func (a *API) GetDistributeOrderDetail(orderID, poiCode string) (distributeOrderDetail *DistributeOrderDetail, err error) {
|
||||||
params1 := map[string]interface{}{
|
params1 := map[string]interface{}{
|
||||||
"wmOrderViewId": orderID,
|
"wmOrderViewId": orderID,
|
||||||
"wmPoiId": poiID,
|
"wmPoiId": poiCode,
|
||||||
}
|
|
||||||
result1, err := json.MarshalIndent(params1, "", "")
|
|
||||||
if err != nil {
|
|
||||||
return distributeOrderDetail, err
|
|
||||||
}
|
}
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"orderInfos": []string{string(result1)},
|
"orderInfos": []string{string(utils.MustMarshal(params1))},
|
||||||
}
|
}
|
||||||
result, err2 := a.AccessOrderPage("order/receive/processed/r/distribute/list/v2", params, false)
|
result, err2 := a.AccessUserPage2("order/receive/processed/r/distribute/list/v2", params, false)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return distributeOrderDetail, err
|
return distributeOrderDetail, err
|
||||||
}
|
}
|
||||||
utils.Map2StructByJson(result[orderID], &distributeOrderDetail, true)
|
err = utils.Map2StructByJson(result[orderID], &distributeOrderDetail, true)
|
||||||
return distributeOrderDetail, err
|
return distributeOrderDetail, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
userURL = "http://i.waimai.meituan.com"
|
userURL = "http://i.waimai.meituan.com"
|
||||||
|
orderURL = "https://shangoue.meituan.com/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -37,20 +38,31 @@ type ListShopItem struct {
|
|||||||
WmPoiScore int `json:"wmPoiScore"`
|
WmPoiScore int `json:"wmPoiScore"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) AccessUserPage(subURL string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
|
func getRootURL(subURL string) (rootURL string) {
|
||||||
|
if strings.Index(subURL, "order/receive/processed/r/distribute") >= 0 {
|
||||||
|
return orderURL
|
||||||
|
}
|
||||||
|
return userURL
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) AccessUserPage2(subURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
||||||
if a.GetCookieCount() == 0 {
|
if a.GetCookieCount() == 0 {
|
||||||
return nil, fmt.Errorf("需要设置User Cookie才能使用此方法")
|
return nil, fmt.Errorf("需要设置User Cookie才能使用此方法")
|
||||||
}
|
}
|
||||||
|
rootURL := getRootURL(subURL)
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
func() *http.Request {
|
func() *http.Request {
|
||||||
var request *http.Request
|
var request *http.Request
|
||||||
fullURL := utils.GenerateGetURL(userURL, subURL, nil)
|
if isPost {
|
||||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
fullURL := utils.GenerateGetURL(rootURL, subURL, nil)
|
||||||
request.Header.Set("charset", "UTF-8")
|
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
request.Header.Set("charset", "UTF-8")
|
||||||
request.Header.Set("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1")
|
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
request.Header.Set("Pragma", "no-cache")
|
request.Header.Set("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1")
|
||||||
|
request.Header.Set("Pragma", "no-cache")
|
||||||
|
} else {
|
||||||
|
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(rootURL, subURL, params), nil)
|
||||||
|
}
|
||||||
a.FillRequestCookies(request)
|
a.FillRequestCookies(request)
|
||||||
return request
|
return request
|
||||||
},
|
},
|
||||||
@@ -66,12 +78,16 @@ func (a *API) AccessUserPage(subURL string, params map[string]interface{}) (retV
|
|||||||
return platformapi.ErrLevelSuccess, nil
|
return platformapi.ErrLevelSuccess, nil
|
||||||
}
|
}
|
||||||
newErr := utils.NewErrorIntCode(jsonResult1["msg"].(string), code)
|
newErr := utils.NewErrorIntCode(jsonResult1["msg"].(string), code)
|
||||||
baseapi.SugarLogger.Debugf("ebai AccessStorePage failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
baseapi.SugarLogger.Debugf("mtwm AccessUserPage failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||||
})
|
})
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) AccessUserPage(subURL string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
|
return a.AccessUserPage2(subURL, params, true)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) GetStoreList(lng, lat float64) (shopList []*ListShopItem, err error) {
|
func (a *API) GetStoreList(lng, lat float64) (shopList []*ListShopItem, err error) {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"sortId": 1,
|
"sortId": 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user