Skip to content

Commit

Permalink
fixed get xshell download url
Browse files Browse the repository at this point in the history
  • Loading branch information
woetu committed May 20, 2021
1 parent 827d4c5 commit a17d4fa
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 63 deletions.
30 changes: 21 additions & 9 deletions reptile/Netsarang.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ func GetInfoUrl(product string) (string, error) {

// NetsarangGetMail 获取可用mail
func NetsarangGetMail() (string, error) {
prefix := utils.RandomLowercaseAlphanumeric(9)
/*prefix := utils.RandomLowercaseAlphanumeric(9)
suffix, err := LinShiYouXiangSuffix()
if err != nil {
return "", err
}
_, err = LinShiYouXiangApply(prefix)
if err != nil {
return "", err
}*/
mailUser, err := GetSecmailUser()
if err != nil {
return "", err
}
mail := prefix + suffix
mail := mailUser[0] + "@" + mailUser[1]
log.Println("邮箱号:", mail)
return mail, nil
}
Expand Down Expand Up @@ -111,10 +115,11 @@ func NetsarangGetInfo(mail, product string) (string, error) {
if err != nil {
return "", err
}
prefix := strings.Split(mail, "@")[0]
//prefix := strings.Split(mail, "@")[0]

time.Sleep(10 * time.Second)
mailList, err := LinShiYouXiangList(prefix)
//mailList, err := LinShiYouXiangList(prefix)
mailList, err := GetSecmailList()
if err != nil {
return "", err
}
Expand All @@ -123,29 +128,36 @@ func NetsarangGetInfo(mail, product string) (string, error) {
break
}
time.Sleep(10 * time.Second)
mailList, err = LinShiYouXiangList(prefix)
//mailList, err = LinShiYouXiangList(prefix)
mailList, err = GetSecmailList()
if err != nil {
return "", err
}
}
if len(mailList) == 0 {
return "", errors.New("没有邮件")
}
mailId := mailList[len(mailList)-1]["id"].(string)
//mailId := mailList[len(mailList)-1]["id"].(string)
mailId, err := GetSecmailLatestId(mailList)
if err != nil {
return "", err
}
if mailId == "" {
return "", errors.New("邮件ID不存在")
}
// 获取最新一封邮件
msg, err := LinShiYouXiangGetMail(prefix, mailId)
/*msg, err := LinShiYouXiangGetMail(prefix, mailId)
if err != nil {
return "", err
}
htmlText, err := DecodeMail(msg)
htmlText, err := DecodeMail(msg)*/
msg, err := GetSecmailMessage(mailId)
if err != nil {
return "", err
}
htmlText := msg["body"].(string)
// 解析HTML
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(htmlText))
doc, err := goquery.NewDocumentFromReader(bytes.NewReader([]byte(htmlText)))
if err != nil {
return "", err
}
Expand Down
67 changes: 65 additions & 2 deletions reptile/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ package reptile

import (
"encoding/base64"
"encoding/json"
"errors"
"github.com/antchfx/htmlquery"
"github.com/chromedp/cdproto/page"
"github.com/chromedp/chromedp"
"log"
"math"
"math/big"
"net/http"
"net/mail"
"strings"
Expand All @@ -41,6 +44,65 @@ func DecodeMail(msg *mail.Message) ([]byte, error) {
return nil, errors.New("解码方式错误:" + encoding)
}

const secmail1 = "https://www.1secmail.com/api/v1/"

var mailUser []string

// GetSecmailUser 获取一次性邮箱
func GetSecmailUser() ([]string, error) {
if len(mailUser) == 0 || mailUser == nil {
// 获取邮箱
res, err := utils.HttpReadBodyString(http.MethodGet, secmail1+"?action=genRandomMailbox&count=1", "",
nil, nil)
if err != nil {
return nil, err
}
var data []interface{}
err = json.Unmarshal([]byte(res), &data)
mailUser = strings.Split(data[0].(string), "@") // 获取用户名和域名
}
return mailUser, nil
}

// GetSecmailList 获取邮件列表
func GetSecmailList() ([]map[string]interface{}, error) {
mailListUrl := secmail1 + "?action=getMessages&login=" + mailUser[0] + "&domain=" + mailUser[1]
// 获取邮件列表
return utils.HttpReadBodyJsonMapArray(http.MethodGet, mailListUrl, "", nil, nil)
}

// GetSecmailLatestId 获取最新一封邮件ID
func GetSecmailLatestId(mailList []map[string]interface{}) (string, error) {
if mailList == nil || len(mailList) == 0 {
// 获取邮件列表
mailList, err := GetSecmailList()
if err != nil {
return "", err
}
log.Println(mailList, err, mailUser)
}
if len(mailList) == 0 {
return "", errors.New("没有邮件")
}
// 科学计数法转换string数字
newNum := big.NewRat(1, 1)
newNum.SetFloat64(mailList[0]["id"].(float64))
id := newNum.FloatString(0)
return id, nil
}

// GetSecmailMessage 获取邮件内容
func GetSecmailMessage(id string) (map[string]interface{}, error) {
mailMessageUrl := secmail1 + "?action=readMessage&login=" + mailUser[0] + "&domain=" + mailUser[1] + "&id=" + id
// 获取邮件内容
message, err := utils.HttpReadBodyJsonMap(http.MethodGet, mailMessageUrl, "", nil, nil)
if err != nil {
return nil, err
}
//log.Println(message, err, mailUser)
return message, err
}

const LinShiYouXiang = "https://www.linshiyouxiang.net"

// LinShiYouXiangSuffix 获取邮箱号后缀
Expand Down Expand Up @@ -75,14 +137,15 @@ func LinShiYouXiangApply(prefix string) (map[string]interface{}, error) {
"mailbox": prefix,
"_ts": utils.ToString(math.Round(float64(time.Now().Unix() / 1000))),
}
return utils.HttpReadBodyJsonMap(http.MethodGet, url, "", param, nil)
r, e := utils.HttpReadBodyJsonMap(http.MethodGet, url, "", param, nil)
return r, e
}

// LinShiYouXiangList 获取邮件列表
// prefix: 邮箱前缀
func LinShiYouXiangList(prefix string) ([]map[string]interface{}, error) {
url := LinShiYouXiang + "/api/v1/mailbox/" + prefix
return utils.HttpReadBodyJsonArray(http.MethodGet, url, "", nil, nil)
return utils.HttpReadBodyJsonMapArray(http.MethodGet, url, "", nil, nil)
}

// LinShiYouXiangGetMail 获取邮件内容
Expand Down
84 changes: 84 additions & 0 deletions reptile/mail_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package reptile

import (
"bytes"
"fmt"
"github.com/chromedp/chromedp"
"log"
"math/big"
"net/http"
"net/mail"
"strings"
"testing"
"tool-gin/utils"
)

// https://pkg.go.dev/net/mail#ReadMessage
func TestMail(t *testing.T) {
msg := "Received: from a27-154.smtp-out.us-west-2.amazonses.com ([54.240.27.154]) by temporary-mail.net\n for <[email protected]>; Wed, 21 Apr 2021 13:29:21 +0800 (CST)\nDKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=n6yk34xlzntpmtevqgs5ghp2jksprvft; d=netsarang.com; t=1618982959;\n\th=Date:To:From:Reply-To:Subject:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding;\n\tbh=OsRfLaUS97/+yRoJ/BSpIARvBe+S33pKrzp1it7xCyQ=;\n\tb=LTblU9qEhTeorpht/julhD6ar7a6MDmEI9zH3TBy28KI6ah7Q+E1J0fAML2Pbcd0\n\tqX/68C8+vtGD03BGEzVPjJTJDoztO0qoNz5l7C/DSGV1MEyxh8ccQtW7rw+7+kQXv/+\n\tBKztqxpwXMjNuzZb3E0W1GYju0kr4qT5nXkMXD5o=\nDKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=7v7vs6w47njt4pimodk5mmttbegzsi6n; d=amazonses.com; t=1618982959;\n\th=Date:To:From:Reply-To:Subject:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID;\n\tbh=OsRfLaUS97/+yRoJ/BSpIARvBe+S33pKrzp1it7xCyQ=;\n\tb=NhCoNeJCoIpySzLuSxUV5P0zlsh4pLKUz5bhIG3spGhLgW0Pzf/1ZHyJJOTL9T3C\n\tDi7ChUyfnWdRjWSp+7EiA4VNrqGtOzoOsMZKipURghknjlG8bYjpCpdGXrO1D5IBlIj\n\tCl8sZevNShTh++kQW27S4S83cuDhbwxGEgxhSy3k=\nDate: Wed, 21 Apr 2021 05:29:19 +0000\nTo: [email protected]\nFrom: \"NetSarang, Inc.\" <[email protected]>\nReply-To: [email protected]\nSubject: Xshell 7 download instruction\nMessage-ID: <01010178f2e77a87-c9bb10f6-ef08-4dad-ba57-4524546de5d2-000000@us-west-2.amazonses.com>\nX-Mailer: PHPMailer 5.2.10 (https://github.com/PHPMailer/PHPMailer/)\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\nContent-Transfer-Encoding: base64\nFeedback-ID: 1.us-west-2.l7ekw14vD6Jumpwas0GHbg0O54ld7FbCklw8tqJLu88=:AmazonSES\nX-S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0cj48dGQ+\nUGhvbmU6ICg2NjkpIDIwNC0zMzAxPC90ZD48L3RyPg0KPC90Ym9keT4NCjwvdGFibGU+DQo=\n\n"
r := strings.NewReader(msg)
m, err := mail.ReadMessage(r)
if err != nil {
log.Fatal(err)
}
header := m.Header
fmt.Println("Date:", header.Get("Date"))
fmt.Println("From:", header.Get("From"))
fmt.Println("To:", header.Get("To"))
fmt.Println("Subject:", header.Get("Subject"))
fmt.Println("Content-Transfer-Encoding:", header.Get("Content-Transfer-Encoding"))

buf := new(bytes.Buffer) // io.ReadCloser类型转换为string
buf.ReadFrom(m.Body)
b := buf.String()
fmt.Println("-------", b)
}

func TestLinShiYouXiangSuffix(t *testing.T) {
LinShiYouXiangSuffix()
}

func TestLinShiYouXiangList(t *testing.T) {
list, _ := LinShiYouXiangList("5wij52emu")
t.Log(list)
}

func TestGetMail24(t *testing.T) {
//GetMail24()
var test string
//ctx, cancel := Apply(true)
//defer cancel()
ctx, _ := Apply(true)
err := chromedp.Run(ctx, GetMail24MailName(&test))
t.Log(err)
t.Log(test)
err = chromedp.Run(ctx, GetMail24LatestMail(&test))
t.Log(err)
fmt.Println(test)
}

func TestGetSecmail(t *testing.T) {
// 获取邮箱
/*res, err := utils.HttpReadBodyString(http.MethodGet, secmail1+"?action=genRandomMailbox&count=1", "",
nil, nil)
var data []interface{}
err = json.Unmarshal([]byte(res), &data)
fmt.Println(res, err)
r := strings.Split(data[0].(string), "@") // 获取用户名和域名*/
//url := secmail1 + "?action=getMessages&login=" + r[0] + "&domain=" + r[1]
url := secmail1 + "?action=getMessages&login=qw7dtxz8gu&domain=1secmail.org"
// 获取邮件列表
mailList, err := utils.HttpReadBodyJsonMapArray(http.MethodGet, url, "", nil, nil)
fmt.Println(mailList, err)
if len(mailList) == 0 {
return
}
// 科学计数法转换string数字
newNum := big.NewRat(1, 1)
newNum.SetFloat64(mailList[0]["id"].(float64))
id := newNum.FloatString(0)
// 获取邮件内容
m, err := utils.HttpReadBodyJsonMap(http.MethodGet, secmail1+"?action=readMessage&login=qw7dtxz8gu&domain=1secmail.org&id="+id, "",
nil, nil)
fmt.Println(m, err)
}
49 changes: 0 additions & 49 deletions reptile/reptile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,12 @@
package reptile

import (
"bytes"
"fmt"
"github.com/chromedp/cdproto/target"
"github.com/chromedp/chromedp"
"log"
"net/mail"
"strings"
"testing"
"time"
)

func TestLinShiYouXiangSuffix(t *testing.T) {
LinShiYouXiangSuffix()
}

func TestLinShiYouXiangList(t *testing.T) {
list, _ := LinShiYouXiangList("5wij52emu")
t.Log(list)
}

func TestGetMail24(t *testing.T) {
//GetMail24()
var test string
//ctx, cancel := Apply(true)
//defer cancel()
ctx, _ := Apply(true)
err := chromedp.Run(ctx, GetMail24MailName(&test))
t.Log(err)
t.Log(test)
err = chromedp.Run(ctx, GetMail24LatestMail(&test))
t.Log(err)
fmt.Println(test)
}

func TestApply(t *testing.T) {
ctx, cancel := Apply(false)
defer cancel()
Expand All @@ -71,24 +43,3 @@ func TestApply(t *testing.T) {
t.Log(err)
t.Log(res)
}

// https://pkg.go.dev/net/mail#ReadMessage
func TestMail(t *testing.T) {
msg := "Received: from a27-154.smtp-out.us-west-2.amazonses.com ([54.240.27.154]) by temporary-mail.net\n for <[email protected]>; Wed, 21 Apr 2021 13:29:21 +0800 (CST)\nDKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=n6yk34xlzntpmtevqgs5ghp2jksprvft; d=netsarang.com; t=1618982959;\n\th=Date:To:From:Reply-To:Subject:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding;\n\tbh=OsRfLaUS97/+yRoJ/BSpIARvBe+S33pKrzp1it7xCyQ=;\n\tb=LTblU9qEhTeorpht/julhD6ar7a6MDmEI9zH3TBy28KI6ah7Q+E1J0fAML2Pbcd0\n\tqX/68C8+vtGD03BGEzVPjJTJDoztO0qoNz5l7C/DSGV1MEyxh8ccQtW7rw+7+kQXv/+\n\tBKztqxpwXMjNuzZb3E0W1GYju0kr4qT5nXkMXD5o=\nDKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=7v7vs6w47njt4pimodk5mmttbegzsi6n; d=amazonses.com; t=1618982959;\n\th=Date:To:From:Reply-To:Subject:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID;\n\tbh=OsRfLaUS97/+yRoJ/BSpIARvBe+S33pKrzp1it7xCyQ=;\n\tb=NhCoNeJCoIpySzLuSxUV5P0zlsh4pLKUz5bhIG3spGhLgW0Pzf/1ZHyJJOTL9T3C\n\tDi7ChUyfnWdRjWSp+7EiA4VNrqGtOzoOsMZKipURghknjlG8bYjpCpdGXrO1D5IBlIj\n\tCl8sZevNShTh++kQW27S4S83cuDhbwxGEgxhSy3k=\nDate: Wed, 21 Apr 2021 05:29:19 +0000\nTo: [email protected]\nFrom: \"NetSarang, Inc.\" <[email protected]>\nReply-To: [email protected]\nSubject: Xshell 7 download instruction\nMessage-ID: <01010178f2e77a87-c9bb10f6-ef08-4dad-ba57-4524546de5d2-000000@us-west-2.amazonses.com>\nX-Mailer: PHPMailer 5.2.10 (https://github.com/PHPMailer/PHPMailer/)\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\nContent-Transfer-Encoding: base64\nFeedback-ID: 1.us-west-2.l7ekw14vD6Jumpwas0GHbg0O54ld7FbCklw8tqJLu88=:AmazonSES\nX-SES-Outgoing: 2021.04.21-54.240.27.154\n\nPHNwYW4+RGVhciB1c2VyLDwvc3Bhbj4NCjxiciAvPjxiciAvPg0KPHNwYW4+VGhhbmsgeW91IGZv\nciB5b3VyIGludGVyZXN0IGluIFhzaGVsbCA3LiBXZSBoYXZlIHByZXBhcmVkIHlvdXIgZXZhbHVh\ndGlvbiBwYWNrYWdlLiBJZiB5b3UgZGlkIG5vdCByZXF1ZXN0IGFuIGV2YWx1YXRpb24gb2YgWHNo\nZWxsIDcsIHBsZWFzZSBjb250YWN0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VhdGlvbiBw\nZXJpb2QuIElmIHlvdSBoYXZlIGFueSBxdWVzdGlvbnMsIHBsZWFzZSBzZW5kIHVzIGFuIGVtYWls\nIGF0IDxhIGhyZWY9Im1haWx0bzpzdXBwb3J0QG5ldHNhcmFuZy5jb20iPnN1cHBvcnRAbmV0c2Fy\nYW5nLmNvbTwvYT4uPC9zcGFuPg0KPGJyIC8+PGJyIC8+PGJyIC8+DQo8c3Bhbj5CZXN0IHJlZ2Fy\nZHMsPC9zcGFuPg0KPGJyIC8+PGJyIC8+PGJyIC8+DQo8dGFibGUgYm9yZGVyPSIwIiBjZWxscGFk\nZGluZz0iMCIgY2VsbHNwYWNpbmc9IjAiPg0KPHRib2R5Pg0KPHRyPjx0ZD49PT09PT09PT09PT09\nPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PC90\nZD48L3RyPg0KPHRyPjx0ZD5OZXRTYXJhbmcsIEluYy48L3RkPjwvdHI+DQo8dHI+PHRkPjQ3MDEg\nUGF0cmljayBIZW5yeSBEci4gQkxERyAyMiwgU3VpdGUgMTM3LCBTYW50YSBDbGFyYSwgQ0EgOTUw\nNTQsIFUuUy5BLjwvdGQ+PC90cj4NCjx0cj48dGQ+V2Vic2l0ZTogaHR0cDovL3d3dy5uZXRzYXJh\nbmcuY29tIHwgRW1haWw6IHN1cHBvcnRAbmV0c2FyYW5nLmNvbTwvdGQ+PC90cj4NCjx0cj48dGQ+\nUGhvbmU6ICg2NjkpIDIwNC0zMzAxPC90ZD48L3RyPg0KPC90Ym9keT4NCjwvdGFibGU+DQo=\n\n"
r := strings.NewReader(msg)
m, err := mail.ReadMessage(r)
if err != nil {
log.Fatal(err)
}
header := m.Header
fmt.Println("Date:", header.Get("Date"))
fmt.Println("From:", header.Get("From"))
fmt.Println("To:", header.Get("To"))
fmt.Println("Subject:", header.Get("Subject"))
fmt.Println("Content-Transfer-Encoding:", header.Get("Content-Transfer-Encoding"))

buf := new(bytes.Buffer) // io.ReadCloser类型转换为string
buf.ReadFrom(m.Body)
b := buf.String()
fmt.Println("-------", b)
}
25 changes: 22 additions & 3 deletions utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ func HttpReadBodyJsonMap(method, urlText, contentType string, params, header map
return data, nil
}

// HttpReadBodyJsonArray 请求并读取返回内容为json数组
func HttpReadBodyJsonArray(method, urlText, contentType string, params, header map[string]string) ([]map[string]interface{}, error) {
// HttpReadBodyJsonMapArray 请求并读取返回内容为json Map数组
func HttpReadBodyJsonMapArray(method, urlText, contentType string, params,
header map[string]string) ([]map[string]interface{}, error) {
res, err := HttpReadBody(method, urlText, contentType, params, header)
if err != nil {
return nil, err
Expand All @@ -263,6 +264,20 @@ func HttpReadBodyJsonArray(method, urlText, contentType string, params, header m
return data, nil
}

// HttpReadBodyJsonArray 请求并读取返回内容为json数组
func HttpReadBodyJsonArray(method, urlText, contentType string, params, header map[string]string) ([]interface{}, error) {
res, err := HttpReadBody(method, urlText, contentType, params, header)
if err != nil {
return nil, err
}
var data []interface{}
err = json.Unmarshal(res, &data)
if err != nil {
return nil, err
}
return data, nil
}

type HttpClient struct {
Method string
UrlText string
Expand Down Expand Up @@ -291,6 +306,10 @@ func (hc *HttpClient) HttpReadBodyJsonMap() (map[string]interface{}, error) {
return HttpReadBodyJsonMap(hc.Method, hc.UrlText, hc.ContentType, hc.Params, hc.Header)
}

func (hc *HttpClient) ReadBodyJsonArray() ([]map[string]interface{}, error) {
func (hc *HttpClient) HttpReadBodyJsonMapArray() ([]map[string]interface{}, error) {
return HttpReadBodyJsonMapArray(hc.Method, hc.UrlText, hc.ContentType, hc.Params, hc.Header)
}

func (hc *HttpClient) ReadBodyJsonArray() ([]interface{}, error) {
return HttpReadBodyJsonArray(hc.Method, hc.UrlText, hc.ContentType, hc.Params, hc.Header)
}

0 comments on commit a17d4fa

Please sign in to comment.