├── .DS_Store ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── index.js ├── lib ├── face.js ├── history.js ├── translate.js └── weather.js ├── package.json └── test ├── face.test.js ├── history.test.js ├── translate.test.js └── weather.test.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netpi/spiders/06ed5eddc1fd24f92e8bca7e52b169aab99b6126/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Night Hunter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | ./node_modules/.bin/mocha 3 | 4 | cov test-cov: 5 | ./node_modules/.bin/istanbul cover _mocha 6 | 7 | .PHONY: test cov test-cov 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## wechat-tools 让您的公众平台有可以回复‘天气预报’、‘历史上的今天’ 等 2 | 源码地址 [netpi/wechat-tools](https://github.com/netpi/wechat-tools) 3 | 4 | 5 | 推荐微信公众平台的开发者配合使用 [node-webot/wechat](https://github.com/node-webot/wechat) 6 | 7 | ### 功能预览 8 | 9 | 1 ,天气预报 (获取中国任意城市 三天内的天气预报) 10 | 11 | 2 ,历史上的今天 (获取历史上的今天 发生的大事件) 12 | 13 | 3 ,翻译助手(自动检查语言并且翻译-支持12种语言) 14 | 15 | 4 ,人脸识别(分析某一张照片上的人脸信息) 16 | ## 安装 17 | ``` 18 | npm install wechat-tools --save; 19 | ``` 20 | ## 测试 21 | 22 | ``` 23 | make test ; 24 | 25 | ``` 26 | ### 1 天气预报 (获取中国任意城市 三天内的天气预报) 27 | 此为共享 ak = uD67wmZzhi3RFcmTkGoks2Dr,实际应用时建议去[百度开发者](http://developer.baidu.com/map/index.php)自行申请ak 28 | 29 | ```js 30 | var wt = request('wechat-tools'); 31 | var ak = 'uD67wmZzhi3RFcmTkGoks2Dr';// 32 | var city = '北京'; 33 | wt.weather(ak,city,function(err , data){ 34 | if(err){ 35 | throw err; 36 | }else{ 37 | console.log(data); 38 | } 39 | }); 40 | ``` 41 | #### console.log(data); 结果如下图 42 |  43 | ### 2 历史上的今天 (获取历史上的今天 发生的大事件) 44 | ```js 45 | wt.history(function (err,data) { 46 | if(err){ 47 | throw err; 48 | }else{ 49 | console.log(data); 50 | } 51 | }) 52 | ``` 53 | #### console.log(data); 结果如下图 54 |  55 | 56 | ### 3 翻译助手(自动检查语言并且翻译-支持12种语言) 57 | 58 | 支持语言种类: 59 | 中文、英语、日语、韩语、德语、法语、俄语、泰语、意大利语、西班牙语、葡萄牙语、阿拉伯语 60 | 61 | 62 | 翻译服务会自动检测源语言语种,并根据源语言的语种按照规则设置目标语言的语种。当源语言为非中文时,目标语言自动设置为中文。当源语言为中文时,目标语言自动设置为英文。 63 | 64 | #### 英译汉 65 | ```js 66 | var wt = request('wechat-tools'); 67 | var ak = 'uD67wmZzhi3RFcmTkGoks2Dr'; 68 | var word = '周末放假'; // 要翻译的词汇 69 | wt.translate(ak, word, function(err, data) { 70 | if (err) { 71 | throw err; 72 | } else { 73 | console.log(data);// --> The weekend holiday 74 | }; 75 | }); 76 | ``` 77 | #### 汉译英 78 | ```js 79 | 80 | var wt = request('wechat-tools'); 81 | var ak = 'uD67wmZzhi3RFcmTkGoks2Dr'; 82 | var word = 'The weekend holiday'; // 要翻译的单词 83 | wt.translate(ak, word, function(err, data) { 84 | if (err) { 85 | throw err; 86 | } else { 87 | console.log(data);// --> 周末度假 88 | }; 89 | }); 90 | 91 | ``` 92 | 93 | ### 4 人脸识别 (分析某一张照片上的人脸信息) 94 | 95 | 建议去 [face++](http://www.faceplusplus.com.cn/) 官网申请api_key、api_secret 96 | 97 | ```js 98 | 99 | var wt = request('wechat-tools'); 100 | 101 | var option = { 102 | api_key : '0ef14fa726ce34d820c5a44e57fef470', 103 | api_secret : '4Y9YXOMSDvqu1Ompn9NSpNwWQFHs1hYD', 104 | imgurl : 'http://cn.faceplusplus.com/static/resources/python_demo/1.jpg' 105 | }; 106 | 107 | wt.face(option , function (err,data) { 108 | if(err){ 109 | // err ... 110 | }else{ 111 | var face1 = JSON.parse(data).face[0]; 112 | console.log(face1.attribute.age); // => { range: 7, value: 33 } (33岁 偏差 7) 113 | console.log(face1.attribute.gender); // => { confidence: 99.94, value: 'Male' } (女 可信度99.94/%) 114 | console.log(face1.attribute.race); // => { confidence: 99.6939, value: 'White' } (白种人 可信度99.6939%) 115 | } 116 | }); 117 | ``` 118 | 详细结果分析参看 [face++ api文档](http://www.faceplusplus.com.cn/detection_detect/) 119 | 120 | ## 应用 121 |  122 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | function wechattools() {} 2 | wechattools.weather = require('./lib/weather'); 3 | wechattools.history = require('./lib/history'); 4 | wechattools.translate = require('./lib/translate'); 5 | wechattools.face = require('./lib/face'); 6 | 7 | module.exports = wechattools; -------------------------------------------------------------------------------- /lib/face.js: -------------------------------------------------------------------------------- 1 | var urllib =require('urllib'); 2 | 3 | var face =function (opt , callback) { 4 | 5 | var ak = opt.api_key; 6 | var sk = opt.api_secret; 7 | var imgurl = opt.imgurl; 8 | urllib.request('https://apicn.faceplusplus.com/v2/detection/detect', { 9 | method: 'POST', 10 | data: { 11 | api_key: ak, 12 | api_secret: sk, 13 | url: imgurl 14 | } 15 | }, function(urllib_err, data) { 16 | var error = null; 17 | if (urllib_err) { 18 | 19 | error = urllib_err; 20 | } else { 21 | var face_error = JSON.parse(data.toString()).error; 22 | if(face_error){ 23 | error = data; 24 | }else if(!JSON.parse(data.toString()).face[0]){ 25 | error = {'error' : 'no face'}; 26 | } 27 | callback(error, data.toString()); 28 | } 29 | }); 30 | }; 31 | module.exports = face; 32 | -------------------------------------------------------------------------------- /lib/history.js: -------------------------------------------------------------------------------- 1 | var urllib = require('urllib'); 2 | var history = function(callback) { 3 | urllib.request('http://www.rijiben.com/', function(error, data, res1) { 4 | var err = null; 5 | // 返回的数据 6 | var rdata = ''; 7 | if (error) { 8 | err = error; 9 | } else { 10 | var re = /