必应验证码解决方案 (#528)

* feat: 必应验证码另一个解决方案

* fix: add log

* fix: try try

* fix: 优化报错信息
This commit is contained in:
ikechan8370 2023-07-28 23:58:29 +08:00 committed by GitHub
parent 709a1cebf0
commit e445cb3c7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 45 deletions

View file

@ -1,9 +1,9 @@
import fetch from 'node-fetch'
// this file is deprecated
import { Config } from './config.js'
import {Config} from './config.js'
import HttpsProxyAgent from 'https-proxy-agent'
const newFetch = (url, options = {}) => {
const defaultOptions = Config.proxy
? {
@ -60,3 +60,31 @@ export async function solveCaptcha (id, regionId, text, token) {
}
}
}
export async function solveCaptchaOneShot (token) {
if (!token) {
throw new Error('no token')
}
let solveUrl = Config.bingCaptchaOneShotUrl
if (!solveUrl) {
throw new Error('no captcha source')
}
logger.info(`尝试解决token${token}的验证码`)
let result = await fetch(solveUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
_U: token
})
})
if (result.status === 200) {
return await result.json()
} else {
return {
success: false,
error: result.statusText
}
}
}

View file

@ -131,6 +131,7 @@ const defaultConfig = {
serpSource: 'ikechan8370',
extraUrl: 'https://cpe.ikechan8370.com',
smartMode: false,
bingCaptchaOneShotUrl: 'http://bingcaptcha.ikechan8370.com/bing',
version: 'v2.7.3'
}
const _path = process.cwd()