新增修改注册流程

This commit is contained in:
zyj
2025-09-30 11:19:39 +08:00
parent 22e21f6eb8
commit dbf8b5bcca
9 changed files with 391 additions and 42 deletions

View File

@@ -35,24 +35,64 @@ type BitCookieParam struct {
func (*BitBrowserService) CreateBrowser(proxy *models.Proxy, cookies []*proto.NetworkCookieParam) string {
fingerprint := map[string]interface{}{
"name": fmt.Sprintf(`推特注册%s`, utils.RandString(10)),
"proxyMethod": 2,
"proxyType": "noproxy",
"host": "",
"port": 0,
"proxyUserName": "",
"proxyPassword": "",
"randomFingerprint": true,
"syncTabs": false,
"syncCookies": false,
"name": fmt.Sprintf(`推特注册%s`, utils.RandString(10)),
"proxyMethod": 2,
"proxyType": "noproxy",
"host": "",
"port": 0,
"proxyUserName": "",
"proxyPassword": "",
"randomFingerprint": true,
"syncTabs": false,
"syncCookies": false,
"browserFingerPrint": map[string]interface{}{
"coreVersion": "130",
"ostype": "PC",
"os": "Win32",
"osVersion": "11,10",
"openWidth": 1920,
"openHeight": 1480,
"resolutionType": "0",
// "coreVersion": "130",
// "ostype": "PC",
// "os": "Win32",
// "osVersion": "11,10",
// "openWidth": 1920,
// "openHeight": 1480,
// "resolutionType": "0",
// "userAgent": "", // ua不填则自动生成
// "isIpCreateTimeZone": true, // 基于IP生成对应的时区
// "timeZone": "", // 时区isIpCreateTimeZone 为false时参考附录中的时区列表
// "timeZoneOffset": 0, // isIpCreateTimeZone 为false时设置时区偏移量
// "webRTC": "3", //webrtc 0 => 替换, 1 => 允许, 2 => 禁止, 3 => 隐私
// "ignoreHttpsErrors": false, // 忽略https证书错误true, false
// "position": "1", //地理位置 0 => 询问, 1 => 允许, 2 => 禁止
// "isIpCreatePosition": true, // 是否基于IP生成对应的地理位置
// "lat": "", // 纬度 isIpCreatePosition 为false时设置
// "lng": "", // 经度 isIpCreatePosition 为false时设置
// "precisionData": "", //精度米 isIpCreatePosition 为false时设置
// "isIpCreateLanguage": true, // 是否基于IP生成对应国家的浏览器语言
// "languages": "", // isIpCreateLanguage 为false时设置值参考附录
// "isIpCreateDisplayLanguage": true, // 是否基于IP生成对应国家的浏览器界面语言
// "displayLanguages": "", // isIpCreateDisplayLanguage 为false时设置默认为空即跟随系统值参考附录
// "windowSizeLimit": true, // 分辨率类型为自定义且ostype为PC时此项有效约束窗口最大尺寸不超过分辨率
// "devicePixelRatio": 1, // 显示缩放比例默认1填写时建议 1, 1.5, 2, 2.5, 3
// "fontType": "2", // 字体生成类型 0 => 系统默认 | 2 => 随机
// "canvas": "0", //canvas 0随机1关闭
// "webGL": "0", //webGL图像0随机1关闭
// "webGLMeta": "0", //webgl元数据 0自定义1关闭
// "webGLManufacturer": "", // webGLMeta 自定义时webGL厂商值建议留空会自动生成
// "webGLRender": "", // webGLMeta自定义时webGL渲染值建议留空自动生成
// "audioContext": "0", // audioContext值0随机1关闭
// "mediaDevice": "0", // 媒体设备0 随机 | 1 关闭
// "speechVoices": "0", // Speech Voices0随机1关闭
// "hardwareConcurrency": "4", // 硬件并发数
// "deviceMemory": "8", // 设备内存48不要传入大于8的值
// "doNotTrack": "1", // doNotTrack 1开启0关闭
// "clientRectNoiseEnabled": true, // ClientRects true使用相匹配的值代替您真实的ClientRects | false每个浏览器使用当前电脑默认的ClientRects
// "portScanProtect": "0", // 端口扫描保护 0开启1关闭注意默认开启保护组织所有本地127的ws链接比如某些打印机之类的如有连接本地服务需求建议关闭或者在 portWhiteList 中,填写对应端口,加入白名单
// "portWhiteList": "", // 端口扫描保护开启时的白名单,逗号分隔
// "deviceInfoEnabled": true, // 自定义设备信息,默认开启
// "computerName": "", // deviceInfoEnabled 为true时设置建议留空系统自动生成即可
// "macAddr": "", // deviceInfoEnabled 为true时设置建议留空系统自动生成即可
// "disableSslCipherSuitesFlag": false, // ssl是否禁用特性默认不禁用注意开启后自定义设置时有可能会导致某些网站无法访问
// "disableSslCipherSuites": nil, // ssl 禁用特性序列化的ssl特性值参考附录
// "enablePlugins": false, // 是否启用插件指纹
// "plugins": "", // enablePlugins为true时序列化的插件值插件指纹值参考附录
// "launchArgs": "", // 启动参数,如无痕模式打开,那么设置启动参数为 "--incognito", 多个启动参数用逗号分隔,如 "--incognito,--no-sandbox"
},
}
if cookies != nil {
@@ -228,16 +268,31 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
// 随机生成生日
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`)
// 月份
log.Println(dateSelects)
fmt.Println(strconv.Itoa(dateParams.Month))
fmt.Println(strconv.Itoa(dateParams.Day))
fmt.Println(strconv.Itoa(dateParams.Year))
/// 月份
dateSelects[0].WaitVisible()
dateSelects[0].MustSelect(strconv.Itoa(dateParams.Month))
// 日期
dateSelects[1].WaitVisible()
dateSelects[1].MustSelect(strconv.Itoa(dateParams.Day))
opts, _ := dateSelects[0].Elements("option")
for i, opt := range opts {
txt, _ := opt.Text()
val, _ := opt.Attribute("value")
log.Printf("option[%d] text=%s value=%s\n", i, txt, *val)
if i != 0 && i == dateParams.Month {
dateSelects[0].MustSelect(txt)
}
}
// 年份
dateSelects[2].WaitVisible()
dateSelects[2].MustSelect(strconv.Itoa(dateParams.Year))
// 日期
dateSelects[1].WaitVisible()
dateSelects[1].MustSelect(strconv.Itoa(dateParams.Day))
// dateSelects[0].MustClick()
// monthOption := dateSelects[0].MustElement(fmt.Sprintf(`option[value="%d"]`, dateParams.Month))
// monthOption.MustClick()
time.Sleep(2 * time.Second)
// 点击下一步
ocfSignupNextLink := page.Timeout(5 * time.Second).MustElement(`button[data-testid="ocfSignupNextLink"]`)
ocfSignupNextLink.MustClick()
@@ -282,7 +337,7 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
page.MustNavigate("https://x.com").MustWaitLoad()
time.Sleep(10 * time.Second)
// 获取cookie
cookieArr := getPageCookie(page, "https://x.com")
cookieArr := GetPageCookie(page, "https://x.com")
// 创建用户
twitterAccountService := InitTwitterAccountService()
twitterAccountService.Create(&models.TwitterAccount{
@@ -303,14 +358,51 @@ func (bit *BitBrowserService) Register() *libs.ErrorInfo {
emailService.Update(emailInfo.Email, models.Email{
UseStatus: 1,
})
// 删除浏览器
bit.DeleteBrowser(browserId)
return libs.ErrorCode["RegisterSuccessful"]
// 设置fa2
page.MustNavigate("https://x.com/settings/account/login_verification").MustWaitLoad()
// 点击fa2按钮
inputCheckbox := page.Timeout(5 * time.Second).MustElement(`input[aria-describedby="CHECKBOX_2_LABEL"]`)
inputCheckbox.MustClick()
// 等待2秒
time.Sleep(2 * time.Second)
// 设置密码
inpurPassword, errPassword := page.Timeout(5 * time.Second).Element(`input[name="password"]`)
if errPassword == nil {
inpurPassword.MustInput(emailInfo.Password)
// 点击确认
faConfirm := page.Timeout(5 * time.Second).MustElement(`button[data-testid="LoginForm_Login_Button"]`)
faConfirm.MustClick()
}
// 等待2秒
time.Sleep(2 * time.Second)
ActionListNextButton := page.Timeout(5 * time.Second).MustElement(`button[data-testid="ActionListNextButton"]`)
ActionListNextButton.MustClick()
// 点击无法扫描二维码
queryCode := page.Timeout(5 * time.Second).MustElement("div.css-175oi2r.r-1awozwy.r-w7s2jr>div.css-175oi2r.r-95jzfe>div.css-146c3p1.r-bcqeeo.r-1ttztb7.r-qvutc0.r-37j5jr.r-a023e6.r-rjixqe.r-16dba41>button.css-1jxf684.r-bcqeeo.r-qvutc0.r-poiln3.r-fdjqy7")
queryCode.MustClick()
fa2Code := page.Timeout(5 * time.Second).MustElement(`div.css-146c3p1.r-bcqeeo.r-qvutc0.r-37j5jr.r-1blvdjr.r-vrz42v.r-b88u0q.r-x572qd.r-ywje51.r-1oqcu8e.r-q4m81j.r-13qz1uu`)
fa2CodeText := fa2Code.MustText()
log.Println("当前账号的二步验证码,", fa2CodeText)
ocfShowCodeNextLink := page.Timeout(5 * time.Second).MustElement(`button[data-testid="ocfShowCodeNextLink"]`)
ocfShowCodeNextLink.MustClick()
codeText, _ := utils.GetFA2Code(fa2CodeText)
ocfEnterTextTextInput := page.Timeout(5 * time.Second).MustElement(`input[data-testid="ocfEnterTextTextInput"]`)
ocfEnterTextTextInput.MustInput(codeText)
ocfEnterTextNextButton := page.Timeout(5 * time.Second).MustElement(`button[data-testid="ocfEnterTextNextButton"]`)
ocfEnterTextNextButton.MustClick()
OCF_CallToAction_Button, errOCF := page.Timeout(5 * time.Second).Element(`button[data-testid="OCF_CallToAction_Button"]`)
if errOCF == nil {
OCF_CallToAction_Button.MustClick()
}
// 删除浏览器
// bit.DeleteBrowser(browserId)
return libs.ErrorCode["RegisterSuccessful"]
}
// 获取指定页面的cookie列表
func getPageCookie(page *rod.Page, url string) []*proto.NetworkCookieParam {
func GetPageCookie(page *rod.Page, url string) []*proto.NetworkCookieParam {
cookieArr, _ := page.Cookies([]string{url})
var cookies []*proto.NetworkCookieParam
for _, cookie := range cookieArr {