From 8d5beec179c43cf8d7bdeec44d929ba3d41a7ef6 Mon Sep 17 00:00:00 2001 From: yema <1304119519@qq.com> Date: Thu, 8 Jun 2023 13:00:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E7=94=B3=E8=AF=B7=204.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/gpt/batchApplication.ts | 101 ++++++++++++++++++++++---- electron/main/gpt/index.ts | 4 +- electron/main/index.ts | 13 ++++ electron/main/poe/index.js | 4 - package.json | 3 +- src/App.vue | 2 +- 6 files changed, 106 insertions(+), 21 deletions(-) diff --git a/electron/main/gpt/batchApplication.ts b/electron/main/gpt/batchApplication.ts index a677cc4..afc372d 100644 --- a/electron/main/gpt/batchApplication.ts +++ b/electron/main/gpt/batchApplication.ts @@ -6,38 +6,76 @@ import { awaitWrap, randomNum } from '../tools'; import Mock from 'mockjs' import axios from 'axios' import { SocksProxyAgent } from 'socks-proxy-agent' +import proxyChain from 'proxy-chain' +// const proxyChain = require('proxy-chain'); puppeteer.use(StealthPlugin()) -function getProxy() { - return axios.get('http://api.proxy.ipidea.io/getBalanceProxyIp?num=1&return_type=json&lb=1&sb=0&flow=1®ions=us&protocol=socks5').then(res => { - return res.data.data[0] +function getProxy(options = {} as any) { + const log = clog(options) + log('开始获取代理ip') + // return axios.get('https://tq.lunaproxy.com/getflowip?neek=1037914&num=1&type=1&sep=1®ions=us&ip_si=1&level=1&sb=', { + // // return axios.get('https://www.miyaip.com/api/ProxyGenerage/PublicGenerateProxy?country=us&city=jaffrey®ion=nh&num=1&apiSwitch=0&mealType=2&genType=2&username=nmfk549724@163.com&secret=E3BCBmiyaipC23358C250F5', { + // // return axios.get('http://api.tianqiip.com/getip?secret=loy0r7fpmnlshm8l&num=1&type=json&port=3&time=3&mr=1&sign=5f73ab58ad7ab40346311014bef59b79', { + // timeout: 10 * 1000, + // }).then(res => { + // // const [user, pass] = res.data.split(':') + // // return { user, pass, ip, port } + // // // return axios.get('https://www.miyaip.com/api/ProxyGenerage/PublicGenerateProxy?country=us&city=cairo®ion=ny&num=1&apiSwitch=0&mealType=2&genType=2&username=nmfk549724@163.com&secret=E3BCBmiyaipC23358C250F5').then(res => { + // const [ip, port] = res.data.replace(/(\n|\r\s)/g, '').split(':') + // console.log({ ip, port, }) + // // const [ip, pory, user, pass] = res.data.split(':') + // return { ip, port, } + // }) + return Promise.resolve({ + ip: '43.130.10.70', + port: '22993', + // user: '1E783B07miyaip489C251B3FA7', + // pass: '1g7E3M4U5w03vO' }) } +// getProxy()//.then(res => console.log(res.data)) + + export const browsers = new Map() // 登录 async function login(options = {} as any): Promise { const { user, pass } = options - const proxy = await getProxy() - const proxyUrl = `socks5://${proxy.ip}:${proxy.port}` - const agent = new SocksProxyAgent(proxyUrl); + const log = clog(options) - console.log('proxy', proxy) + // const [pErr, proxy] = await awaitWrap(getProxy(options)) + // if (pErr) { + // console.log('获取代理失败', pErr) + // return + // } + // console.log('获取代理成功', proxy) + // // const proxyUrl = await proxyChain.anonymizeProxy(`socks5://${proxy.ip}:${proxy.port}`); + // const proxyUrl = `socks5://${proxy.ip}:${proxy.port}` + // console.log('proxyUrl', proxyUrl) + // // const agent = new SocksProxyAgent(`socks5://${proxy.user}:${proxy.pass}@${proxy.ip}:${proxy.port}`); + + // // console.log('proxy', proxy) + + log('启动浏览器') const browser = await puppeteer.launch({ headless: false, args: [ '--no-sandbox', '--disable-setuid-sandbox', - // `--proxy-server=${proxyUrl}`, ] }) + log('创建新页面') const page = await browser.newPage() + // await page.authenticate({ + // username: proxy.user, + // password: proxy.pass + // }) browsers.set(user, browser) - + // await page.setRequestInterception(true); // page.on('request', (request) => { // request.continue({ @@ -54,46 +92,64 @@ async function login(options = {} as any): Promise { // return // 进入 + log('准备进入 gpt 登录') await page.goto('https://platform.openai.com') // const [err, res] = await awaitWrap(page.waitForNavigation({ timeout: 10000 })) // if (err) throw err + log('等待出现输入框') await page.waitForSelector('#username', { visible: true, timeout: 10000 }) // 输入账号 + log('输入账号') await page.type('#username', user) await Promise.all([ page.waitForNavigation(), page.keyboard.press('Enter') ]) + log('等待出现密码输入框') await page.waitForSelector('#password', { visible: true }) + log('输入密码') await page.type('#password', pass) + log('准备登录') await Promise.all([ page.waitForNavigation({ timeout: 10000 }), page.keyboard.press('Enter') ]) + log('登录成功') + return page } // 获取组织id -async function getOrgId(page: Page) { +async function getOrgId(page: Page, options: any) { + const log = clog(options) + log('准备进入组织页面') await page.goto('https://platform.openai.com/account/org-settings') await page.waitForSelector('input') + log('开始获取组织id') const orgId = await page.$$eval('input', (inputs: HTMLInputElement[]) => inputs?.[1].value || '') + log('获取组织id成功', { orgId }) return orgId } // 申请 export async function application(page: Page, options = {} as any) { + const log = clog(options) + + log('准备进入申请页面') await page.goto('https://openai.com/waitlist/gpt-4-api') + log('等待出现输入框') await page.waitForSelector('input') + log('开始申请') + const f = Mock.mock('@first') const l = Mock.mock('@last') console.log(f, l); @@ -105,13 +161,33 @@ export async function application(page: Page, options = {} as any) { const i = randomNum(1, 4) + log('选择申请类型', { i }) page.evaluate((i) => { document.querySelector('#primaryUse').nextSibling.childNodes[i].childNodes[1].click() }, i) + log('等待 gpt 生成描述') const desc = await generateDescription(i) await page.type('#ideas', desc) + log('点击提交申请') + const isSuccess = await page.evaluate((selector, searchText) => { + const elements = Array.from(document.querySelectorAll(selector)); + const target = elements.find(el => el.textContent.trim() === searchText); + + if (target) target.click() + return !!target + }, 'button', 'Join waitlist') + + if (isSuccess) { + log('提交成功,等待 gpt 返回结果') + console.log('isSuccess', isSuccess) + await page.waitForSelector('button[type="submit"] + .ui-richtext') + const text = await page.evaluate(() => document.querySelector('button[type="submit"] + .ui-richtext').textContent) + log('gpt 返回已结果', { result: text }) + } + + // await page.click('form[data-gtm-form-interact-id] button[type="submit"]') } @@ -154,10 +230,9 @@ export async function batchApplication(options) { await page.waitForSelector('.ovr-section') - const orgId = await getOrgId(page) + const orgId = await getOrgId(page, options) options.orgId = orgId console.log('orgId', orgId) - application(page, options) - + await application(page, options) } diff --git a/electron/main/gpt/index.ts b/electron/main/gpt/index.ts index bbdfc8d..0022ba1 100644 --- a/electron/main/gpt/index.ts +++ b/electron/main/gpt/index.ts @@ -2,7 +2,7 @@ import { ipcMain } from 'electron' import { getLink } from './getLink' import { validate } from './validate' import { browser } from './login' -import { batchApplication } from './batchApplication' +import { batchApplication, browsers } from './batchApplication' const parseAccount = text => text.split('\n').filter(Boolean).map(v => { v = v.split(/(——|-)+/).filter(v => !['-', '——'].includes(v)) @@ -61,5 +61,5 @@ ipcMain.handle('gpt-batch-4.0', async (event, arg) => { }) console.log('process', i, user, link) } - // browser && browser.close() + browsers.forEach(browser => browser.close()) }) diff --git a/electron/main/index.ts b/electron/main/index.ts index bf868dd..19c03a6 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -3,6 +3,9 @@ import { release } from 'node:os' import { join } from 'node:path' import './poe/index' import './gpt/index' +import { browser as poeBrowser } from './poe/login' +import { browser as gptBrowser } from './gpt/login' +import { browsers } from './gpt/batchApplication' // The built directory structure // @@ -60,6 +63,8 @@ async function createWindow() { if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298 win.loadURL(url) + console.log('process.env.VITE_DEV_SERVER_URL', process.env.VITE_DEV_SERVER_URL); + // Open devTool if the app is not packaged win.webContents.openDevTools() } else { @@ -119,3 +124,11 @@ ipcMain.handle('open-win', (_, arg) => { childWindow.loadFile(indexHtml, { hash: arg }) } }) + +ipcMain.handle('stop', async (event, arg) => { + poeBrowser && poeBrowser.close() + gptBrowser && gptBrowser.close() + browsers.forEach(browser => browser.close()) + return true +}) + diff --git a/electron/main/poe/index.js b/electron/main/poe/index.js index aa645b2..140062c 100644 --- a/electron/main/poe/index.js +++ b/electron/main/poe/index.js @@ -56,7 +56,3 @@ ipcMain.handle('poe-result', async (event, arg) => { browser && browser.close() return links }) -ipcMain.handle('stop', async (event, arg) => { - browser && browser.close() - return true -}) diff --git a/package.json b/package.json index 4c59f79..ea8fce7 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ ], "debug": { "env": { - "VITE_DEV_SERVER_URL": "http://127.0.0.1:3344/" + "VITE_DEV_SERVER_URL": "http://127.0.0.1:3200/" } }, "scripts": { @@ -44,6 +44,7 @@ "axios": "^1.4.0", "mockjs": "^1.1.0", "naive-ui": "^2.34.4", + "proxy-chain": "^2.3.0", "puppeteer": "^13.3.2", "puppeteer-extra": "^3.3.6", "puppeteer-extra-plugin-stealth": "^2.11.2", diff --git a/src/App.vue b/src/App.vue index 6500253..fb2b440 100644 --- a/src/App.vue +++ b/src/App.vue @@ -233,7 +233,7 @@ const columns = [ poe: 提取链接 充值结果 - + 申请4.0
gpt: