autoCaptcha
chrome谷歌浏览器扩展工具
调用api识别验证码图片
ps: 推荐油猴脚本–可自动识别页面验证码并填充到输入框 网页通用验证码
安装及操作示例
主要代码
请求图片流
function getImg(src) {
return new Promise((resolve, reject) => {
fetch(src, {
method: 'get',
responseType: 'arraybuffer'
}).then(res => {
return res.arrayBuffer();
}).then(arraybuffer => {
console.log(arraybuffer);
resolve(arrayBufferToBase64Img(arraybuffer))
}).catch(e => {
reject(e)
})
})
}
图片流转base64
function arrayBufferToBase64Img(buffer) {
const str = String.fromCharCode(...new Uint8Array(buffer));
return `data:image/jpeg;base64,${window.btoa(str)}`;
}
请求api
getImg(info.srcUrl).then(base64 => {
return fetch("http://www.bhshare.cn/imgcode/", {
"headers": {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "zh-CN,zh;q=0.9",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"x-requested-with": "XMLHttpRequest"
},
"body": "token=free&type=online&uri=" + encodeURIComponent(base64),
"method": "POST"
})
})
.then(response => response.json())
.then(res => {
console.log(res)
if (res.code === 200) {
copy(res.data, 'text/plain')
notification(`验证码: ${res.data} ,如未复制到粘贴板请手动填写`, '成功')
} else {
notification(res.msg, '失败')
}
})
.catch(error => {
notification(error, '失败')
})
end