Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
lcc-akm
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangmingming
lcc-akm
Commits
d8fe0a64
Commit
d8fe0a64
authored
Mar 09, 2023
by
王明明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
改写
parent
87247bb9
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
124 additions
and
70 deletions
+124
-70
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
main.go
main.go
+14
-4
easyjet.go
model/easyjet.go
+94
-61
init.go
model/init.go
+9
-3
test.go
test/test.go
+4
-2
No files found.
go.mod
View file @
d8fe0a64
...
...
@@ -4,6 +4,7 @@ go 1.20
require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/antonfisher/nested-logrus-formatter v1.3.1 // indirect
github.com/bogdanfinn/fhttp v0.5.18 // indirect
github.com/bogdanfinn/tls-client v1.3.6 // indirect
github.com/bogdanfinn/utls v1.5.14 // indirect
...
...
go.sum
View file @
d8fe0a64
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ=
github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA=
github.com/bogdanfinn/fhttp v0.5.18 h1:n3lnt5huD9Z35I5gXJCBLiJJo8JMckb0Z05Nqnh+tIQ=
github.com/bogdanfinn/fhttp v0.5.18/go.mod h1:S9yg7SmaUVpsY5QvGJ1jY0ZvJ68jkPLW5VEqWlhYWRI=
github.com/bogdanfinn/tls-client v1.3.6 h1:yUy2eaM1dZDZ1Aygx4omDipwA6JAvGNqc0M/7WY4o98=
...
...
main.go
View file @
d8fe0a64
...
...
@@ -2,8 +2,10 @@ package main
import
(
"fmt"
nested
"github.com/antonfisher/nested-logrus-formatter"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"log"
"net/http"
"test/model"
...
...
@@ -15,15 +17,23 @@ func WelcomeHandler(w http.ResponseWriter, r *http.Request) {
func
main
()
{
logrus
.
SetLevel
(
logrus
.
TraceLevel
)
logrus
.
SetFormatter
(
&
logrus
.
TextFormatter
{
//HideKeys: true,
//logrus.SetFormatter(&logrus.TextFormatter{
// //HideKeys: true,
// TimestampFormat: "2006-01-02 15:04:05.000", //时间格式
// FullTimestamp: true,
//})
logrus
.
SetFormatter
(
&
nested
.
Formatter
{
HideKeys
:
true
,
FieldsOrder
:
[]
string
{
"type"
},
TimestampFormat
:
"2006-01-02 15:04:05.000"
,
//时间格式
FullTimestamp
:
true
,
})
//str := "<noscript><img src=\"https://www.easyjet.com/akam/13/pixel_7b9d10f9?a=dD1lMmMzOTBjM2M4NWUyYz\nkzNjljOTNhZDUyNmRkOGJjMDdjNjM2MWJmJmpzPW9mZg==\" style=\"visibility: hidden; position: absolu\nte; left: -999px; top: -999px;\" /></noscript><script type=\"text/javascript\" src=\"/-Hzovq/uluGM/jHPdr/v3N7/m5OOLVXmDOwY/NG4dCQE/Zy/lnEF9qaQI\"></script></body>\n</html>"
//str = "<noscript><img src=\"https://www.easyjet.com/akam/13/pixel_4ac30e0f?a=dD1kZmQ1ODJiODRhNzUxMzAzMDJmN\nTczMjdhMGVlZGEyNWM3MTcwNDY5JmpzPW9mZg==\" style=\"visibility: hidden; position: absolute; left: -999\npx; top: -999px;\" /></noscript><script type=\"text/javascript\" src=\"/9dz5yx/00N2ob/cHtIJhA/oGemj3/BA/SaOXNNXpVab5wO/PVZtb1s9Aw/by/ZID307CB8\"></script></body>\n"
//
//reg, _ := regexp.Compile("</noscript><script type=\"text/javascript\" src=\"(.+?)\"></s")
//matchs := reg.FindStringSubmatch(str)
//fmt.Println(matchs)
//fmt.Println(matchs[1])
//print(len(matchs))
router
:=
mux
.
NewRouter
()
router
.
HandleFunc
(
"/"
,
func
(
writer
http
.
ResponseWriter
,
request
*
http
.
Request
)
{
...
...
model/easyjet.go
View file @
d8fe0a64
package
model
import
(
"fmt"
"encoding/json"
"errors"
http
"github.com/bogdanfinn/fhttp"
tls_client
"github.com/bogdanfinn/tls-client"
"github.com/sirupsen/logrus"
...
...
@@ -18,11 +19,11 @@ type AkmClient struct {
Jar
tls_client
.
CookieJar
Client
tls_client
.
HttpClient
SensorUrl
string
uri
string
logger
*
logrus
.
Entry
}
var
akmClient
*
AkmClient
func
NewAkmClient
(
proxyUrl
string
)
*
AkmClient
{
func
NewAkmClient
(
proxyUrl
string
,
logger
*
logrus
.
Entry
)
*
AkmClient
{
jar
:=
tls_client
.
NewCookieJar
()
options
:=
[]
tls_client
.
HttpClientOption
{
tls_client
.
WithTimeoutSeconds
(
30
),
...
...
@@ -44,11 +45,54 @@ func NewAkmClient(proxyUrl string) *AkmClient {
client
.
SetProxy
(
proxyUrl
)
}
return
&
AkmClient
{
Jar
:
jar
,
Client
:
client
}
return
&
AkmClient
{
Jar
:
jar
,
Client
:
client
,
uri
:
"https://www.easyjet.com/en"
,
logger
:
logger
}
}
func
(
c
*
AkmClient
)
PostJson
(
times
int
,
url
,
data
string
)
(
int
,
error
)
{
req
,
err
:=
http
.
NewRequest
(
http
.
MethodPost
,
url
,
strings
.
NewReader
(
data
))
//req, err := http.NewRequest(http.MethodGet, "https://www.easyjet.com/ejavailability/api/v66/availability/query?AdditionalSeats=0&AdultSeats=1&ArrivalIata=LGW&ChildSeats=0&DepartureIata=BFS&IncludeAdminFees=true&IncludeFlexiFares=false&IncludeLowestFareSeats=true&IncludePrices=true&Infants=0&IsTransfer=false&LanguageCode=EN&MaxDepartureDate=2023-03-20&MinDepartureDate=2023-03-18", nil)
if
err
!=
nil
{
c
.
logger
.
WithError
(
err
)
.
Errorln
(
"初始化abck请求失败"
)
return
-
1
,
err
}
func
GetAbck
(
times
int
,
urlInput
string
)
[]
*
http
.
Cookie
{
abck
,
bmsz
:=
GetCookie
()
req
.
Header
=
http
.
Header
{
"accept"
:
{
"*/*"
},
"accept-language"
:
{
"de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
},
"content-type"
:
{
"application/json"
},
"user-agent"
:
{
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36"
},
http
.
HeaderOrderKey
:
{
"accept"
,
"accept-language"
,
"user-agent"
,
},
}
for
i
:=
0
;
i
<
3
;
i
++
{
startTime
:=
time
.
Now
()
response
,
err
:=
c
.
Client
.
Do
(
req
)
if
err
!=
nil
{
c
.
logger
.
WithError
(
err
)
.
Info
(
"post sensor_data 错误"
)
continue
}
defer
response
.
Body
.
Close
()
readAll
,
err
:=
io
.
ReadAll
(
response
.
Body
)
if
err
!=
nil
{
c
.
logger
.
WithError
(
err
)
.
Info
(
"post sensor_data 读取返回值 错误"
)
continue
}
resJson
:=
make
(
map
[
string
]
bool
)
err
=
json
.
Unmarshal
(
readAll
,
&
resJson
)
if
err
!=
nil
{
c
.
logger
.
WithError
(
err
)
.
Info
(
"序列化 sensor_data 返回值 错误"
)
continue
}
c
.
logger
.
Infof
(
"第%d次snesor请求第%d次尝试结果%v 耗时 %s"
,
times
,
i
,
resJson
[
"success"
],
time
.
Since
(
startTime
)
.
String
())
return
response
.
StatusCode
,
nil
}
return
-
1
,
errors
.
New
(
"请求三次都失败返回结果吧"
)
}
func
(
c
*
AkmClient
)
GetAbck
(
times
int
,
urlInput
string
)
error
{
abck
,
bmsz
:=
c
.
GetCookie
()
//data := url.Values{}
//data.Set("times", strconv.Itoa(times))
//data.Set("abck", abck)
...
...
@@ -64,22 +108,23 @@ func GetAbck(times int, urlInput string) []*http.Cookie {
ua
:=
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50"
t1
:=
time
.
Now
()
res
:=
sensor
.
GenData
(
abck
,
bmsz
,
ua
,
urlInput
)
logrus
.
Info
(
"生产
一次 abck 耗时"
,
time
.
Since
(
t1
)
.
String
())
c
.
logger
.
Info
(
"生成
一次 abck 耗时"
,
time
.
Since
(
t1
)
.
String
())
t1
=
time
.
Now
()
sensor_data
:=
"{
\"
sensor_data
\"
:
\"
"
+
string
(
res
)
+
"
\"
}"
akmRes
,
err
:=
akmClient
.
Client
.
Post
(
"https://www.easyjet.com"
+
akmClient
.
SensorUrl
,
"application/json"
,
strings
.
NewReader
(
sensor_data
))
//akmRes, err := c.Client.Post("https://www.easyjet.com"+c.SensorUrl, "application/json", strings.NewReader(sensor_data))
statusCode
,
err
:=
c
.
PostJson
(
times
,
"https://www.easyjet.com"
+
c
.
SensorUrl
,
sensor_data
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
return
err
}
defer
akmRes
.
Body
.
Close
()
logrus
.
Info
(
"第"
,
times
,
"响应abck结果"
,
akmRes
.
StatusCode
,
"请求耗时"
,
time
.
Since
(
t1
)
.
String
())
return
akmRes
.
Cookies
()
c
.
logger
.
Info
(
"第"
,
times
,
"响应abck结果"
,
statusCode
,
"请求耗时"
,
time
.
Since
(
t1
)
.
String
())
//defer akmRes.Body.Close()
return
nil
}
func
GetCookie
()
(
string
,
string
)
{
func
(
c
*
AkmClient
)
GetCookie
()
(
string
,
string
)
{
uri
,
_
:=
url
.
Parse
(
"https://www.easyjet.com/en"
)
cookies
:=
akmClient
.
Jar
.
Cookies
(
uri
)
cookies
:=
c
.
Jar
.
Cookies
(
uri
)
abck
:=
""
bmsz
:=
""
for
_
,
v
:=
range
cookies
{
...
...
@@ -92,12 +137,13 @@ func GetCookie() (string, string) {
}
return
abck
,
bmsz
}
func
initAbck
(
url
string
)
string
{
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
url
,
nil
)
func
(
c
*
AkmClient
)
init
()
error
{
startTime
:=
time
.
Now
()
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
c
.
uri
,
nil
)
//req, err := http.NewRequest(http.MethodGet, "https://www.easyjet.com/ejavailability/api/v66/availability/query?AdditionalSeats=0&AdultSeats=1&ArrivalIata=LGW&ChildSeats=0&DepartureIata=BFS&IncludeAdminFees=true&IncludeFlexiFares=false&IncludeLowestFareSeats=true&IncludePrices=true&Infants=0&IsTransfer=false&LanguageCode=EN&MaxDepartureDate=2023-03-20&MinDepartureDate=2023-03-18", nil)
if
err
!=
nil
{
log
.
Println
(
err
)
return
""
c
.
logger
.
WithError
(
err
)
.
Errorln
(
"初始化abck请求失败"
)
return
err
}
req
.
Header
=
http
.
Header
{
...
...
@@ -111,59 +157,46 @@ func initAbck(url string) string {
},
}
resp
,
err
:=
akmClient
.
Client
.
Do
(
req
)
defer
resp
.
Body
.
Close
()
resp
,
err
:=
c
.
Client
.
Do
(
req
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
""
c
.
logger
.
WithError
(
err
)
.
Errorln
(
"abck请求失败"
)
return
err
}
defer
resp
.
Body
.
Close
()
readBytes
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
//fmt.Println(string(readBytes))
reg
,
_
:=
regexp
.
Compile
(
"</noscript><script type=
\"
text/javascript
\"
src=
\"
(.+?)
\"
></s"
)
matchs
:=
reg
.
FindStringSubmatch
(
string
(
readBytes
))
if
len
(
matchs
)
==
2
{
return
matchs
[
1
]
c
.
SensorUrl
=
matchs
[
1
]
}
else
{
c
.
logger
.
Errorln
(
"提取不到sensorUrl失败"
)
}
return
""
c
.
logger
.
Info
(
"初始化abck 耗时"
,
time
.
Since
(
startTime
)
.
String
())
return
nil
}
func
query
()
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"https://www.easyjet.com/ejavailability/api/v66/availability/query?AdditionalSeats=0&AdultSeats=1&ArrivalIata=LGW&ChildSeats=0&DepartureIata=BFS&IncludeAdminFees=true&IncludeFlexiFares=false&IncludeLowestFareSeats=true&IncludePrices=true&Infants=0&IsTransfer=false&LanguageCode=EN&MaxDepartureDate=2023-03-20&MinDepartureDate=2023-03-18"
,
nil
)
if
err
!=
nil
{
panic
(
err
)
}
req
.
Header
=
http
.
Header
{
"accept"
:
{
"*/*"
},
"accept-language"
:
{
"de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
},
"user-agent"
:
{
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36"
},
http
.
HeaderOrderKey
:
{
"accept"
,
"accept-language"
,
"user-agent"
,
},
}
resp
,
err
:=
akmClient
.
Client
.
Do
(
req
)
func
EasyJet
(
carrierType
,
proxyUrl
string
)
*
Akm
{
logger
:=
logrus
.
WithField
(
"typoe"
,
carrierType
)
logger
.
Info
(
"使用代理"
,
proxyUrl
)
akmClient
:=
NewAkmClient
(
proxyUrl
,
logger
)
akmClient
.
init
()
logger
.
Info
(
"请求sensor url:"
,
akmClient
.
SensorUrl
)
if
akmClient
.
SensorUrl
==
""
{
logger
.
Info
(
"sensorUrl 初始化失败"
)
return
nil
}
for
i
:=
0
;
i
<
3
;
i
++
{
err
:=
akmClient
.
GetAbck
(
i
,
"https://www.easyjet.com/en/buy/flights?isOneWay=on&pid=www.easyjet.com"
)
if
err
!=
nil
{
panic
(
err
)
logger
.
WithError
(
err
)
.
Errorln
(
"请求失败"
)
return
nil
}
defer
resp
.
Body
.
Close
()
fmt
.
Println
(
"响应结果"
,
resp
.
StatusCode
)
readBytes
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
fmt
.
Println
(
string
(
readBytes
))
}
func
EasyJet
(
proxyUrl
string
)
*
Akm
{
fmt
.
Println
(
"使用代理"
,
proxyUrl
)
akmClient
=
NewAkmClient
(
proxyUrl
)
url
:=
"https://www.easyjet.com/en"
akmClient
.
SensorUrl
=
initAbck
(
url
)
fmt
.
Println
(
"请求sensor url:"
,
akmClient
.
SensorUrl
)
GetAbck
(
0
,
"https://www.easyjet.com/en/buy/flights?isOneWay=on&pid=www.easyjet.com"
)
GetAbck
(
1
,
"https://www.easyjet.com/en/buy/flights?isOneWay=on&pid=www.easyjet.com"
)
GetAbck
(
2
,
"https://www.easyjet.com/en/buy/flights?isOneWay=on&pid=www.easyjet.com"
)
}
akm
:=
&
Akm
{
Cookies
:
GetAllCookie
(),
Cookies
:
akmClient
.
GetAllCookie
(),
Ua
:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50"
,
}
//query()
...
...
@@ -171,10 +204,10 @@ func EasyJet(proxyUrl string) *Akm {
}
func
GetAllCookie
()
map
[
string
]
string
{
func
(
c
*
AkmClient
)
GetAllCookie
()
map
[
string
]
string
{
res
:=
make
(
map
[
string
]
string
)
uri
,
_
:=
url
.
Parse
(
"https://www.easyjet.com/en"
)
cookies
:=
akmClient
.
Jar
.
Cookies
(
uri
)
cookies
:=
c
.
Jar
.
Cookies
(
uri
)
for
_
,
v
:=
range
cookies
{
res
[
v
.
Name
]
=
v
.
Value
...
...
model/init.go
View file @
d8fe0a64
...
...
@@ -14,20 +14,26 @@ func routeToU2(w http.ResponseWriter, r *http.Request) {
logrus
.
Info
(
"请求一次"
,
data
)
if
err
:=
checkPostRequire
(
data
);
err
==
false
{
util
.
WriteJson
(
w
,
util
.
ErrorJson
(
"请求参数不正确"
))
return
}
carrierType
:=
data
[
"type"
]
var
akm
*
Akm
switch
carrierType
{
case
"u2"
:
akm
=
EasyJet
(
data
[
"proxy"
]
.
(
string
))
akm
=
EasyJet
(
carrierType
.
(
string
),
data
[
"proxy"
]
.
(
string
))
default
:
util
.
WriteJson
(
w
,
util
.
ErrorJson
(
"不支持的航司"
))
return
}
logrus
.
Info
(
"请求结束 耗时"
,
time
.
Since
(
t1
)
.
String
())
if
akm
==
nil
{
util
.
WriteJson
(
w
,
&
util
.
Response
{
Code
:
500
,
Message
:
"请求超时"
,
})
return
}
cookies
:=
akm
.
Cookies
util
.
WriteJson
(
w
,
&
util
.
Response
{
...
...
test/test.go
View file @
d8fe0a64
...
...
@@ -16,7 +16,9 @@ import (
func
query
(
data
[]
byte
)
{
v
:=
model
.
Akm
{}
json
.
Unmarshal
(
data
,
&
v
)
fmt
.
Println
(
string
(
data
))
jar
:=
tls_client
.
NewCookieJar
()
options
:=
[]
tls_client
.
HttpClientOption
{
tls_client
.
WithTimeoutSeconds
(
30
),
...
...
@@ -24,7 +26,7 @@ func query(data []byte) {
tls_client
.
WithNotFollowRedirects
(),
tls_client
.
WithCookieJar
(
jar
),
// create cookieJar instance and pass it as argument
//tls_client.WithProxyUrl("http://user-unifflcc-region-us:q39CEBTs5A5YQXor@pr.roxlabs.cn:4600"),
tls_client
.
WithProxyUrl
(
"http://127.0.0.1:88
90
"
),
tls_client
.
WithProxyUrl
(
"http://127.0.0.1:88
88
"
),
tls_client
.
WithInsecureSkipVerify
(),
}
uri
,
_
:=
url
.
Parse
(
"https://www.easyjet.com/"
)
...
...
@@ -76,7 +78,7 @@ func main() {
//resp, err := http.Get("http://127.0.0.1:9999/ping")
//resp, err := http.Post("http://lcc.unififi.com/proxy/get-proxy", "application/json", strings.NewReader("{\n \"name\": \"NK\",\n \"type\": \"shopping\"\n}"))
t1
:=
time
.
Now
()
resp
,
err
:=
http
.
Post
(
"http://127.0.0.1:19999/akamai/gen"
,
"application/json"
,
strings
.
NewReader
(
"{
\"
type
\"
:
\"
u2
\"
,
\"
proxy
\"
:
\"
http://127.0.0.1:88
90
\"
}"
))
resp
,
err
:=
http
.
Post
(
"http://127.0.0.1:19999/akamai/gen"
,
"application/json"
,
strings
.
NewReader
(
"{
\"
type
\"
:
\"
u2
\"
,
\"
proxy
\"
:
\"
http://127.0.0.1:88
88
\"
}"
))
if
err
!=
nil
{
//panic(err)
fmt
.
Println
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment