单个账号流注册流程
This commit is contained in:
@@ -20,7 +20,20 @@ type BitBrowserService struct {
|
||||
var Browser libs.Browser
|
||||
var Chrome libs.Chrome
|
||||
|
||||
func (*BitBrowserService) CreateBrowser(proxy *models.Proxy) string {
|
||||
type BitCookieParam struct {
|
||||
Domain string `json:"domain"`
|
||||
ExpirationDate float64 `json:"expirationDate"` // 必须为 number
|
||||
HttpOnly bool `json:"httpOnly"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Secure bool `json:"secure"`
|
||||
Session bool `json:"session"`
|
||||
StoreID *string `json:"storeId"` // 允许 null,用指针
|
||||
Value string `json:"value"`
|
||||
SameSite *string `json:"sameSite,omitempty"` // 可选字段,不填时省略
|
||||
}
|
||||
|
||||
func (*BitBrowserService) CreateBrowser(proxy *models.Proxy, cookies []*proto.NetworkCookieParam) string {
|
||||
fingerprint := map[string]interface{}{
|
||||
"name": fmt.Sprintf(`推特注册%s`, utils.RandString(10)),
|
||||
"proxyMethod": 2,
|
||||
@@ -42,6 +55,25 @@ func (*BitBrowserService) CreateBrowser(proxy *models.Proxy) string {
|
||||
"resolutionType": "0",
|
||||
},
|
||||
}
|
||||
if cookies != nil {
|
||||
var cookie []BitCookieParam
|
||||
for _, v := range cookies {
|
||||
cookie = append(cookie, BitCookieParam{
|
||||
Domain: v.Domain,
|
||||
ExpirationDate: float64(v.Expires),
|
||||
HttpOnly: v.HTTPOnly,
|
||||
Name: v.Name,
|
||||
Path: v.Path,
|
||||
Secure: v.Secure,
|
||||
Session: false,
|
||||
StoreID: nil,
|
||||
Value: v.Value,
|
||||
SameSite: (*string)(&v.SameSite),
|
||||
})
|
||||
}
|
||||
data, _ := json.Marshal(cookie)
|
||||
fingerprint["cookie"] = data
|
||||
}
|
||||
if proxy != nil {
|
||||
var proxyHandle utils.ProxyHandle
|
||||
protocol, username, password, ip, port, err2 := proxyHandle.ParseProxy(proxy.Type + "://" + proxy.Proxy)
|
||||
@@ -72,7 +104,7 @@ func (*BitBrowserService) CreateBrowser(proxy *models.Proxy) string {
|
||||
UpdateTime: time.Now().Unix(),
|
||||
CreateTime: time.Now().Unix(),
|
||||
}
|
||||
if proxy != nil {
|
||||
if proxy != nil && proxy.Type != "" {
|
||||
params.Proxy = proxy.Type + "://" + proxy.Proxy
|
||||
}
|
||||
browserInstanceService.Create(params)
|
||||
@@ -81,6 +113,7 @@ func (*BitBrowserService) CreateBrowser(proxy *models.Proxy) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 获取当前浏览器的pid
|
||||
func (*BitBrowserService) GetPid(id string) int {
|
||||
// 获取当前
|
||||
bitBrowserRequest := utils.NewBitBrowserRequest()
|
||||
@@ -151,9 +184,9 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
|
||||
var browserId string
|
||||
// 创建新的浏览器
|
||||
if proxy != nil {
|
||||
browserId = bit.CreateBrowser(proxy)
|
||||
browserId = bit.CreateBrowser(proxy, nil)
|
||||
} else {
|
||||
browserId = bit.CreateBrowser(nil)
|
||||
browserId = bit.CreateBrowser(nil, nil)
|
||||
}
|
||||
// 打开浏览器
|
||||
if browserId == "" {
|
||||
@@ -167,15 +200,19 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
|
||||
emailService := InitEmailService()
|
||||
|
||||
emailInfo := emailService.GetEmailOne()
|
||||
log.Println("当前邮箱信息", emailInfo)
|
||||
obj := Browser.GetBitBrowser(ws)
|
||||
page := obj.Page
|
||||
page.MustNavigate("https://x.com/i/flow/signup").MustWaitLoad()
|
||||
// 点击创建账号
|
||||
createAccount := page.Timeout(5 * time.Second).MustElement(`button.css-175oi2r.r-sdzlij.r-1phboty.r-rs99b7.r-lrvibr.r-ywje51.r-184id4b.r-13qz1uu.r-2yi16.r-1qi8awa.r-3pj75a.r-1loqt21.r-o7ynqc.r-6416eg.r-1ny4l3l`)
|
||||
createAccount.MustClick()
|
||||
// 判断当前是否是邮箱注册
|
||||
_, err := page.Element(`input[name="email"]`)
|
||||
if err != nil {
|
||||
switchButton := page.Timeout(5 * time.Second).MustElement(`button.css-146c3p1.r-bcqeeo.r-qvutc0.r-1qd0xha.r-1ff274t.r-a023e6.r-rjixqe.r-16dba41`)
|
||||
switchButton.MustClick()
|
||||
}
|
||||
// _, err := page.Element(`input[name="email"]`)
|
||||
// if err != nil {
|
||||
switchButton := page.Timeout(5 * time.Second).MustElement(`button.css-146c3p1.r-bcqeeo.r-qvutc0.r-37j5jr.r-1ff274t.r-a023e6.r-rjixqe.r-16dba41`)
|
||||
switchButton.MustClick()
|
||||
// }
|
||||
// 获取邮箱输入框
|
||||
inputEmail := page.Timeout(5 * time.Second).MustElement(`input[name="email"]`)
|
||||
inputEmail.MustFocus()
|
||||
@@ -189,7 +226,7 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
|
||||
}
|
||||
inputName.MustInput(nameStr)
|
||||
// 随机生成生日
|
||||
dateParams := utils.RandDate(18, 100)
|
||||
dateParams := utils.RandDate(18, 80)
|
||||
dateSelects, _ := page.Timeout(5 * time.Second).Elements(`select.r-30o5oe.r-1niwhzg.r-17gur6a.r-1yadl64.r-18jsvk2.r-1loqt21.r-1inkyih.r-rjixqe.r-crgep1.r-1wzrnnt.r-1ny4l3l.r-t60dpp.r-xd6kpl.r-is05cd.r-ttdzmv`)
|
||||
// 月份
|
||||
dateSelects[0].WaitVisible()
|
||||
@@ -206,13 +243,24 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
|
||||
ocfSignupNextLink.MustClick()
|
||||
// 判断是否需要验证码
|
||||
time.Sleep(4 * time.Second)
|
||||
codeInput, err1 := page.Timeout(5 * time.Second).Element(`input[name="verfication_code"]`)
|
||||
_, err1 := page.Timeout(5 * time.Second).Element(`input[name="verfication_code"]`)
|
||||
if err1 != nil {
|
||||
// res := getApiResponse(page, "")
|
||||
}
|
||||
//TODO 对接获取邮箱信息接口
|
||||
time.Sleep(10 * time.Second)
|
||||
codeValue := LoopGetEmailCode("pop.dragonsmail.com:993", emailInfo.Email, emailInfo.Password)
|
||||
if codeValue == "0" {
|
||||
emailService.Update(emailInfo.Email, models.Email{
|
||||
Status: 0,
|
||||
})
|
||||
return libs.ErrorCode["MailboxUnavailable"]
|
||||
}
|
||||
// 获取邮箱验证码
|
||||
codeInput.MustInput("")
|
||||
log.Println("获取当前验证码", codeValue)
|
||||
codeInput1, _ := page.Timeout(5 * time.Second).Element(`input[name="verfication_code"]`)
|
||||
codeInput1.MustInput(codeValue)
|
||||
time.Sleep(2 * time.Second)
|
||||
// 点击下一步
|
||||
codeNextButton := page.Timeout(5 * time.Second).MustElement(`button.css-175oi2r.r-sdzlij.r-1phboty.r-rs99b7.r-lrvibr.r-19yznuf.r-64el8z.r-1fkl15p.r-1loqt21.r-o7ynqc.r-6416eg.r-1ny4l3l`)
|
||||
codeNextButton.MustClick()
|
||||
@@ -224,12 +272,15 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
|
||||
if err2 != nil {
|
||||
// res := getApiResponse(page, "")
|
||||
}
|
||||
|
||||
passwordInput.MustInput(emailInfo.Password)
|
||||
time.Sleep(5 * time.Second)
|
||||
// 点击下一步
|
||||
loginButton := page.Timeout(5 * time.Second).MustElement(`button[data-testid="LoginForm_Login_Button"]`)
|
||||
loginButton.MustClick()
|
||||
time.Sleep(5 * time.Second)
|
||||
page.MustNavigate("https://x.com").MustWaitLoad()
|
||||
time.Sleep(10 * time.Second)
|
||||
// 获取cookie
|
||||
cookieArr := getPageCookie(page, "https://x.com")
|
||||
// 创建用户
|
||||
@@ -243,13 +294,15 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
|
||||
Status: "注册成功",
|
||||
LoginStatus: "登录成功",
|
||||
Proxy: func() string {
|
||||
if proxy != nil {
|
||||
if proxy != nil && proxy.Type != "" {
|
||||
return proxy.Type + "://" + proxy.Proxy
|
||||
}
|
||||
return ""
|
||||
}(),
|
||||
})
|
||||
|
||||
emailService.Update(emailInfo.Email, models.Email{
|
||||
UseStatus: 1,
|
||||
})
|
||||
// 删除浏览器
|
||||
bit.DeleteBrowser(browserId)
|
||||
return libs.ErrorCode["RegisterSuccessful"]
|
||||
@@ -273,3 +326,20 @@ func getPageCookie(page *rod.Page, url string) []*proto.NetworkCookieParam {
|
||||
}
|
||||
return cookies
|
||||
}
|
||||
|
||||
// 循环获取3次验证码
|
||||
func LoopGetEmailCode(server, email, password string) string {
|
||||
var emailImap utils.EmailImap
|
||||
for i := 0; i < 3; i++ {
|
||||
codeValue := emailImap.GetMailCode(server, email, password)
|
||||
if codeValue != "0" {
|
||||
return codeValue
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
return "0"
|
||||
}
|
||||
|
||||
func (*BitBrowserService) AccountUnlock(id int64) *libs.ErrorInfo {
|
||||
return libs.ErrorCode["UnlockedSuccessfully"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user