Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.

Commit 3cf7eb8

Browse files
committed
fix 405
1 parent c91fa99 commit 3cf7eb8

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1. 自己使用Charles、Fiddler等工具对叮咚买菜小程序、App抓包,获取config.yaml中需要的参数。
1515
2. 不想抓包或者不会抓包可以直接在配置文件填写家里的经纬度。经纬度获取: https://lbs.amap.com/tools/picker
1616
3. 不想build可以直接下release包 https://github.com/czqu/dingdongMonitor/releases
17+
4. 目前好像不填写经纬度就会405
1718
# 运行
1819
目前提供两种方式运行,
1920
### 本机运行

config.example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mode: 1 #mode=0 本机模式,启动后会根据rate设置的时间运行 mode=1 github_action模式,每次启动只运行一次
1+
mode: 0 #mode=0 本机模式,启动后会根据rate设置的时间运行 mode=1 github_action模式,每次启动只运行一次
22
station_id: #站点id 通过抓包得到,也可以不填写此字段,只填写下面的经纬度,填写此字段后经纬度的配置不会生效
33
# rate在GitHub模式下不生效 需要在GitHub action配置文件配置
44
rate: 3600 # 监控频率,单位:秒

src/monitor/check.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ func CheckTransportCapacity() (bool, error) {
2525
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
2626
}
2727
req.Header.Add("user-agent", UA)
28+
req.Header.Add("alipayminimark", ALIMINIMARK)
29+
req.Header.Add("referer", REFERER)
2830
req.Header.Add("ddmc-app-client-id", strconv.Itoa(APP_CLIENT_ID))
31+
req.Header.Add("ddmc-city-number", CITY)
32+
req.Header.Add("ddmc-api-version", API_VERSION)
33+
req.Header.Add("ddmc-build-version", BUILD_VERSION)
34+
2935
query := req.URL.Query()
36+
query.Add("openid", OPEN_ID)
3037
query.Add("api_version", API_VERSION)
38+
query.Add("app_version", BUILD_VERSION)
3139
query.Add("station_id", Conf.StationId)
3240
query.Add("city_number", CITY)
3341
query.Add("buildVersion", BUILD_VERSION)
@@ -137,19 +145,26 @@ func CheckStock(page int, keyWords []Keyword) (isSucccess bool, isMore bool, pro
137145
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
138146
}
139147
req.Header.Add("user-agent", UA)
148+
req.Header.Add("alipayminimark", ALIMINIMARK)
149+
req.Header.Add("referer", REFERER)
150+
req.Header.Add("ddmc-app-client-id", strconv.Itoa(APP_CLIENT_ID))
140151
req.Header.Add("ddmc-city-number", CITY)
141152
req.Header.Add("ddmc-api-version", API_VERSION)
142153
req.Header.Add("ddmc-build-version", BUILD_VERSION)
143-
req.Header.Add("ddmc-app-client-id", strconv.Itoa(APP_CLIENT_ID))
144154
req.Header.Add("ddmc-station-id", Conf.StationId)
145155
query := req.URL.Query()
146156
query.Add("api_version", API_VERSION)
157+
query.Add("app_version", BUILD_VERSION)
147158
query.Add("station_id", Conf.StationId)
148159
query.Add("city_number", CITY)
149160
query.Add("buildVersion", BUILD_VERSION)
150161
query.Add("app_client_id", strconv.Itoa(APP_CLIENT_ID))
151-
query.Add("tab_type", "1")
162+
query.Add("s_id", OPEN_ID)
163+
query.Add("open_id", OPEN_ID)
164+
query.Add("longitude", Conf.Longitude)
165+
query.Add("latitude", Conf.Latitude)
152166
query.Add("page", strconv.Itoa(page))
167+
query.Add("tab_type", "1")
153168
req.URL.RawQuery = query.Encode()
154169
resp, err := client.Do(req)
155170
if err != nil {
@@ -164,6 +179,7 @@ func CheckStock(page int, keyWords []Keyword) (isSucccess bool, isMore bool, pro
164179
}
165180

166181
if resp.StatusCode != 200 {
182+
fmt.Println(string(body))
167183
return false, false, nil, 0
168184
}
169185
defer func(Body io.ReadCloser) {

src/monitor/check_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
11
package monitor
22

33
import (
4+
"fmt"
5+
"github.com/shopspring/decimal"
6+
"strconv"
47
"testing"
58
)
69

710
func TestGetStationId(t *testing.T) {
11+
_ = GetStationId("121.43818", "31.19169")
812

913
}
14+
func TestCheckStock(t *testing.T) {
15+
conf := ConfigFromFile("../../config.example.yaml")
16+
Conf = &conf
17+
Conf.StationId = GetStationId("121.43818", "31.19169")
18+
19+
keywords := Conf.KeyWords
20+
var newKeywords []Keyword
21+
for _, keyword := range keywords {
22+
if keyword.Name == "" {
23+
continue
24+
25+
}
26+
d, err := decimal.NewFromString(keyword.Price)
27+
if err != nil || d.IsNegative() {
28+
continue
29+
}
30+
31+
newKeywords = append(newKeywords, keyword)
32+
33+
}
34+
ok, _, _, total := CheckStock(1, newKeywords)
35+
if !ok {
36+
panic("error")
37+
}
38+
fmt.Println("total:" + strconv.Itoa(total))
39+
40+
}
41+
func TestCheckTransportCapacity(t *testing.T) {
42+
conf := ConfigFromFile("../../config.example.yaml")
43+
Conf = &conf
44+
Conf.StationId = GetStationId("121.43818", "31.19169")
45+
_, err := CheckTransportCapacity()
46+
if err != nil {
47+
fmt.Println(err)
48+
}
49+
}

src/monitor/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
)
1111

1212
const (
13-
UA = "neighborhood/9.50.2 (iPhone; iOS 15.4.1; Scale/3.00)"
13+
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"
1414
CITY = "0101"
15-
API_VERSION = "9.50.2"
16-
BUILD_VERSION = "1232"
15+
API_VERSION = "9.51.0"
16+
BUILD_VERSION = "2.86.3"
1717
TIME_OUT = 10 * time.Second
1818
BOOKABLE = "可预约"
1919
NOTICE_BOOKABLE = "可以预约啦"
@@ -22,6 +22,9 @@ const (
2222
LOCAL_MODE = 0
2323
GITHUB_MODE = 1
2424
APP_CLIENT_ID = 10
25+
ALIMINIMARK = "DDNMSL"
26+
OPEN_ID = "6666666666666666"
27+
REFERER = "https://2021001157662937.hybrid.alipay-eco.com/2021001157662937/0.2.2205051588.15/index.html#pages/mainPackage/home/home"
2528
)
2629

2730
var Conf = new(config)

0 commit comments

Comments
 (0)