mirror of http://gitlab.batiao8.com/yic/film.git
dadi2
This commit is contained in:
parent
374f0d4200
commit
4085364383
|
@ -24,7 +24,6 @@ func HttpGet(link string, params map[string]string, header map[string]string) ([
|
|||
}
|
||||
}
|
||||
|
||||
fmt.Println(p.Encode())
|
||||
u.RawQuery = p.Encode()
|
||||
req, err := http.NewRequest("GET", u.String(), nil)
|
||||
if err != nil {
|
||||
|
|
15
cmd/film.go
15
cmd/film.go
|
@ -55,19 +55,28 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
dadiProcessor := &worker.Dadi{}
|
||||
dadiProcessor := &worker.Dadi{
|
||||
Token: cfg.Film.DadiToken,
|
||||
}
|
||||
if err := dadiProcessor.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
orderWorker := &worker.Orders{
|
||||
Token: config.GetConfig().Film.Token,
|
||||
Token: config.GetConfig().Film.HahaToken,
|
||||
Dadi: dadiProcessor,
|
||||
}
|
||||
|
||||
if err := orderWorker.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//
|
||||
//dadiProcessor.NewOrder(&model.Order{
|
||||
// CityName: "张家口",
|
||||
// CinemaName: "大地影院(张家口财富中心店)",
|
||||
// ShowTime: 1681006500,
|
||||
// Seats: "3:6|3:5",
|
||||
// MovieName: "超级马力欧兄弟大电影",
|
||||
//})
|
||||
select {}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,5 @@ qiye_secret = "U2kq2Fxe_mwV7t-xYYvZJzmeGqkq2_1PPH-QpVGjWDg"
|
|||
qiye_agent = "1000012"
|
||||
|
||||
[film]
|
||||
token = "cc5f1d4c36f7e9544d641a174b298f94"
|
||||
haha_token = "cc5f1d4c36f7e9544d641a174b298f94"
|
||||
dadi_token = "321566:b891effb-5493-4f26-ac54-bfa5581ca8c3"
|
|
@ -18,4 +18,5 @@ qiye_secret = "G3ITLIrqVDG42jObBgh9XH4G3dcVRguonASJJ0x2YwY"
|
|||
qiye_agent = "1000005"
|
||||
|
||||
[film]
|
||||
token = "cc5f1d4c36f7e9544d641a174b298f94"
|
||||
haha_token = "cc5f1d4c36f7e9544d641a174b298f94"
|
||||
dadi_token = "321566:b891effb-5493-4f26-ac54-bfa5581ca8c3"
|
|
@ -43,7 +43,8 @@ type Weixin struct {
|
|||
}
|
||||
|
||||
type Film struct {
|
||||
Token string `toml:"token"`
|
||||
DadiToken string `toml:"dadi_token"`
|
||||
HahaToken string `toml:"haha_token"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
136
worker/dadi.go
136
worker/dadi.go
|
@ -10,9 +10,11 @@ import (
|
|||
"github.com/spf13/cast"
|
||||
"gitlab.com/jiangyong27/gobase/wxapi"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Dadi struct {
|
||||
Token string
|
||||
citys map[string]*DadiCity
|
||||
qyClient *wxapi.WxQiye
|
||||
}
|
||||
|
@ -20,26 +22,11 @@ type Dadi struct {
|
|||
func (d *Dadi) Init() error {
|
||||
cityUrl := "https://appapi.dadicinema.com/app-web/v1/web/cinema/cbticket/cbase/cityAndCinemaList"
|
||||
|
||||
params := map[string]string{
|
||||
"channelCode": "SYH-DDZY-DD",
|
||||
"channelName": "大地自营-大地",
|
||||
"channelNo": "SYH-DDZY-DD",
|
||||
"channelUid": "SYH-DDZY-DD",
|
||||
"cinema": "11050621",
|
||||
"cinemaCode": "11050621",
|
||||
"cinemaUid": "118",
|
||||
"d": "iPhone14,3",
|
||||
"i": "00000000-0000-0000-0000-000000000000",
|
||||
"k": "321566:b891effb-5493-4f26-ac54-bfa5581ca8c3",
|
||||
"r": "1",
|
||||
"s": "iOS15.2.1",
|
||||
"t": "1",
|
||||
"tenantId": "321566",
|
||||
"unifiedCinemaId": "118",
|
||||
"unifiedCinemaName": "大地影院(北京十里河铭泽店)",
|
||||
"unifiedCode": "11050621",
|
||||
"v": "8.7.3",
|
||||
}
|
||||
params := d.getCinemaReq(&DadiCinema{
|
||||
Name: "大地影院(北京十里河铭泽店)",
|
||||
Id: 118,
|
||||
UnifiedCode: 11050621,
|
||||
})
|
||||
body, err := httputil.HttpGet(cityUrl, params, map[string]string{
|
||||
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
|
||||
})
|
||||
|
@ -78,11 +65,13 @@ func (d *Dadi) Init() error {
|
|||
city.ShortName = cast.ToString(cityInfo["shortName"])
|
||||
city.CityId = cast.ToInt64(data["cityId"])
|
||||
city.CityCode = cast.ToInt64(data["cityCode"])
|
||||
city.Cinemas = cinemas
|
||||
|
||||
citys[city.ShortName] = city
|
||||
}
|
||||
|
||||
d.citys = citys
|
||||
log.Infof("load dadi citys : %d", len(d.citys))
|
||||
|
||||
cfg := config.GetConfig()
|
||||
d.qyClient = wxapi.NewQiye(&wxapi.QiyeConfig{
|
||||
|
@ -103,17 +92,122 @@ func (d *Dadi) NewOrder(order *model.Order) {
|
|||
if cinema.Name != order.CinemaName {
|
||||
continue
|
||||
}
|
||||
log.Infof("cinema : %s match order : %s", goutil.EncodeJSON(cinema), goutil.EncodeJSON(order))
|
||||
|
||||
films, err := d.getCinemaFilm(cinema)
|
||||
if err != nil {
|
||||
log.Errorf("getCinemaFilm cinema : %s error :%s", goutil.EncodeJSON(cinema), err.Error())
|
||||
continue
|
||||
}
|
||||
if _, ok := films[order.MovieName]; !ok {
|
||||
log.Errorf("cinema[%s] not movie[%s] ", cinema.Name, order.MovieName)
|
||||
continue
|
||||
}
|
||||
film := films[order.MovieName]
|
||||
|
||||
orderShowDay := time.Unix(order.ShowTime, 0).Format("2006-01-02")
|
||||
var show *DadiFilmShow = nil
|
||||
for _, sh := range film.Shows {
|
||||
if sh.Day != orderShowDay {
|
||||
continue
|
||||
}
|
||||
show = sh
|
||||
}
|
||||
if show == nil {
|
||||
log.Errorf("cinema[%s] movie[%s] no day[%s]", cinema.Name, order.MovieName, orderShowDay)
|
||||
continue
|
||||
}
|
||||
|
||||
message := make([]string, 0)
|
||||
message = append(message, "【匹配成功】")
|
||||
message = append(message, "订单信息:%s", goutil.EncodeJSON(order))
|
||||
message = append(message, "影院信息:%s", goutil.EncodeJSON(cinema))
|
||||
message = append(message, "电影信息:%s", goutil.EncodeJSON(film))
|
||||
if err := d.qyClient.SendText([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||
log.Errorf("send message error : %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Dadi) getCinemaReq(cinema *DadiCinema) map[string]string {
|
||||
params := map[string]string{
|
||||
"channelCode": "SYH-DDZY-DD",
|
||||
"channelName": "大地自营-大地",
|
||||
"channelNo": "SYH-DDZY-DD",
|
||||
"channelUid": "SYH-DDZY-DD",
|
||||
"cinema": cast.ToString(cinema.UnifiedCode),
|
||||
"cinemaCode": cast.ToString(cinema.UnifiedCode),
|
||||
"cinemaUid": cast.ToString(cinema.Id),
|
||||
"d": "iPhone14,3",
|
||||
"i": "00000000-0000-0000-0000-000000000000",
|
||||
"k": d.Token,
|
||||
"r": "1",
|
||||
"s": "iOS15.2.1",
|
||||
"t": "1",
|
||||
"tenantId": "321566",
|
||||
"unifiedCinemaId": cast.ToString(cinema.Id),
|
||||
"unifiedCinemaName": cinema.Name,
|
||||
"unifiedCode": cast.ToString(cinema.UnifiedCode),
|
||||
"v": "8.7.3",
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (d *Dadi) UpdateOrder(order *model.Order) {
|
||||
|
||||
}
|
||||
|
||||
func (d *Dadi) getCinemaFilm(cinema *DadiCinema) (map[string]*DadiFilm, error) {
|
||||
baseReq := d.getCinemaReq(cinema)
|
||||
reqUrl := "https://appapi.dadicinema.com/app-web/v1/web/film/getHitFilmAndFilmSession"
|
||||
body, err := httputil.HttpGet(reqUrl, baseReq, map[string]string{
|
||||
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("httpGet[%s] error : %s", reqUrl, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
log.Errorf("json.unmarshal [%s] error : %s", string(body), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
if cast.ToInt(result["code"]) != 200 || cast.ToBool(result["success"]) != true {
|
||||
log.Errorf("code[%d] message[%s]", cast.ToInt(result["code"]), cast.ToString(result["msg"]))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
films := make(map[string]*DadiFilm)
|
||||
|
||||
for _, f := range cast.ToSlice(cast.ToStringMap(result["data"])["filmList"]) {
|
||||
film := new(DadiFilm)
|
||||
ff := cast.ToStringMap(f)
|
||||
film.Id = cast.ToInt64(ff["id"])
|
||||
film.Name = cast.ToString(ff["name"])
|
||||
film.Shows = make([]*DadiFilmShow, 0)
|
||||
for _, s := range cast.ToSlice(ff["showList"]) {
|
||||
ss := cast.ToStringMap(s)
|
||||
show := new(DadiFilmShow)
|
||||
show.Day = cast.ToString(ss["dayStr"])
|
||||
show.Halls = make([]*DadiFilmShowHall, 0)
|
||||
for _, p := range cast.ToSlice(ss["plist"]) {
|
||||
pp := cast.ToStringMap(p)
|
||||
hall := new(DadiFilmShowHall)
|
||||
hall.HallName = cast.ToString(pp["hallName"])
|
||||
hall.SessionId = cast.ToString(pp["sessionId"])
|
||||
hall.StartTime = cast.ToString(pp["startTime"])
|
||||
hall.EndTime = cast.ToString(pp["endTime"])
|
||||
show.Halls = append(show.Halls, hall)
|
||||
}
|
||||
film.Shows = append(film.Shows, show)
|
||||
}
|
||||
|
||||
films[film.Name] = film
|
||||
}
|
||||
return films, nil
|
||||
}
|
||||
|
||||
func (d *Dadi) checkSeats(cinema *DadiCinema, order *model.Order) {
|
||||
|
||||
//baseReq := d.getCinemaReq(cinema)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -113,9 +114,14 @@ func (w *Orders) syncOrder() {
|
|||
|
||||
if isAdd {
|
||||
model.AddOrder(order)
|
||||
|
||||
if strings.Contains(order.CinemaName, "大地影院") {
|
||||
w.Dadi.NewOrder(order)
|
||||
}
|
||||
} else {
|
||||
model.UpdateOrder(order)
|
||||
if strings.Contains(order.CinemaName, "大地影院") {
|
||||
w.Dadi.UpdateOrder(order)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,31 @@
|
|||
package worker
|
||||
|
||||
type DadiFilmShowHall struct {
|
||||
HallName string
|
||||
StartTime string
|
||||
EndTime string
|
||||
SessionId string
|
||||
}
|
||||
|
||||
type DadiFilmShow struct {
|
||||
Day string
|
||||
Halls []*DadiFilmShowHall
|
||||
}
|
||||
|
||||
type DadiFilm struct {
|
||||
Id int64
|
||||
Name string
|
||||
Shows []*DadiFilmShow
|
||||
}
|
||||
|
||||
type DadiCinema struct {
|
||||
Id int64
|
||||
UnifiedCode int64
|
||||
Name string
|
||||
Address string
|
||||
Latitude string
|
||||
Longitude string
|
||||
CityId int64
|
||||
UnifiedCode int64
|
||||
}
|
||||
|
||||
type DadiCity struct {
|
||||
|
@ -14,6 +33,5 @@ type DadiCity struct {
|
|||
ShortName string
|
||||
CityCode int64
|
||||
CityId int64
|
||||
|
||||
Cinemas []*DadiCinema
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue