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

Commit

Permalink
fix 405
Browse files Browse the repository at this point in the history
  • Loading branch information
voidbytes committed May 7, 2022
1 parent c91fa99 commit 3cf7eb8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 运行
目前提供两种方式运行,
### 本机运行
Expand Down
2 changes: 1 addition & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
@@ -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 # 监控频率,单位:秒
Expand Down
20 changes: 18 additions & 2 deletions src/monitor/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
40 changes: 40 additions & 0 deletions src/monitor/check_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
9 changes: 6 additions & 3 deletions src/monitor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "可以预约啦"
Expand All @@ -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)
Expand Down

0 comments on commit 3cf7eb8

Please sign in to comment.