@@ -14,11 +14,14 @@ package reptile
1414
1515import (
1616 "encoding/base64"
17+ "encoding/json"
1718 "errors"
1819 "github.com/antchfx/htmlquery"
1920 "github.com/chromedp/cdproto/page"
2021 "github.com/chromedp/chromedp"
22+ "log"
2123 "math"
24+ "math/big"
2225 "net/http"
2326 "net/mail"
2427 "strings"
@@ -41,6 +44,65 @@ func DecodeMail(msg *mail.Message) ([]byte, error) {
4144 return nil , errors .New ("解码方式错误:" + encoding )
4245}
4346
47+ const secmail1 = "https://www.1secmail.com/api/v1/"
48+
49+ var mailUser []string
50+
51+ // GetSecmailUser 获取一次性邮箱
52+ func GetSecmailUser () ([]string , error ) {
53+ if len (mailUser ) == 0 || mailUser == nil {
54+ // 获取邮箱
55+ res , err := utils .HttpReadBodyString (http .MethodGet , secmail1 + "?action=genRandomMailbox&count=1" , "" ,
56+ nil , nil )
57+ if err != nil {
58+ return nil , err
59+ }
60+ var data []interface {}
61+ err = json .Unmarshal ([]byte (res ), & data )
62+ mailUser = strings .Split (data [0 ].(string ), "@" ) // 获取用户名和域名
63+ }
64+ return mailUser , nil
65+ }
66+
67+ // GetSecmailList 获取邮件列表
68+ func GetSecmailList () ([]map [string ]interface {}, error ) {
69+ mailListUrl := secmail1 + "?action=getMessages&login=" + mailUser [0 ] + "&domain=" + mailUser [1 ]
70+ // 获取邮件列表
71+ return utils .HttpReadBodyJsonMapArray (http .MethodGet , mailListUrl , "" , nil , nil )
72+ }
73+
74+ // GetSecmailLatestId 获取最新一封邮件ID
75+ func GetSecmailLatestId (mailList []map [string ]interface {}) (string , error ) {
76+ if mailList == nil || len (mailList ) == 0 {
77+ // 获取邮件列表
78+ mailList , err := GetSecmailList ()
79+ if err != nil {
80+ return "" , err
81+ }
82+ log .Println (mailList , err , mailUser )
83+ }
84+ if len (mailList ) == 0 {
85+ return "" , errors .New ("没有邮件" )
86+ }
87+ // 科学计数法转换string数字
88+ newNum := big .NewRat (1 , 1 )
89+ newNum .SetFloat64 (mailList [0 ]["id" ].(float64 ))
90+ id := newNum .FloatString (0 )
91+ return id , nil
92+ }
93+
94+ // GetSecmailMessage 获取邮件内容
95+ func GetSecmailMessage (id string ) (map [string ]interface {}, error ) {
96+ mailMessageUrl := secmail1 + "?action=readMessage&login=" + mailUser [0 ] + "&domain=" + mailUser [1 ] + "&id=" + id
97+ // 获取邮件内容
98+ message , err := utils .HttpReadBodyJsonMap (http .MethodGet , mailMessageUrl , "" , nil , nil )
99+ if err != nil {
100+ return nil , err
101+ }
102+ //log.Println(message, err, mailUser)
103+ return message , err
104+ }
105+
44106const LinShiYouXiang = "https://www.linshiyouxiang.net"
45107
46108// LinShiYouXiangSuffix 获取邮箱号后缀
@@ -75,14 +137,15 @@ func LinShiYouXiangApply(prefix string) (map[string]interface{}, error) {
75137 "mailbox" : prefix ,
76138 "_ts" : utils .ToString (math .Round (float64 (time .Now ().Unix () / 1000 ))),
77139 }
78- return utils .HttpReadBodyJsonMap (http .MethodGet , url , "" , param , nil )
140+ r , e := utils .HttpReadBodyJsonMap (http .MethodGet , url , "" , param , nil )
141+ return r , e
79142}
80143
81144// LinShiYouXiangList 获取邮件列表
82145// prefix: 邮箱前缀
83146func LinShiYouXiangList (prefix string ) ([]map [string ]interface {}, error ) {
84147 url := LinShiYouXiang + "/api/v1/mailbox/" + prefix
85- return utils .HttpReadBodyJsonArray (http .MethodGet , url , "" , nil , nil )
148+ return utils .HttpReadBodyJsonMapArray (http .MethodGet , url , "" , nil , nil )
86149}
87150
88151// LinShiYouXiangGetMail 获取邮件内容
0 commit comments