From 160cbd9afd178796a2d042b08895c20f139c2de3 Mon Sep 17 00:00:00 2001 From: smackxu <smackxu@raventech.com> Date: Tue, 23 May 2017 15:48:27 +0800 Subject: [PATCH] OcrKing for Node --- Node/56623.jpg | Bin 0 -> 1173 bytes Node/OcrKing.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ Node/README.md | 21 +++++++++++++++++++++ Node/example.js | 13 +++++++++++++ Node/package.json | 28 ++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 Node/56623.jpg create mode 100644 Node/OcrKing.js create mode 100644 Node/README.md create mode 100644 Node/example.js create mode 100644 Node/package.json diff --git a/Node/56623.jpg b/Node/56623.jpg new file mode 100644 index 0000000000000000000000000000000000000000..906bdc8cdb3866539f44dde7325e00bdc6e9c824 GIT binary patch literal 1173 zcmex=<NpH&0WUXCHwH#V1_nkTWcYuZ!I^=Bjg6g+m4ls~os*M;i${c)hnt&6Qb?Fz zL{>^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<<Uft5x!pKI?*u)5A2qPyaCl5D|1TU|I zk)n*E5y{~H0R}-121$khW=16jCP7AKLB{__803NOWMu>c1}I=;VrF4wW9Q)H;sz?% zD!{<R$jr>d!pzFb!U9xX3zTPI5o8roG<0MW4oqZMDikqloVbuf*=gfJ(V&YTRE(2~ znmD<{#3dx9RMpfqG__1j&CD$<t(;w4-P}Dqy@EqR!@?sXqmoln)6z3Cvx-Yf%gQS% ztD0L{+uA!iyCzMZGIiSY88c@sTD)ZGvgIpQuG+MD%hqk%ckJAC=<t!F$Bv&kdFs;T zD_5^wzj5={!$*&wJbm{3#miS8KYjl4_1pI!KYxMz#mK-6@fMJTcnr;7f<S*Uv9K_+ zu!H=?$W#u*%z`YeiiT`Lj)Clng~CckjT|CQ6Blkg$f;}`^g%SK=pvVxipfLOk07ss zeMX$en#l4Q++zrT-D2QjW&}navmk>#!<YXI5_jTm9bQ&D?Qy`iHt)03i!;B~XHHf6 zl&bvn(~}1$lv&=szirxDxjHU$p6LE7TTcJJTlD3$=oYbCQvz?B1Y57tNEJMGdcL7F ze^2ic0cq2lug!MNJyKAgnk5i<T4whW<6A#pYUL(wXgKAr8m-uV_qbCw*Ym@{vA1JR zSJzC+n!I)Q-$fQ&F8f^O<!CA2@jLKSciNrXv!5|%1n}_M*!8c=y{41%Xvef;)$Ld1 z1G78L+%D#arFXJq&ScJwQBZj3syn~)cIY+NrE|iJ9CsdB{PywN0IlZFp84Cg%voc^ z?wI!;^mDkf^TU%{bHtOQ_j-3O-!koF+$CnFqaqFYhc;X4c&%5N_-P%(&+U%Mi(;eW z4i;Ayr~PM0-Ikr5v1Tpro{XM=36ACGe{ErwU`Su*#$Z`5dMCTeYi7>Z<@1Ag?+U%V zWy`i6cO|CXQ#Wx>5HC!>w;=sT#quAUV`qDWM`yn^v!2M2k*nr5t9p4-XkcKZ2TOzT z=XCYP?Xxo<u8q4MbHy~{YqjP&y&0=)uQu;K%wZW3(m91y){o&%rKPEOhmC3V`rD_M z$7TI4S($S0<MAApH;i}0�_pPF|GG#i%~XK{v`@_1WCqV$<Exr%g1K5B+DTGICJ$ zb9hqnLUR(=evMU=xERh)2=!!*pAc%v%21usw90F1Rn&4-hCq-&+_Y8R4k9U{evaWw hRuu)XYO)4T&HA#{&x>KH!m1*!y{f^}8tnhy1OUWt&3OO- literal 0 HcmV?d00001 diff --git a/Node/OcrKing.js b/Node/OcrKing.js new file mode 100644 index 0000000..d815152 --- /dev/null +++ b/Node/OcrKing.js @@ -0,0 +1,45 @@ +const xml2json = require('node-xml2json'); +const request = require('request'); +const fs = require('fs'); +const url = require('url'); + +function getCaptcha(filePath, option) { + const defaultOption = { + service: 'OcrKingForPhoneNumber', + language: 'eng', + charset: '11', + type: 'http://www.unknown.com', + }; + const result = url.format({ + protocol: 'http:', + hostname: 'lab.ocrking.com/ok.html', + query: Object.assign({}, defaultOption, option), + }); + + return new Promise((resolve, reject) => { + const formData = { + file: fs.createReadStream(filePath), + }; + + request.post({ + url: result, + formData, + }, (err, httpResponse, body) => { + if (err) { + reject({ + error: err, + }); + } + try { + bodyObj = xml2json.parser(body).results.resultlist || {}; + resolve(bodyObj); + } catch (e) { + reject({ + error: e, + }); + } + }); + }); +} + +module.exports = getCaptcha; diff --git a/Node/README.md b/Node/README.md new file mode 100644 index 0000000..03e203a --- /dev/null +++ b/Node/README.md @@ -0,0 +1,21 @@ +# OcrKing Node + +## 安装依赖 + +```js + +npm install + +``` + +## Example + +```shell + + node example.js + +``` + +## option + +option 详见 [接口说明](../线上识别http接口说明.txt) diff --git a/Node/example.js b/Node/example.js new file mode 100644 index 0000000..a9acb87 --- /dev/null +++ b/Node/example.js @@ -0,0 +1,13 @@ +const getCaptcha = require('./OcrKing'); +const path = require('path'); + + +const filePath = path.resolve('./56623.jpg'); + +getCaptcha(filePath, { + apiKey: '51ef8dc7b3b0b5be53qUWQPIpynwaRCZb2MxvzUXqlsPQYPtbp0CG0Df55dh9vp5BScpESjJcH', +}).then((result) => { + console.log(result); +}).catch((err) => { + console.log(err); +}); diff --git a/Node/package.json b/Node/package.json new file mode 100644 index 0000000..dcb0007 --- /dev/null +++ b/Node/package.json @@ -0,0 +1,28 @@ +{ + "name": "ocrking", + "version": "1.0.0", + "description": "OcrKing for Node", + "main": "OcrKing.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/smackgg/OcrKing.git" + }, + "keywords": [ + "OcrKing", + "Node", + "captha" + ], + "author": "smackgg", + "license": "ISC", + "bugs": { + "url": "https://github.com/smackgg/OcrKing/issues" + }, + "homepage": "https://github.com/smackgg/OcrKing#readme", + "dependencies": { + "node-xml2json": "^1.0.0", + "request": "^2.81.0" + } +}