Skip to content

Commit 4f54082

Browse files
author
bajins
committed
fixed 获取xshell失败
1 parent 75cd6ac commit 4f54082

File tree

2 files changed

+49
-26
lines changed

2 files changed

+49
-26
lines changed

reptile/Netsarang.go

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"tool-gin/utils"
2929
)
3030

31-
const NetsarangJsonUrl = "https://www.netsarang.com/json/download/process.html"
31+
const NetsarangJsonUrl = "https://update.netsarang.com/json/download/process.html"
3232

3333
var (
3434
NetsarangMap map[string]NetsarangInfo
@@ -190,49 +190,68 @@ func NetsarangSendMail(mail, product string) error {
190190
return errors.New("产品不能为空!")
191191
}
192192

193-
productCode := ""
194193
productName := ""
195194
switch strings.ToLower(product) {
196195
case "xshell":
197-
productCode = "4203"
198196
productName = "xshell-download"
199197
case "xftp":
200-
productCode = "4242"
201198
productName = "xftp-download"
202199
case "xlpd":
203-
productCode = "4280"
204200
productName = "xlpd-download"
205201
case "xmanager":
206-
productCode = "4162"
207202
productName = "xmanager-download"
208203
case "xshellplus":
209-
productCode = "4132"
210204
productName = "xshell-plus-download"
211205
case "powersuite":
212-
productCode = "4066"
213206
productName = "xmanager-power-suite-download"
214207
}
215-
if productCode == "" || productName == "" {
208+
if productName == "" {
216209
return errors.New("产品不匹配")
217210
}
218-
data := map[string]string{
219-
"_wpcf7": "3016",
220-
"_wpcf7_version": "5.1.1",
221-
"_wpcf7_locale": "en_US",
222-
"_wpcf7_unit_tag": "wpcf7-f3016-p" + productCode + "-o2",
223-
"_wpcf7_container_post": productCode,
224-
"g-recaptcha-response": "",
225-
"md": "setDownload",
226-
"language": "3",
227-
"downloadType": "0",
228-
"licenseType": "0",
229-
"action": "/json/download/process.html",
230-
"user-name": mail,
231-
"email": mail,
232-
"company": "",
233-
"productName": productName,
234-
}
211+
// 请求并获取发送邮件的表单
235212
httpClient := utils.HttpClient{
213+
Method: http.MethodGet,
214+
UrlText: "https://www.netsarang.com/" + productName,
215+
ContentType: utils.ContentTypeMFD,
216+
Header: nil,
217+
}
218+
body, err := httpClient.ReadBody()
219+
if err != nil {
220+
return err
221+
}
222+
// 解析HTML
223+
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(body))
224+
if err != nil {
225+
return err
226+
}
227+
// 找到最后一个form
228+
form := doc.Find(`form[novalidate="novalidate"]`).Last()
229+
if form.Length() < 1 {
230+
return errors.New("没有找到提交表单")
231+
}
232+
// 查找请求数据并构造
233+
inputs := form.Find(`input[type="hidden"],input[type="text"],input[type="email"]`)
234+
if inputs.Length() < 1 {
235+
return errors.New("没有找到请求数据")
236+
}
237+
// 使用make函数创建一个非nil的map,nil map不能赋值
238+
data := make(map[string]string)
239+
inputs.Each(func(i int, selection *goquery.Selection) {
240+
name, nbl := selection.Attr("name")
241+
value, vbl := selection.Attr("value")
242+
if nbl && vbl {
243+
data[name] = value
244+
}
245+
})
246+
if data == nil {
247+
return errors.New("构造请求数据失败")
248+
}
249+
data["user-name"] = mail
250+
data["email"] = mail
251+
data["productName"] = productName
252+
log.Println("构造数据:", data)
253+
// 请求发送邮件
254+
httpClient = utils.HttpClient{
236255
Method: http.MethodPost,
237256
UrlText: NetsarangJsonUrl,
238257
ContentType: utils.ContentTypeMFD,

reptile/mail.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func LinShiYouXiangSuffix() (string, error) {
3939
m := htmlquery.InnerText(row)
4040
suffixArray = append(suffixArray, m)
4141
}
42+
suffixArrayLen := len(suffixArray)
43+
if suffixArrayLen == 0 {
44+
return "", nil
45+
}
4246
return suffixArray[utils.RandIntn(len(suffixArray)-1)], nil
4347
}
4448

0 commit comments

Comments
 (0)