g.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package g
  2. import (
  3. "TripUpRate/models"
  4. "TripUpRate/yjy/utils"
  5. "crypto/md5"
  6. "encoding/hex"
  7. "encoding/json"
  8. "fmt"
  9. "gitee.com/nanqis/bigtires/big"
  10. "github.com/beego/beego/v2/core/logs"
  11. "strconv"
  12. "strings"
  13. "sync"
  14. "time"
  15. )
  16. var (
  17. TaskList sync.Map
  18. AgencyTag = "BLTL"
  19. )
  20. /**
  21. 初始化Cookie
  22. 返回:
  23. cookies:初始化后的cookies
  24. proxy:代理IP:端口
  25. idc:IDC服务商
  26. */
  27. func InitCookies() (cookies string, proxy string, idc string) {
  28. //获取代理IP
  29. proxy = utils.GetProxyIpNiuYun()
  30. idc, _, cookies, _ = big.HttpSend(&big.HttpParms{
  31. Url: "https://us.trip.com/",
  32. 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
  33. accept-encoding: gzip, deflate, br
  34. accept-language: zh-CN,zh;q=0.9
  35. user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
  36. ProxyIP: proxy,
  37. })
  38. idc = big.StrGetSub(idc, "data-idc=\"", "\"")
  39. _, _, cookies, _ = big.HttpSend(&big.HttpParms{
  40. Url: "https://us.trip.com/flights/graphql/hotCitySearch",
  41. Mode: "POST",
  42. DataStr: "{\"operationName\":\"hotCitySearch\",\"variables\":{},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"a70a7532ccd91276029469dbf61c18b8ff88a7c68119575ba3f2e8af717aada2\"}}}",
  43. Cookies: cookies,
  44. Headers: `accept: */*
  45. accept-encoding: gzip, deflate, br
  46. accept-language: zh-CN,zh;q=0.9
  47. content-type: application/json
  48. referer: https://us.trip.com/
  49. user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
  50. ProxyIP: proxy,
  51. })
  52. _, _, cookies, _ = big.HttpSend(&big.HttpParms{
  53. Url: "https://us.trip.com/flights/graphql/location",
  54. Mode: "POST",
  55. DataStr: "{\"operationName\":\"location\",\"variables\":{},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"bcb092764f217e77a1a82d863b276e63ea7d67db287255563a7f70844624fa2b\"}}}",
  56. Cookies: cookies,
  57. Headers: `accept: */*
  58. accept-encoding: gzip, deflate, br
  59. accept-language: zh-CN,zh;q=0.9
  60. content-type: application/json
  61. referer: https://us.trip.com/
  62. user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
  63. ProxyIP: proxy,
  64. })
  65. _, _, cookies, _ = big.HttpSend(&big.HttpParms{
  66. Url: "https://chloro.trip.com/v2/d",
  67. Mode: "POST",
  68. DataStr: "data=" + big.ProgRandChar(big.ProgRangeRand(1600, 2000, 0), 0, false) + "&version=7&serverName=https://www.trip.com",
  69. Cookies: cookies,
  70. Headers: `Connection: keep-alive
  71. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
  72. Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  73. Accept: */*
  74. Referer: https://www.trip.com/
  75. Accept-Encoding: gzip, deflate, br
  76. Accept-Language: zh-CN,zh;q=0.9`,
  77. ProxyIP: proxy,
  78. })
  79. return
  80. }
  81. type TaskInfo struct {
  82. Dptcity string `json:"dptcity"` // 出发地 XNN
  83. Arrcity string `json:"arrcity"` // 到达地 MIG
  84. Fromdate string `json:"fromdate"` // 出发日期 2021-04-13
  85. Enddate time.Time `json:"enddate"` //任务结束时间
  86. }
  87. func ForClick(key string) {
  88. for {
  89. //判断时间是否过期,过期则删除并结束协程
  90. info, _ := TaskList.Load(key)
  91. parm := info.(TaskInfo)
  92. if parm.Enddate.Before(time.Now()) {
  93. logs.Error(fmt.Sprintf("任务过期\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, parm.Fromdate))
  94. TaskList.Delete(key)
  95. break
  96. }
  97. //初始化Cookies
  98. cookies, proxy, idc := InitCookies()
  99. temp := ""
  100. dayStr := ""
  101. //判断有无找到,没有则新加一天,最多加7天
  102. for i := 0; i < 7; i++ {
  103. day, _ := time.Parse("2006-01-02", parm.Fromdate)
  104. dayStr = day.AddDate(0, 0, i).Format("2006-01-02")
  105. logs.Warn(fmt.Sprintf("正在查询\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
  106. //查询列表
  107. temp, _, _, _ = big.HttpSend(&big.HttpParms{
  108. Url: "https://us.trip.com/flights/graphql/intlFlightListSearchAll",
  109. Mode: "POST",
  110. 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),
  111. Cookies: cookies,
  112. Headers: `accept: */*
  113. accept-encoding: gzip, deflate, br
  114. accept-language: zh-CN,zh;q=0.9
  115. content-type: application/json
  116. 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
  117. user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36`,
  118. ProxyIP: proxy,
  119. })
  120. if strings.Contains(temp, AgencyTag) {
  121. break
  122. }
  123. //如果没有找到,则重新获取Cookies为下一次刷新做准备
  124. cookies, proxy, idc = InitCookies()
  125. }
  126. if !strings.Contains(temp, AgencyTag) {
  127. //增加7天都没有找到,结束本次循环
  128. logs.Error(fmt.Sprintf("查询失败\t%s-%s\t%s\t近7天查询无果等待下轮查询", parm.Dptcity, parm.Arrcity, dayStr))
  129. big.TimeSleepRangeRand(2, 4, time.Minute)
  130. continue
  131. }
  132. //反序列化
  133. var query models.Query
  134. err := json.Unmarshal([]byte(temp), &query)
  135. if err != nil {
  136. logs.Error(fmt.Sprintf("查询失败\t%s-%s\t%s\t响应结果参数效验错误等待下轮查询\t错误信息:%s", parm.Dptcity, parm.Arrcity, dayStr, err.Error()))
  137. big.TimeSleepRangeRand(2, 4, time.Minute)
  138. continue
  139. }
  140. //遍历结果,直至找到
  141. var infolist models.PolicyInfoList
  142. for _, flightlist := range query.Data.IntlFlightListSearch.ProductInfoList {
  143. for _, infoList := range flightlist.PolicyInfoList {
  144. if strings.Contains(infoList.AgencyTag, AgencyTag) {
  145. //找到了跳出循环
  146. infolist = infoList
  147. goto click
  148. }
  149. }
  150. }
  151. click:
  152. //判断是否找到
  153. if infolist.RemarkTokenKey == "" {
  154. logs.Error(fmt.Sprintf("查询失败\t%s-%s\t%s\t响应结果遍历没有找到等待下轮查询", parm.Dptcity, parm.Arrcity, dayStr))
  155. big.TimeSleepRangeRand(2, 4, time.Minute)
  156. continue
  157. }
  158. //找到了,开始点击
  159. tokens := strings.Split(infolist.ProductKeyInfo.GroupKey, "^")
  160. flightInfo := strings.Split(tokens[0], "-")
  161. temp, _, cookies, _ = big.HttpSend(&big.HttpParms{
  162. Url: "https://us.trip.com/flights/graphql/getFlightBookingInfo",
  163. Mode: "POST",
  164. 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\"}}}",
  165. Cookies: cookies,
  166. Headers: `Connection: keep-alive
  167. accept: */*
  168. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
  169. content-type: application/json
  170. Accept-Encoding: gzip, deflate, br
  171. Accept-Language: zh-CN,zh;q=0.9`,
  172. ProxyIP: proxy,
  173. })
  174. if strings.Contains(temp, "cabinClass:YSGroup") {
  175. logs.Info(fmt.Sprintf("验价成功\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
  176. //判断是否需要生单
  177. if big.ProgRangeRand(1, 20, 0) == 5 {
  178. //延迟几十秒后执行生单操作
  179. big.TimeSleepRangeRand(15, 30, time.Second)
  180. //随机生成乘客姓名
  181. userLastName := big.ProgRandChar(big.ProgRangeRand(3, 5, 0), 2, false)
  182. userFirstName := big.ProgRandChar(big.ProgRangeRand(5, 8, 0), 2, false)
  183. usereMail := big.ProgRandChar(big.ProgRangeRand(5, 10, 0), 3, false) + "@gmail.com"
  184. userPhone := "1" + big.ProgLenRand(9, 0)
  185. userBirthday := strconv.Itoa(big.ProgRangeRand(1970, 2002, 0)) + "-0" + strconv.Itoa(big.ProgRangeRand(1, 9, 0)) + "-" + strconv.Itoa(big.ProgRangeRand(10, 28, 0))
  186. md5 := md5.New()
  187. md5.Write([]byte(userLastName + "/" + userFirstName))
  188. userCardNo := hex.EncodeToString(md5.Sum(nil))
  189. if userCardNo[:1] == "0" {
  190. userCardNo = userCardNo[1:]
  191. }
  192. for len(userCardNo) < 9 {
  193. userCardNo += "0"
  194. }
  195. userLimit := strconv.Itoa(big.ProgRangeRand(2023, 2027, 0)) + "-0" + strconv.Itoa(big.ProgRangeRand(1, 9, 0)) + "-" + strconv.Itoa(big.ProgRangeRand(10, 28, 0))
  196. userLimitTime, _ := time.Parse("2006-01-02", userLimit)
  197. userSex := "M"
  198. if big.ProgRangeRand(0, 1, 0) == 1 {
  199. userSex = "F"
  200. }
  201. UserRandomid, _ := big.TimeStamp(16)
  202. UserClientTime := time.Now().Format("2006-01-02T15:04:05+08:00")
  203. UserVid, _ := big.TimeStamp(13)
  204. UserVid += "." + strings.ToLower(big.ProgRandChar(5, 0, false))
  205. 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\"}}}"
  206. cookies = big.HttpMergeCookies(cookies, "cticket=89B755E40A1B7CAE31103C48EC693B1EFAC59C231FD0FA2D8CED0ACF0B7061AA")
  207. temp, _, cookies, _ = big.HttpSend(&big.HttpParms{
  208. Url: "https://us.trip.com/flights/graphql/intlCreateOrder",
  209. Mode: "POST",
  210. DataStr: data,
  211. Cookies: cookies,
  212. Headers: `Connection: keep-alive
  213. accept: */*
  214. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
  215. content-type: application/json
  216. Accept-Encoding: gzip, deflate, br
  217. Accept-Language: zh-CN,zh;q=0.9`,
  218. ProxyIP: proxy,
  219. })
  220. if strings.Contains(temp, "PaymentGlobalizationOnline/NewPay") {
  221. logs.Info(fmt.Sprintf("生单成功\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
  222. } else {
  223. logs.Info(fmt.Sprintf("生单失败\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
  224. }
  225. }
  226. } else {
  227. logs.Error(fmt.Sprintf("验价失败\t%s-%s\t%s", parm.Dptcity, parm.Arrcity, dayStr))
  228. }
  229. big.TimeSleepRangeRand(2, 4, time.Minute)
  230. }
  231. }