This commit is contained in:
苏尹岚
2021-03-29 16:13:26 +08:00
parent 9c34435ca4
commit 99e23faf82
4 changed files with 120 additions and 3 deletions

View File

@@ -51,6 +51,45 @@ func (a *API) AccessActPage(subURL string, params map[string]interface{}, isPost
return retVal, err
}
func (a *API) AccessActPage2(subURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
if a.GetCookieCount() == 0 {
return nil, fmt.Errorf("需要设置User Cookie才能使用此方法")
}
rootURL := getRootURL(subURL)
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
var request *http.Request
if isPost {
fullURL := utils.GenerateGetURL(rootURL, subURL, nil)
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
} else {
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(rootURL, subURL, params), 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")
}
retVal = jsonResult1
if jsonResult1["code"] == nil {
return platformapi.ErrLevelGeneralFail, fmt.Errorf("返回结果格式不正常")
}
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("mtwm AccessUserPage failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
return platformapi.ErrLevelCodeIsNotOK, newErr
})
return retVal, err
}
type GetCenterListResult struct {
ActivityStartTime int `json:"activityStartTime"`
ActivityEndTime int `json:"activityEndTime"`
@@ -100,3 +139,72 @@ func (a *API) GetCenterList(vendorStoreID string) (getCenterListResult []*GetCen
}
return getCenterListResult, err
}
type GetInviteDetailResult struct {
ID int `json:"id"`
InviteID int `json:"inviteId"`
PoiID int `json:"poiId"`
SegmentID int `json:"segmentId"`
Name string `json:"name"`
BriefIntroduction string `json:"briefIntroduction"`
EndTime int `json:"endTime"`
CreateTime int `json:"createTime"`
Status int `json:"status"`
ActivityStartTime int `json:"activityStartTime"`
ActivityEndTime int `json:"activityEndTime"`
ActivityType string `json:"activityType"`
RegistrationForm string `json:"registrationForm"`
ActivityRule string `json:"activityRule"`
ActivityIntroduction string `json:"activityIntroduction"`
OperationAdvice string `json:"operationAdvice"`
SegmentType int `json:"segmentType"`
Faq string `json:"faq"`
IsEntered int `json:"isEntered"`
EnterTime int `json:"enterTime"`
ApproveStatus int `json:"approveStatus"`
EnterID int `json:"enterId"`
MatchPoiBaseFilter int `json:"matchPoiBaseFilter"`
WeekTimes string `json:"weekTimes"`
PoiApplyStatus int `json:"poiApplyStatus"`
Period string `json:"period"`
PoiInviteType int `json:"poiInviteType"`
PoiPolicyType int `json:"poiPolicyType"`
MtCostAdd int `json:"mtCostAdd"`
MtCostAddon int `json:"mtCostAddon"`
EnteredDataUnionStatus int `json:"enteredDataUnionStatus"`
ActivityDateList []interface{} `json:"activityDateList"`
CanEnter int `json:"canEnter"`
IsCanCancel int `json:"isCanCancel"`
IsCanModify int `json:"isCanModify"`
StatisticsData struct {
TotalOrderNum int `json:"totalOrderNum"`
TotalIncome float64 `json:"totalIncome"`
AveragePrice float64 `json:"averagePrice"`
Cost float64 `json:"cost"`
InOutRatio float64 `json:"inOutRatio"`
TotalGoodsSoldNum int `json:"totalGoodsSoldNum"`
TotalObtainNum int `json:"totalObtainNum"`
TotalUsedNum int `json:"totalUsedNum"`
UseRate float64 `json:"useRate"`
Stock int `json:"stock"`
CouponNum int `json:"couponNum"`
DayCount int `json:"dayCount"`
IsShow int `json:"isShow"`
} `json:"statisticsData"`
NeedApprove int `json:"needApprove"`
IsCollectorUpdated int `json:"isCollectorUpdated"`
IsPoiCanModify int `json:"isPoiCanModify"`
IsPoiCanCancel int `json:"isPoiCanCancel"`
}
func (a *API) GetInviteDetail(actID int, vendorStoreID string) (getCenterListResult *GetInviteDetailResult, err error) {
result, err := a.AccessActPage2("api/invite/detail", map[string]interface{}{
"wmPoiId": vendorStoreID,
"id": actID,
"usedForBatch": false,
}, true)
if err == nil {
utils.Map2StructByJson(result, &getCenterListResult, false)
}
return getCenterListResult, err
}

View File

@@ -7,7 +7,15 @@ import (
)
func TestGetCenterList(t *testing.T) {
result, err := api.GetCenterList("7634034")
result, err := api.GetCenterList("7169838")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}
func TestGetInviteDetail(t *testing.T) {
result, err := api.GetInviteDetail(11838, "7169838")
if err != nil {
t.Fatal(err)
}

View File

@@ -27,8 +27,8 @@ func init() {
//商超
// api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_tE0txRtx7CRuPIOjh2BH4w") //token_nH_IlcWQKAkZBqklwItNRw
cookieStr := `
uuid=e8034a4d222c4b51b81c.1574126611.1.0.0; _ga=GA1.2.827950563.1574128001; _lxsdk_cuid=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; _lxsdk=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; t_lxid=1719bfe9d5e30-0cf08957b60ff-3d375b01-15f900-1719bfe9d5fc8-tid; igateApp=recoanalysis; lsu=; mtcdn=K; token=0mSedih8udpe6yOnYDkGCYUi1ZoBjKT5Cvky4kBDolyA*; acctId=57396785; _source=PC; bsid=yfpaaPKXj1BNDzKZXSLxpftf3dEnZ22uHvnqWXHKQ9ndFU5rb_YFk5vDi01MoEc6K91Ly6a6aqXT07tw1UI4Vg; virtual=0; vacctId=0; acctName=null; terminal=bizCenter; logan_custom_report=; wmPoiId=7634034; logan_session_token=fwxhqemst6q8uff1oztv; _lxsdk_s=1787cb12bac-7cd-4f6-eb2%7C%7C172
`
uuid=e8034a4d222c4b51b81c.1574126611.1.0.0; _ga=GA1.2.827950563.1574128001; _lxsdk_cuid=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; _lxsdk=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; t_lxid=1719bfe9d5e30-0cf08957b60ff-3d375b01-15f900-1719bfe9d5fc8-tid; lsu=; mtcdn=K; _source=PC; virtual=0; vacctId=0; acctName=null; terminal=bizCenter; logan_custom_report=; igateApp=shangouepc; uuid_update=true; wpush_server_url=wss://wpush.meituan.com; shopCategory=market; device_uuid=!3fb10fb5-cd78-41e2-afd6-4d656136a3fc; e_u_id_3299326472=e5ae16afe444349d24af7d33b66620a1; token=06eu5I1k0_C9L1O__0BB-PWk8mqIpagIL3aKWuTPz8t8*; acctId=57396785; bsid=40I5kUwAJ5uq67jA3bNkn3hT3xpZCkAwhPCq5bGnfIXlBpdbIR9Zz-waWJqJYX6jIe6yK7KCsl4Q_ickenwIcA; wmPoiId=7169838; _lxsdk_s=1787cb12bac-7cd-4f6-eb2%7C%7C378; logan_session_token=1yndau3dxtsh4kg3znsl
`
api.SetCookieWithStr(cookieStr)
}

View File

@@ -47,6 +47,7 @@ var (
"reuse/sc/product/packageprice/r/get": orderURL,
"reuse/sc/product/retail/r/getStandardProductListWithCond": orderURL,
"api/sg/promotion/invite/centerList": actURL,
"api/invite/detail": actURL,
}
)