From 3cf7eb8779f25c16c71083b0505acdd8f6eec9a1 Mon Sep 17 00:00:00 2001 From: czqu <13680422+czqu@users.noreply.github.com> Date: Sat, 7 May 2022 23:42:19 +0800 Subject: [PATCH] fix 405 --- README.md | 1 + config.example.yaml | 2 +- src/monitor/check.go | 20 ++++++++++++++++++-- src/monitor/check_test.go | 40 +++++++++++++++++++++++++++++++++++++++ src/monitor/config.go | 9 ++++++--- 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c45e69b..4b302d5 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ 1. 自己使用Charles、Fiddler等工具对叮咚买菜小程序、App抓包,获取config.yaml中需要的参数。 2. 不想抓包或者不会抓包可以直接在配置文件填写家里的经纬度。经纬度获取: https://lbs.amap.com/tools/picker 3. 不想build可以直接下release包 https://github.com/czqu/dingdongMonitor/releases +4. 目前好像不填写经纬度就会405 # 运行 目前提供两种方式运行, ### 本机运行 diff --git a/config.example.yaml b/config.example.yaml index 165b15c..75b1602 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -1,4 +1,4 @@ -mode: 1 #mode=0 本机模式,启动后会根据rate设置的时间运行 mode=1 github_action模式,每次启动只运行一次 +mode: 0 #mode=0 本机模式,启动后会根据rate设置的时间运行 mode=1 github_action模式,每次启动只运行一次 station_id: #站点id 通过抓包得到,也可以不填写此字段,只填写下面的经纬度,填写此字段后经纬度的配置不会生效 # rate在GitHub模式下不生效 需要在GitHub action配置文件配置 rate: 3600 # 监控频率,单位:秒 diff --git a/src/monitor/check.go b/src/monitor/check.go index 7a641a7..85ce5d2 100644 --- a/src/monitor/check.go +++ b/src/monitor/check.go @@ -25,9 +25,17 @@ func CheckTransportCapacity() (bool, error) { Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}, } req.Header.Add("user-agent", UA) + req.Header.Add("alipayminimark", ALIMINIMARK) + req.Header.Add("referer", REFERER) req.Header.Add("ddmc-app-client-id", strconv.Itoa(APP_CLIENT_ID)) + req.Header.Add("ddmc-city-number", CITY) + req.Header.Add("ddmc-api-version", API_VERSION) + req.Header.Add("ddmc-build-version", BUILD_VERSION) + query := req.URL.Query() + query.Add("openid", OPEN_ID) query.Add("api_version", API_VERSION) + query.Add("app_version", BUILD_VERSION) query.Add("station_id", Conf.StationId) query.Add("city_number", CITY) query.Add("buildVersion", BUILD_VERSION) @@ -137,19 +145,26 @@ func CheckStock(page int, keyWords []Keyword) (isSucccess bool, isMore bool, pro Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}, } req.Header.Add("user-agent", UA) + req.Header.Add("alipayminimark", ALIMINIMARK) + req.Header.Add("referer", REFERER) + req.Header.Add("ddmc-app-client-id", strconv.Itoa(APP_CLIENT_ID)) req.Header.Add("ddmc-city-number", CITY) req.Header.Add("ddmc-api-version", API_VERSION) req.Header.Add("ddmc-build-version", BUILD_VERSION) - req.Header.Add("ddmc-app-client-id", strconv.Itoa(APP_CLIENT_ID)) req.Header.Add("ddmc-station-id", Conf.StationId) query := req.URL.Query() query.Add("api_version", API_VERSION) + query.Add("app_version", BUILD_VERSION) query.Add("station_id", Conf.StationId) query.Add("city_number", CITY) query.Add("buildVersion", BUILD_VERSION) query.Add("app_client_id", strconv.Itoa(APP_CLIENT_ID)) - query.Add("tab_type", "1") + query.Add("s_id", OPEN_ID) + query.Add("open_id", OPEN_ID) + query.Add("longitude", Conf.Longitude) + query.Add("latitude", Conf.Latitude) query.Add("page", strconv.Itoa(page)) + query.Add("tab_type", "1") req.URL.RawQuery = query.Encode() resp, err := client.Do(req) if err != nil { @@ -164,6 +179,7 @@ func CheckStock(page int, keyWords []Keyword) (isSucccess bool, isMore bool, pro } if resp.StatusCode != 200 { + fmt.Println(string(body)) return false, false, nil, 0 } defer func(Body io.ReadCloser) { diff --git a/src/monitor/check_test.go b/src/monitor/check_test.go index 456bf5e..bd397e7 100644 --- a/src/monitor/check_test.go +++ b/src/monitor/check_test.go @@ -1,9 +1,49 @@ package monitor import ( + "fmt" + "github.com/shopspring/decimal" + "strconv" "testing" ) func TestGetStationId(t *testing.T) { + _ = GetStationId("121.43818", "31.19169") } +func TestCheckStock(t *testing.T) { + conf := ConfigFromFile("../../config.example.yaml") + Conf = &conf + Conf.StationId = GetStationId("121.43818", "31.19169") + + keywords := Conf.KeyWords + var newKeywords []Keyword + for _, keyword := range keywords { + if keyword.Name == "" { + continue + + } + d, err := decimal.NewFromString(keyword.Price) + if err != nil || d.IsNegative() { + continue + } + + newKeywords = append(newKeywords, keyword) + + } + ok, _, _, total := CheckStock(1, newKeywords) + if !ok { + panic("error") + } + fmt.Println("total:" + strconv.Itoa(total)) + +} +func TestCheckTransportCapacity(t *testing.T) { + conf := ConfigFromFile("../../config.example.yaml") + Conf = &conf + Conf.StationId = GetStationId("121.43818", "31.19169") + _, err := CheckTransportCapacity() + if err != nil { + fmt.Println(err) + } +} diff --git a/src/monitor/config.go b/src/monitor/config.go index cd9c4ba..bce068d 100644 --- a/src/monitor/config.go +++ b/src/monitor/config.go @@ -10,10 +10,10 @@ import ( ) const ( - UA = "neighborhood/9.50.2 (iPhone; iOS 15.4.1; Scale/3.00)" + UA = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/19E258 Ariver/1.1.0 AliApp(AP/10.2.60.6200) Nebula WK RVKType(0) AlipayDefined(nt:WIFI,ws:390|780|3.0,ac:T) AlipayClient/10.2.60.6200 Language/zh-Hans Region/CN NebulaX/1.0.0" CITY = "0101" - API_VERSION = "9.50.2" - BUILD_VERSION = "1232" + API_VERSION = "9.51.0" + BUILD_VERSION = "2.86.3" TIME_OUT = 10 * time.Second BOOKABLE = "可预约" NOTICE_BOOKABLE = "可以预约啦" @@ -22,6 +22,9 @@ const ( LOCAL_MODE = 0 GITHUB_MODE = 1 APP_CLIENT_ID = 10 + ALIMINIMARK = "DDNMSL" + OPEN_ID = "6666666666666666" + REFERER = "https://2021001157662937.hybrid.alipay-eco.com/2021001157662937/0.2.2205051588.15/index.html#pages/mainPackage/home/home" ) var Conf = new(config)