-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallImageRecognition.js
37 lines (34 loc) · 970 Bytes
/
callImageRecognition.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require('fs');
const rest = require('restler');
const { API_USERNAME, API_PASSWORD, TYPEID, SOFTID, SOFTKEY } = process.env;
module.exports = function callImageRecognition(url, filename) {
return new Promise(resolve => {
rest
.post(url, {
multipart: true,
data: {
username: API_USERNAME,
password: API_PASSWORD,
typeid: TYPEID,
softid: SOFTID,
softkey: SOFTKEY,
image: rest.file(
filename,
null,
fs.statSync(filename).size,
null,
'image/png'
),
},
headers: {
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0',
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.on('complete', data => {
const captcha = JSON.parse(data);
resolve(captcha);
});
});
};