This commit is contained in:
jiangyong27 2023-04-07 23:51:09 +08:00
parent 150b922027
commit 374f0d4200
11 changed files with 13229 additions and 7 deletions

49
base/httputil/httpget.go Normal file
View File

@ -0,0 +1,49 @@
package httputil
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"net/url"
"time"
)
// Get 请求 link请求url
func HttpGet(link string, params map[string]string, header map[string]string) ([]byte, error) {
client := &http.Client{Timeout: 20 * time.Second}
//忽略https的证书
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
p := url.Values{}
u, _ := url.Parse(link)
if params != nil {
for k, v := range params {
p.Set(k, v)
}
}
fmt.Println(p.Encode())
u.RawQuery = p.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}
if header != nil {
for k, v := range header {
req.Header.Add(k, v)
}
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%d:%s", resp.StatusCode, resp.Status)
}
return io.ReadAll(resp.Body)
}

View File

@ -55,9 +55,19 @@ func main() {
panic(err) panic(err)
} }
w := &worker.Worker{ dadiProcessor := &worker.Dadi{}
Token: config.GetConfig().Film.Token, if err := dadiProcessor.Init(); err != nil {
panic(err)
} }
w.Init()
orderWorker := &worker.Orders{
Token: config.GetConfig().Film.Token,
Dadi: dadiProcessor,
}
if err := orderWorker.Init(); err != nil {
panic(err)
}
select {} select {}
} }

View File

@ -11,6 +11,10 @@ user = "film"
pass = "7VCfJx7H8MymUm" pass = "7VCfJx7H8MymUm"
db = "film" db = "film"
[weixin]
qiye_appid = "ww288920bd3e8c92b2"
qiye_secret = "U2kq2Fxe_mwV7t-xYYvZJzmeGqkq2_1PPH-QpVGjWDg"
qiye_agent = "1000012"
[film] [film]
token = "cc5f1d4c36f7e9544d641a174b298f94" token = "cc5f1d4c36f7e9544d641a174b298f94"

View File

@ -11,5 +11,11 @@ user = "film"
pass = "7VCfJx7H8MymUm" pass = "7VCfJx7H8MymUm"
db = "film" db = "film"
[weixin]
qiye_appid = "ww1f9a1f9e96186e4c"
qiye_secret = "G3ITLIrqVDG42jObBgh9XH4G3dcVRguonASJJ0x2YwY"
qiye_agent = "1000005"
[film] [film]
token = "cc5f1d4c36f7e9544d641a174b298f94" token = "cc5f1d4c36f7e9544d641a174b298f94"

View File

@ -35,6 +35,13 @@ type Redis struct {
Db int `toml:"db"` Db int `toml:"db"`
Password string `toml:"password"` Password string `toml:"password"`
} }
type Weixin struct {
QiyeAppid string `toml:"qiye_appid"`
Qiyesecret string `toml:"qiye_secret"`
QiyeAgent string `toml:"qiye_agent"`
}
type Film struct { type Film struct {
Token string `toml:"token"` Token string `toml:"token"`
} }
@ -43,6 +50,7 @@ type Config struct {
Server *Server `toml:"server"` Server *Server `toml:"server"`
Mysql *Mysql `toml:"mysql"` Mysql *Mysql `toml:"mysql"`
Redis *Redis `toml:"redis"` Redis *Redis `toml:"redis"`
Weixin *Weixin `toml:"weixin"`
Film *Film `toml:"film"` Film *Film `toml:"film"`
} }

12992
data/dadi_city.json Normal file

File diff suppressed because it is too large Load Diff

7
go.mod
View File

@ -11,13 +11,18 @@ require (
github.com/smbrave/goutil v0.0.0-20230208141215-e3360c3bfd1b github.com/smbrave/goutil v0.0.0-20230208141215-e3360c3bfd1b
github.com/spf13/cast v1.5.0 github.com/spf13/cast v1.5.0
github.com/spf13/viper v1.15.0 github.com/spf13/viper v1.15.0
gitlab.com/jiangyong27/gobase v1.0.23
gorm.io/driver/mysql v1.4.7 gorm.io/driver/mysql v1.4.7
gorm.io/gorm v1.24.6 gorm.io/gorm v1.24.6
) )
require ( require (
github.com/astaxie/beego v1.7.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20160117192205-fb1f79c6b65a // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/gomodule/redigo v1.8.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
@ -27,10 +32,12 @@ require (
github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/silenceper/wechat v1.2.6 // indirect
github.com/spf13/afero v1.9.3 // indirect github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sync v0.1.0 // indirect golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect golang.org/x/text v0.5.0 // indirect

View File

@ -27,6 +27,9 @@ type Order struct {
CinemaName string CinemaName string
MovieName string MovieName string
Address string Address string
Count int
IsSeat int
LoverSeat int
CreateDate string CreateDate string
CreateTime int64 CreateTime int64
UpdateTime int64 UpdateTime int64

119
worker/dadi.go Normal file
View File

@ -0,0 +1,119 @@
package worker
import (
"encoding/json"
"film/base/httputil"
"film/config"
"film/model"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
"gitlab.com/jiangyong27/gobase/wxapi"
"strings"
)
type Dadi struct {
citys map[string]*DadiCity
qyClient *wxapi.WxQiye
}
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",
}
body, err := httputil.HttpGet(cityUrl, params, map[string]string{
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
})
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 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 err
}
citys := make(map[string]*DadiCity)
datas := cast.ToSlice(result["data"])
for _, d := range datas {
data := cast.ToStringMap(d)
cinemas := make([]*DadiCinema, 0)
for _, c := range cast.ToSlice(data["cinemas"]) {
cin := cast.ToStringMap(c)
cinema := new(DadiCinema)
cinema.Name = cast.ToString(cin["name"])
cinema.Address = cast.ToString(cin["address"])
cinema.Latitude = cast.ToString(cin["latitude"])
cinema.Longitude = cast.ToString(cin["longitude"])
cinema.CityId = cast.ToInt64(cin["cityId"])
cinema.UnifiedCode = cast.ToInt64(cin["unifiedCode"])
cinemas = append(cinemas, cinema)
}
cityInfo := cast.ToStringMap(data["cityInfo"])
city := new(DadiCity)
city.Name = cast.ToString(cityInfo["chName"])
city.ShortName = cast.ToString(cityInfo["shortName"])
city.CityId = cast.ToInt64(data["cityId"])
city.CityCode = cast.ToInt64(data["cityCode"])
citys[city.ShortName] = city
}
d.citys = citys
cfg := config.GetConfig()
d.qyClient = wxapi.NewQiye(&wxapi.QiyeConfig{
Corpid: cfg.Weixin.QiyeAppid,
Secret: cfg.Weixin.Qiyesecret,
Sender: cfg.Weixin.QiyeAgent,
})
return nil
}
func (d *Dadi) NewOrder(order *model.Order) {
if _, ok := d.citys[order.CityName]; !ok {
log.Errorf("city[%s] not exist dadi cinema", order.CityName)
return
}
city := d.citys[order.CityName]
for _, cinema := range city.Cinemas {
if cinema.Name != order.CinemaName {
continue
}
log.Infof("cinema : %s match order : %s", goutil.EncodeJSON(cinema), goutil.EncodeJSON(order))
message := make([]string, 0)
message = append(message, "【匹配成功】")
message = append(message, "订单信息:%s", goutil.EncodeJSON(order))
message = append(message, "影院信息:%s", goutil.EncodeJSON(cinema))
if err := d.qyClient.SendText([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
log.Errorf("send message error : %s", err.Error())
}
}
}
func (d *Dadi) UpdateOrder(order *model.Order) {
}

View File

@ -14,11 +14,12 @@ import (
"time" "time"
) )
type Worker struct { type Orders struct {
Token string Token string
Dadi *Dadi
} }
func (w *Worker) Init() error { func (w *Orders) Init() error {
timezone, _ := time.LoadLocation("Asia/Shanghai") timezone, _ := time.LoadLocation("Asia/Shanghai")
cron := gocron.NewScheduler(timezone) cron := gocron.NewScheduler(timezone)
@ -30,7 +31,7 @@ func (w *Worker) Init() error {
return nil return nil
} }
func (w *Worker) httpPost(requestUrl string) ([]byte, error) { func (w *Orders) httpPost(requestUrl string) ([]byte, error) {
client := &http.Client{Timeout: 20 * time.Second} client := &http.Client{Timeout: 20 * time.Second}
//忽略https的证书 //忽略https的证书
client.Transport = &http.Transport{ client.Transport = &http.Transport{
@ -57,7 +58,7 @@ func (w *Worker) httpPost(requestUrl string) ([]byte, error) {
return io.ReadAll(resp.Body) return io.ReadAll(resp.Body)
} }
func (w *Worker) syncOrder() { func (w *Orders) syncOrder() {
orderUrl := "https://hahapiao.cn/api/Synchro/toList" orderUrl := "https://hahapiao.cn/api/Synchro/toList"
body, err := w.httpPost(orderUrl) body, err := w.httpPost(orderUrl)
if err != nil { if err != nil {
@ -106,9 +107,13 @@ func (w *Worker) syncOrder() {
order.Address = cast.ToString(data["address"]) order.Address = cast.ToString(data["address"])
order.Ting = cast.ToString(data["ting"]) order.Ting = cast.ToString(data["ting"])
order.CinemaName = cast.ToString(data["cinemaName"]) order.CinemaName = cast.ToString(data["cinemaName"])
order.Count = cast.ToInt(data["count"])
order.IsSeat = cast.ToInt(data["is_seat"])
order.LoverSeat = cast.ToInt(data["loverSeat"])
if isAdd { if isAdd {
model.AddOrder(order) model.AddOrder(order)
} else { } else {
model.UpdateOrder(order) model.UpdateOrder(order)
} }

19
worker/type.go Normal file
View File

@ -0,0 +1,19 @@
package worker
type DadiCinema struct {
Name string
Address string
Latitude string
Longitude string
CityId int64
UnifiedCode int64
}
type DadiCity struct {
Name string
ShortName string
CityCode int64
CityId int64
Cinemas []*DadiCinema
}