123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- package g
- import (
- "TripUpRate/models"
- "TripUpRate/yjy/utils"
- "crypto/md5"
- "encoding/hex"
- "encoding/json"
- "fmt"
- "gitee.com/nanqis/bigtires/big"
- "github.com/beego/beego/v2/core/logs"
- "strconv"
- "strings"
- "sync"
- "time"
- )
- var (
- TaskList sync.Map
- AgencyTag = "BLTL"
- )
- /**
- 初始化Cookie
- 返回:
- cookies:初始化后的cookies
- proxy:代理IP:端口
- idc:IDC服务商
- */
- func InitCookies() (cookies string, proxy string, idc string) {
- //获取代理IP
- proxy = utils.GetProxyIpNiuYun()
- idc, _, cookies, _ = big.HttpSend(&big.HttpParms{
- Url: "https://us.trip.com/",
- Headers: `accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
- accept-encoding: gzip, deflate, br
- accept-language: zh-CN,zh;q=0.9
- user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
- ProxyIP: proxy,
- })
- idc = big.StrGetSub(idc, "data-idc=\"", "\"")
- _, _, cookies, _ = big.HttpSend(&big.HttpParms{
- Url: "https://us.trip.com/flights/graphql/hotCitySearch",
- Mode: "POST",
- DataStr: "{\"operationName\":\"hotCitySearch\",\"variables\":{},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"a70a7532ccd91276029469dbf61c18b8ff88a7c68119575ba3f2e8af717aada2\"}}}",
- Cookies: cookies,
- Headers: `accept: */*
- accept-encoding: gzip, deflate, br
- accept-language: zh-CN,zh;q=0.9
- content-type: application/json
- referer: https://us.trip.com/
- user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
- ProxyIP: proxy,
- })
- _, _, cookies, _ = big.HttpSend(&big.HttpParms{
- Url: "https://us.trip.com/flights/graphql/location",
- Mode: "POST",
- DataStr: "{\"operationName\":\"location\",\"variables\":{},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"bcb092764f217e77a1a82d863b276e63ea7d67db287255563a7f70844624fa2b\"}}}",
- Cookies: cookies,
- Headers: `accept: */*
- accept-encoding: gzip, deflate, br
- accept-language: zh-CN,zh;q=0.9
- content-type: application/json
- referer: https://us.trip.com/
- user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
- ProxyIP: proxy,
- })
- _, _, cookies, _ = big.HttpSend(&big.HttpParms{
- Url: "https://chloro.trip.com/v2/d",
- Mode: "POST",
- DataStr: "data=" + big.ProgRandChar(big.ProgRangeRand(1600, 2000, 0), 0, false) + "&version=7&serverName=https://www.trip.com",
- Cookies: cookies,
- Headers: `Connection: keep-alive
- User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
- Content-Type: application/x-www-form-urlencoded; charset=UTF-8
- Accept: */*
- Referer: https://www.trip.com/
- Accept-Encoding: gzip, deflate, br
- Accept-Language: zh-CN,zh;q=0.9`,
- ProxyIP: proxy,
- })
- return
- }
- type TaskInfo struct {
- Dptcity string `json:"dptcity"` // 出发地 XNN
- Arrcity string `json:"arrcity"` // 到达地 MIG
- Fromdate string `json:"fromdate"` // 出发日期 2021-04-13
- Enddate time.Time `json:"enddate"` //任务结束时间
- }
- func ForClick(key string) {
- for {
- //判断时间是否过期,过期则删除并结束协程
- info, _ := TaskList.Load(key)
- parm := info.(TaskInfo)
- if parm.Enddate.Before(time.Now()) {
- logs.Error(fmt.Sprintf("任务过期\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, parm.Fromdate))
- TaskList.Delete(key)
- break
- }
- //初始化Cookies
- cookies, proxy, idc := InitCookies()
- temp := ""
- dayStr := ""
- //判断有无找到,没有则新加一天,最多加7天
- for i := 0; i < 7; i++ {
- day, _ := time.Parse("2006-01-02", parm.Fromdate)
- dayStr = day.AddDate(0, 0, i).Format("2006-01-02")
- logs.Warn(fmt.Sprintf("正在查询\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
- //查询列表
- temp, _, _, _ = big.HttpSend(&big.HttpParms{
- Url: "https://us.trip.com/flights/graphql/intlFlightListSearchAll",
- Mode: "POST",
- DataStr: fmt.Sprintf("{\"operationName\":\"intlFlightListSearch\",\"variables\":{\"request\":{\"Head\":{\"Currency\":\"USD\"},\"mode\":1,\"searchNo\":1,\"criteriaToken\":\"\",\"productKeyInfo\":null,\"searchInfo\":{\"tripType\":\"OW\",\"cabinClass\":\"YS\",\"searchSegmentList\":[{\"dCityCode\":\"%s\",\"aCityCode\":\"%s\",\"dDate\":\"%s\"}],\"travelerNum\":{\"adult\":1,\"child\":0,\"infant\":0},\"openRtMergeSearch\":false}}},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"af100ae907a5c8e83e24542d42e83b6ecd24ad9a9072900f1fa0b5483f41d32f\"}}}", parm.Dptcity, parm.Arrcity, dayStr),
- Cookies: cookies,
- Headers: `accept: */*
- accept-encoding: gzip, deflate, br
- accept-language: zh-CN,zh;q=0.9
- content-type: application/json
- referer: https://us.trip.com/flights/denver-to-cancun/tickets-den-cun?FlightWay=OW&class=Y&Quantity=1&ChildQty=0&BabyQty=0&dcity=den&acity=cun&ddate=2021-07-20
- user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
- ProxyIP: proxy,
- })
- if strings.Contains(temp, AgencyTag) {
- break
- }
- //如果没有找到,则重新获取Cookies为下一次刷新做准备
- cookies, proxy, idc = InitCookies()
- }
- if !strings.Contains(temp, AgencyTag) {
- //增加7天都没有找到,结束本次循环
- logs.Error(fmt.Sprintf("查询失败\t%s-%s\t%s\t近7天查询无果等待下轮查询", parm.Dptcity, parm.Arrcity, dayStr))
- big.TimeSleepRangeRand(2, 4, time.Minute)
- continue
- }
- //反序列化
- var query models.Query
- err := json.Unmarshal([]byte(temp), &query)
- if err != nil {
- logs.Error(fmt.Sprintf("查询失败\t%s-%s\t%s\t响应结果参数效验错误等待下轮查询\t错误信息:%s", parm.Dptcity, parm.Arrcity, dayStr, err.Error()))
- big.TimeSleepRangeRand(2, 4, time.Minute)
- continue
- }
- //遍历结果,直至找到
- var infolist models.PolicyInfoList
- for _, flightlist := range query.Data.IntlFlightListSearch.ProductInfoList {
- for _, infoList := range flightlist.PolicyInfoList {
- if strings.Contains(infoList.AgencyTag, AgencyTag) {
- //找到了跳出循环
- infolist = infoList
- goto click
- }
- }
- }
- click:
- //判断是否找到
- if infolist.RemarkTokenKey == "" {
- logs.Error(fmt.Sprintf("查询失败\t%s-%s\t%s\t响应结果遍历没有找到等待下轮查询", parm.Dptcity, parm.Arrcity, dayStr))
- big.TimeSleepRangeRand(2, 4, time.Minute)
- continue
- }
- //找到了,开始点击
- tokens := strings.Split(infolist.ProductKeyInfo.GroupKey, "^")
- flightInfo := strings.Split(tokens[0], "-")
- temp, _, cookies, _ = big.HttpSend(&big.HttpParms{
- Url: "https://us.trip.com/flights/graphql/getFlightBookingInfo",
- Mode: "POST",
- DataStr: "{\"operationName\":\"getFlightBookingInfo\",\"variables\":{\"Head\":{\"Currency\":\"USD\"},\"source\":null,\"remarkTokenKey\":\"" + infolist.RemarkTokenKey + "\",\"criteriaToken\":\"tripType:OW|criteriatoken:" + tokens[2] + "|cabinClass:YSGroup|adult:1|dCity_1:" + flightInfo[1] + "|aCity_1:" + flightInfo[2] + "|date_1:" + dayStr + "|idc:" + idc + "\",\"productKeyInfo\":{\"shoppingId\":\"" + infolist.ProductKeyInfo.ShoppingID + "\",\"groupKey\":\"" + infolist.ProductKeyInfo.GroupKey + "\"}},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"22cbc6b7f0ffa46f8d533c0eddf844cff0edbf3ae3272e40d8c5cdf6dc6abfd6\"}}}",
- Cookies: cookies,
- Headers: `Connection: keep-alive
- accept: */*
- User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
- content-type: application/json
- Accept-Encoding: gzip, deflate, br
- Accept-Language: zh-CN,zh;q=0.9`,
- ProxyIP: proxy,
- })
- if strings.Contains(temp, "cabinClass:YSGroup") {
- logs.Info(fmt.Sprintf("验价成功\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
- //判断是否需要生单
- if big.ProgRangeRand(1, 20, 0) == 5 {
- //延迟几十秒后执行生单操作
- big.TimeSleepRangeRand(15, 30, time.Second)
- //随机生成乘客姓名
- userLastName := big.ProgRandChar(big.ProgRangeRand(3, 5, 0), 2, false)
- userFirstName := big.ProgRandChar(big.ProgRangeRand(5, 8, 0), 2, false)
- usereMail := big.ProgRandChar(big.ProgRangeRand(5, 10, 0), 3, false) + "@gmail.com"
- userPhone := "1" + big.ProgLenRand(9, 0)
- userBirthday := strconv.Itoa(big.ProgRangeRand(1970, 2002, 0)) + "-0" + strconv.Itoa(big.ProgRangeRand(1, 9, 0)) + "-" + strconv.Itoa(big.ProgRangeRand(10, 28, 0))
- md5 := md5.New()
- md5.Write([]byte(userLastName + "/" + userFirstName))
- userCardNo := hex.EncodeToString(md5.Sum(nil))
- if userCardNo[:1] == "0" {
- userCardNo = userCardNo[1:]
- }
- for len(userCardNo) < 9 {
- userCardNo += "0"
- }
- userLimit := strconv.Itoa(big.ProgRangeRand(2023, 2027, 0)) + "-0" + strconv.Itoa(big.ProgRangeRand(1, 9, 0)) + "-" + strconv.Itoa(big.ProgRangeRand(10, 28, 0))
- userLimitTime, _ := time.Parse("2006-01-02", userLimit)
- userSex := "M"
- if big.ProgRangeRand(0, 1, 0) == 1 {
- userSex = "F"
- }
- UserRandomid, _ := big.TimeStamp(16)
- UserClientTime := time.Now().Format("2006-01-02T15:04:05+08:00")
- UserVid, _ := big.TimeStamp(13)
- UserVid += "." + strings.ToLower(big.ProgRandChar(5, 0, false))
- data := "{\"operationName\":\"intlCreateOrder\",\"variables\":{\"request\":{\"Head\":{\"Currency\":\"USD\",\"clientTime\":\"" + UserClientTime + "\",\"ExtendFields\":{\"onex\":\"open\",\"cardAgeLimit\":\"true\",\"Source\":null},\"AbTesting\":\"\"},\"remarkTokenKey\":\"" + infolist.RemarkTokenKey + "\",\"criteriaToken\":\"tripType:OW|criteriatoken:" + tokens[2] + "|cabinClass:YSGroup|adult:1|dCity_1:" + flightInfo[1] + "|aCity_1:" + flightInfo[2] + "|date_1:" + dayStr + "|idc:" + idc + "\",\"productKeyInfo\":{\"groupKey\":\"" + infolist.ProductKeyInfo.GroupKey + "\",\"shoppingId\":\"" + infolist.ProductKeyInfo.ShoppingID + "\"},\"xProductOrderInfo\":{\"baggageInfoList\":[],\"loungeInfoList\":null,\"checkInProductList\":null,\"servicePackageInfoList\":null,\"blueRibbonBagInfo\":null,\"insuranceDetail\":{\"insuranceInfoList\":[]}},\"basicInfo\":{\"enableRePricingNote\":true,\"checkRepeatOrders\":true,\"enableQuickBooking\":true,\"gdprRecord\":{\"pageId\":\"10320667455\",\"content\":\"By proceeding, I acknowledge that I have read and agree to Trip.com's <a target='_blank' href='//pages.trip.com/service-guideline/terms-en-us.html'>Flight Booking Policies</a> and <a target='_blank' href='//pages.trip.com/m/privacy-policy-en-us.html'>Privacy Statement</a>.\",\"hasCheckBox\":false,\"checked\":false}},\"flightPassengerList\":[{\"randomid\":\"" + UserRandomid + "\",\"travelerType\":\"ADT\",\"passengerId\":\"\",\"surName\":\"" + userLastName + "\",\"givenName\":\"" + userFirstName + "\",\"nationalityname\":\"United States\",\"nationality\":\"US\",\"gender\":\"" + userSex + "\",\"birthday\":\"" + userBirthday + "\",\"cardName\":\"Passport\",\"cardType\":2,\"cardNo\":\"" + userCardNo + "\",\"cardTimelimitTime\":" + strconv.FormatInt(userLimitTime.Unix(), 10) + ",\"passportLimit\":\"" + userLimit + "\",\"airLineCardList\":[{\"cardNumber\":\"\",\"airlineCode\":\"\"}]}],\"contactInfo\":{\"contactName\":\"" + userLastName + "/" + userFirstName + "\",\"phoneArea\":\"+1\",\"mobilePhone\":\"" + userPhone + "\",\"email\":\"" + usereMail + "\",\"postCode\":\"\"},\"couponInfo\":{},\"promotionId\":null,\"vid\":\"" + UserVid + "\",\"sid\":1,\"pvid\":8,\"riskControlInfo\":{\"rmsToken\":\"fp=krjmmc-1frht1k-nyd0if&vid=" + UserVid + "&pageId=10320667452&r=" + strings.ReplaceAll(big.HttpGetCookie(cookies, "_RGUID"), "-", "") + "&ip=" + big.StrGetLeft(proxy, ":") + "&rg=fin&kpData=0_0_0&kpControl=0_0_0-0_0_0&kpEmp=0_0_0_0_0_0_0_0_0_0-0_0_0_0_0_0_0_0_0_0-0_0_0_0_0_0_0_0_0_0&screen=2560x1440&tz=+8&blang=zh-CN&oslang=zh-CN&ua=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20WOW64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F86.0.4240.198%20Safari%2F537.36&d=us.trip.com&v=23&kpg=0_0_0_0_0_0_0_0_0_0&adblock=F&cck=F\"}}},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"8cc07d02934afbabdd82d7d957fab1a9cbda1944db419bb7208374bf06f00bb6\"}}}"
- cookies = big.HttpMergeCookies(cookies, "cticket=89B755E40A1B7CAE31103C48EC693B1EFAC59C231FD0FA2D8CED0ACF0B7061AA")
- temp, _, cookies, _ = big.HttpSend(&big.HttpParms{
- Url: "https://us.trip.com/flights/graphql/intlCreateOrder",
- Mode: "POST",
- DataStr: data,
- Cookies: cookies,
- Headers: `Connection: keep-alive
- accept: */*
- User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
- content-type: application/json
- Accept-Encoding: gzip, deflate, br
- Accept-Language: zh-CN,zh;q=0.9`,
- ProxyIP: proxy,
- })
- if strings.Contains(temp, "PaymentGlobalizationOnline/NewPay") {
- logs.Info(fmt.Sprintf("生单成功\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
- } else {
- logs.Info(fmt.Sprintf("生单失败\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
- }
- }
- } else {
- logs.Error(fmt.Sprintf("验价失败\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
- }
- big.TimeSleepRangeRand(2, 4, time.Minute)
- }
- }
|