Skip to content

Commit

Permalink
跑通候补流程
Browse files Browse the repository at this point in the history
  • Loading branch information
yincongcyincong committed Mar 9, 2022
1 parent 6e7c239 commit 0263cd9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
22 changes: 8 additions & 14 deletions action/afterrNate.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func AfterNateGetQueueNum() error {

func AfterNateConfirmHB(passengers []*module.Passenger, searchParam *module.SearchParam, trainData *module.TrainData) error {

// url encode需要小心,会多处理
passengerInfo := ""
for _, p := range passengers {
passengerInfo = passengerInfo + p.PassengerInfo
Expand All @@ -112,28 +111,23 @@ func AfterNateConfirmHB(passengers []*module.Passenger, searchParam *module.Sear
data := make(url.Values)
data.Set("passengerInfo", passengerInfo)
data.Set("jzParam", "")
data.Set("hbTrain", fmt.Sprintf("%s,%s#", trainData.TrainNo, searchParam.SeatType))
data.Set("hbTrain", fmt.Sprintf("%s,%s#", trainData.TrainName, searchParam.SeatType))
data.Set("lkParam", "")
data.Set("sessionId", "000")
data.Set("sessionId", "")
data.Set("sig", "")
data.Set("scene", "")
data.Set("encryptedData", strconv.Itoa(rand.Intn(math.MaxInt64)))
data.Set("is_revceive_wseat", "Y")
data.Set("realize_limit_time_di", "360")
data.Set("if_receive_wseat", "Y")
data.Set("realize_limit_time_diff", "360") // 候补票距离开车前的截止兑换时间,单位: 分钟,默认: 360

confirmQueue := new(module.ConfirmQueueRes)
err := utils.Request(utils.ReplaceSpecailChar(data.Encode()), utils.GetCookieStr(), "https://kyfw.12306.cn/otn/afterNate/confirmHB", confirmQueue, map[string]string{"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc"})
confirmHB := new(module.AfterNatConfirm)
err := utils.Request(utils.ReplaceSpecailChar(data.Encode()), utils.GetCookieStr(), "https://kyfw.12306.cn/otn/afterNate/confirmHB", confirmHB, map[string]string{"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc"})
if err != nil {
return err
}

switch data := confirmQueue.Data.(type) {
case string:
return errors.New(data)
case module.ConfirmData:
if !data.SubmitStatus {
return errors.New(fmt.Sprintf("确认排队信息失败: %+v", confirmQueue.Data))
}
if !confirmHB.Status || !confirmHB.Data.Flag {
return errors.New(fmt.Sprintf("候补车票失败:%+v", confirmHB))
}

return nil
Expand Down
5 changes: 1 addition & 4 deletions action/buy.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ func GetQueueCount(submitToken *module.SubmitToken, searchParam *module.SearchPa
}

func ConfirmQueue(passengers []*module.Passenger, submitToken *module.SubmitToken, searchParam *module.SearchParam) error {

// url encode需要小心,会多处理

passengerTicketStr := ""
oldPassengerStr := ""
for _, p := range passengers {
Expand Down Expand Up @@ -169,7 +168,6 @@ func ConfirmQueue(passengers []*module.Passenger, submitToken *module.SubmitToke

func OrderWait(submitToken *module.SubmitToken) (*module.OrderWaitRes, error) {

// url encode需要小心,会多处理
var err error
orderWaitUrl := fmt.Sprintf("https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?random=%s&tourFlag=dc&_json_att=&REPEAT_SUBMIT_TOKEN=%s", strconv.Itoa(rand.Intn(math.MaxInt64)), submitToken.Token)
orderWaitRes := new(module.OrderWaitRes)
Expand All @@ -195,7 +193,6 @@ func OrderWait(submitToken *module.SubmitToken) (*module.OrderWaitRes, error) {

func OrderResult(submitToken *module.SubmitToken, orderNo string) error {

// url encode需要小心,会多处理
var err error
data := make(url.Values)
data.Set("orderSequence_no", orderNo)
Expand Down
1 change: 1 addition & 0 deletions action/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func GetTrainInfo(searchParam *module.SearchParam) ([]*module.TrainData, error)
resSlice := strings.Split(res, "|")
sd := new(module.TrainData)
sd.Status = resSlice[1]
sd.TrainName = resSlice[2]
sd.TrainNo = resSlice[3]
sd.FromStationName = searchRes.Data.Map[resSlice[6]]
sd.ToStationName = searchRes.Data.Map[resSlice[7]]
Expand Down
2 changes: 1 addition & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func StartHBReq(w http.ResponseWriter, r *http.Request) {
utils.HTTPFailResp(w, http.StatusInternalServerError, 1, err.Error(), "")
return
}
pgs := passengers.Data.NormalPassengers[:0]
pgs := passengers.Data.NormalPassengers[:1]

err = action.PassengerInit()
if err != nil {
Expand Down
23 changes: 17 additions & 6 deletions module/afterNate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type ChechFace struct {
}

type SuccRate struct {
ValidateMessagesShowId string `json:"validateMessagesShowId"`
Status bool `json:"status"`
HTTPStatus int `json:"httpstatus"`
Messages []string `json:"messages"`
Data struct{
ValidateMessagesShowId string `json:"validateMessagesShowId"`
Status bool `json:"status"`
HTTPStatus int `json:"httpstatus"`
Messages []string `json:"messages"`
Data struct {
Flag []*SuccRateFlag `json:"flag"`
} `json:"data"`
}
Expand Down Expand Up @@ -65,4 +65,15 @@ type PassengerInit struct {
Status bool `json:"status"`
HTTPStatus int `json:"httpstatus"`
Messages []string `json:"messages"`
}
}

type AfterNatConfirm struct {
ValidateMessagesShowId string `json:"validateMessagesShowId"`
Status bool `json:"status"`
HTTPStatus int `json:"httpstatus"`
Messages []string `json:"messages"`
Data struct {
Flag bool `json:"flag"`
ReserveNo string `json:"reserve_no"`
} `json:"data"`
}
3 changes: 2 additions & 1 deletion module/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type TrainData struct {
ArrivalTime string
DistanceTime string
Status string
IsCanNate string
IsCanNate string
TrainName string
SeatInfo map[string]string
}

Expand Down

0 comments on commit 0263cd9

Please sign in to comment.