aa
This commit is contained in:
@@ -2,6 +2,7 @@ package mtunionapi
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
@@ -15,9 +16,13 @@ import (
|
||||
const (
|
||||
prodURL = "https://runion.meituan.com"
|
||||
sigKey = "sign"
|
||||
|
||||
ActTypeQB = 1 //券包推广
|
||||
)
|
||||
|
||||
type API struct {
|
||||
platformapi.APICookie
|
||||
|
||||
appKey string
|
||||
appSecret string
|
||||
client *http.Client
|
||||
@@ -93,6 +98,44 @@ func (a *API) AccessAPI(action string, isPost bool, bizParams map[string]interfa
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
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才能使用此方法")
|
||||
}
|
||||
data, _ := json.Marshal(bizParams)
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
var request *http.Request
|
||||
if isPost {
|
||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(string(data)))
|
||||
request.Header.Set("Content-Type", "application/json;charset=utf-8")
|
||||
} 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
|
||||
}
|
||||
|
||||
//https://union.meituan.com/v2/apiDetail?id=8
|
||||
//https://runion.meituan.com/generateLink
|
||||
func (a *API) GenerateLink(actID int, userID string) (url string, err error) {
|
||||
@@ -102,3 +145,27 @@ func (a *API) GenerateLink(actID int, userID string) (url string, err error) {
|
||||
})
|
||||
return url, err
|
||||
}
|
||||
|
||||
type ActivityListResult struct {
|
||||
ID int `json:"id"`
|
||||
ActName string `json:"actName"`
|
||||
ActDes string `json:"actDes"`
|
||||
URL string `json:"url"`
|
||||
ActRule string `json:"actRule"`
|
||||
Ratio string `json:"ratio"`
|
||||
DateBound string `json:"dateBound"`
|
||||
ActSrc string `json:"actSrc"`
|
||||
}
|
||||
|
||||
//https://union.meituan.com/api/activity/list
|
||||
func (a *API) ActivityList(actType, limit, offset int) (activityListResult []*ActivityListResult, err error) {
|
||||
result, err := a.AccessStorePage("https://union.meituan.com/api/activity/list", map[string]interface{}{
|
||||
"actType": actType,
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
}, true)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"].(map[string]interface{})["dataList"], &activityListResult, false)
|
||||
}
|
||||
return activityListResult, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user