├── .babelrc ├── .editorconfig ├── .env ├── .env.development ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .prettierignore ├── .prettierrc.js ├── LICENSE ├── README.md ├── bak-file ├── api.png ├── api2.png ├── university.sql └── vtools.sql ├── bin └── www ├── jsconfig.json ├── package.json ├── src ├── app.js ├── config │ └── orm.js ├── controller │ ├── 163 │ │ ├── joke.js │ │ ├── tt-news-detail.js │ │ ├── tt-news-list.js │ │ ├── video-detail.js │ │ └── video-list.js │ ├── bank-card.js │ ├── down-img.js │ ├── history-today │ │ ├── history-today-detail.js │ │ ├── history-today.js │ │ └── rule.js │ ├── icon-list.js │ ├── idcard-info.js │ ├── idiom.js │ ├── job │ │ ├── lagou-positionsearch.js │ │ └── position-info.js │ ├── jwt.js │ ├── lunar-calendar.js │ ├── music │ │ ├── new-songs.js │ │ ├── plist-songs.js │ │ ├── plist.js │ │ ├── rank-list-info.js │ │ ├── rank-list.js │ │ ├── search.js │ │ ├── singer-classify.js │ │ ├── singer-info.js │ │ ├── singer-list.js │ │ ├── song-info.js │ │ └── song-lrc.js │ ├── star-detail │ │ ├── juhe-star-detail.js │ │ └── star-detail.js │ ├── tang300.js │ ├── university │ │ ├── rule.js │ │ └── university.js │ ├── we-app │ │ └── getUserInfo.js │ └── web │ │ ├── 404.js │ │ └── index.js ├── entity │ ├── historyTodayOrm.js │ ├── idiomOrm.js │ ├── poetryOrm.js │ ├── starDetailOrm.js │ ├── universityOrm.js │ ├── userOrm.js │ └── weAppOrm.js ├── middlewares │ ├── interceptor.js │ ├── openPath.js │ └── resAPI.js ├── models │ ├── history-today │ │ ├── history-today-detail.js │ │ └── history-today.js │ ├── idiom │ │ ├── CSV.js │ │ └── idiom.js │ ├── poetry │ │ └── tang300.js │ ├── star-detail │ │ └── juhe-star-detail.js │ ├── university │ │ └── university.js │ ├── user │ │ └── User.js │ └── we-app │ │ ├── WXBizDataCrypt.js │ │ └── wx-login.js ├── routers.js └── utils │ ├── api-sign.js │ ├── crawler-request.js │ ├── jwt.js │ ├── log4.js │ ├── request.js │ └── swaggerUI.js ├── views ├── error.html ├── index.html └── web │ └── 404.html └── webstorm.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "env", 5 | { 6 | "targets": { 7 | "node": "current" 8 | } 9 | } 10 | ] 11 | ], 12 | "plugins": [] 13 | } 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | ApiSign=true 2 | -------------------------------------------------------------------------------- /.env.development: -------------------------------------------------------------------------------- 1 | NODE_ENV=development 2 | #是否需要接口签名 3 | ApiSign=false 4 | #接口签名密钥 5 | appKey=44cb0b75f52f4596a57773b9173416a6 6 | #jwt 的密钥 7 | jwtSecret=kjhgyhvfsdcvbjk 8 | #小程序appid 9 | appid='secret' 10 | #小程序的secret 11 | secret='you secret' 12 | #database 13 | host=localhost 14 | database=vtools 15 | username = root 16 | password = '' 17 | #星座运势 18 | STAR_APPCODE='juhe' 19 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /utils/ 2 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | commonjs: true, 5 | es6: true, 6 | es2021: true, 7 | node: true 8 | }, 9 | extends: ['eslint:recommended', 'plugin:prettier/recommended'], // 覆盖eslint格式配置,写在最后 10 | globals: { 11 | Atomics: 'readonly', 12 | SharedArrayBuffer: 'readonly', 13 | $: true 14 | }, 15 | parserOptions: { 16 | ecmaVersion: 'latest' 17 | }, 18 | rules: { 19 | indent: ['error', 2], 20 | quotes: ['error', 'single'], 21 | semi: ['error', 'always'], 22 | 'array-bracket-spacing': ['error', 'never'], // 数组前后空格 23 | 'object-curly-spacing': ['error', 'always'] // 对象前后空格 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # PHPStorm 2 | .idea 3 | .gitee 4 | .vscode 5 | .vscode/ 6 | images/ 7 | node_modules/ 8 | logs/ 9 | dist 10 | .env.production 11 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | bak-file 2 | dist 3 | logs 4 | node_modules 5 | .idea 6 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | trailingComma: 'none', // 确保对象的最后一个属性后有逗号 3 | printWidth: 100, // 指定代码长度,超出换行 4 | semi: true, // 结尾加上分号 5 | singleQuote: true, // 使用单引号 6 | arrowParens: 'avoid', // 箭头函数,单个参数不添加括号 7 | bracketSpacing: true, // 大括号有空格 { name: 'rose' } 8 | stylelintIntegration: true, 9 | }; 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 ecitlm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Express 2 | >项目基于`express`+`sequelize`+`mysql`+`express-validator` 3 | > 基于node+express爬虫 API接口项目,包括全国高校信息、成语诗歌、星座运势、历史的今天、音乐数据接口、图片壁纸、搞笑视频、热点新闻资讯 详情接口数据 4 | 5 | - [x] express 6 | - [x] sequelize 7 | - [x] mysql 8 | - [x] `express-validator`参数表单校验 9 | - [x] 使用`cheerio`解析爬虫页面 10 | - [x] 集成`ejs`模板 11 | - [x] 集成`swaggerUI`接口文档 12 | - [x] `nodemon`项目开发动态热更新 13 | - [x] `dotenv`管理配置系统参数 14 | - [x] 包含接口sign请求验证 15 | - [x] `log4js` 错误日志收集 16 | 17 | ### 环境要求 18 | >需要安装`node`环境,`mysql`数据库 19 | 20 | ### 部署运行 21 | ```shell 22 | $ git clone https://github.com/ecitlm/Node-SpliderApi.git 23 | $ npm install 24 | # start project dev 25 | $ npm run dev 26 | # starting prd 27 | $ npm run prd 28 | #localhost:3001 29 | 30 | ``` 31 | ### 服务器部署 32 | 33 | > 在服务器中使用 `pm2` 对 `node` 服务进行进程守护 34 | 35 | ```shell 36 | #启动进程/应用 37 | pm2 start npm --watch --name tools -- run prd 38 | pm2 restart tools 39 | pm2 stop tools 40 | pm2 delete tools 41 | ``` 42 | ### 数据库 43 | >`mysql`中包含、唐诗300、成语、历史的今天、星座运势(聚合平台数据-需要申请自己的APPCODE)、用户表等数据 44 | > 项目目录`bak-file`文件夹可查看 45 | 46 | ### 接口文档 47 | >启动项目之后`http://localhost:3001/api-docs/` 可查看接口文档页面 48 | ![api.png](bak-file/api.png) 49 | ![api2.png](bak-file/api2.png) 50 | 51 | 52 | ### 错误码说明 53 | 54 | | 状态码 | 含义 | 备注 | 55 | |------| ---------------------------------- | ---- | 56 | | 200 | 响应正常 | | 57 | | 1001 | 参数无效、如一个不存在的id | | 58 | | 1002 | 参数为空、验证不通过、参数类型错误 | | 59 | | 1003 | 请求签名异常、非法 | 60 | | 404 |请求不存在 | 61 | | 405 | 请求方式错误| 62 | | 9999 | 第三方接口请求异常| 63 | | 500 |系统异常| 64 | 65 | 66 | 67 | ### 感谢JetBrains 的支持 68 | JetBrains:https://www.jetbrains.com/?from=Node-SpliderApi 69 | -------------------------------------------------------------------------------- /bak-file/api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ecitlm/Node-SpliderApi/aa76cc088ed237b6f3f7b2c60057d77b4f16b1c5/bak-file/api.png -------------------------------------------------------------------------------- /bak-file/api2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ecitlm/Node-SpliderApi/aa76cc088ed237b6f3f7b2c60057d77b4f16b1c5/bak-file/api2.png -------------------------------------------------------------------------------- /bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | let debug = require('debug')('my-application'); 3 | let app = require('../src/app'); 4 | 5 | app.set('port', process.env.PORT || 30011); 6 | 7 | let server = app.listen(app.get('port'), function () { 8 | debug('Express server listening on port ' + server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES6", 4 | "module": "commonjs", 5 | "allowSyntheticDefaultImports": true, 6 | "baseUrl": "./", 7 | "paths": { 8 | "@/*": [ 9 | "/*" 10 | ] 11 | } 12 | }, 13 | "exclude": [ 14 | "node_modules" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vtools-server", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www", 7 | "prd": "cross-env NODE_ENV=production nodemon src/app.js", 8 | "dev": "cross-env NODE_ENV=development nodemon src/app.js" 9 | }, 10 | "dependencies": { 11 | "apicache": "^1.6.3", 12 | "axios": "^0.26.0", 13 | "body-parser": "^1.19.2", 14 | "cheerio": "^1.0.0-rc.12", 15 | "cookie-parser": "^1.4.6", 16 | "dayjs": "^1.11.9", 17 | "dotenv": "^16.3.1", 18 | "ejs": "^3.1.6", 19 | "express": "^4.17.3", 20 | "express-rate-limit": "^6.3.0", 21 | "express-session": "^1.17.2", 22 | "express-validator": "^6.14.0", 23 | "iconv-lite": "^0.6.3", 24 | "idcard": "^4.1.0", 25 | "jsonwebtoken": "^8.5.1", 26 | "log4js": "^6.4.2", 27 | "lunar-calendar-fix": "^0.1.5", 28 | "md5": "^2.2.1", 29 | "morgan": "~1.10.0", 30 | "mysql2": "^3.5.1", 31 | "node-fetch": "^3.2.1", 32 | "qs": "^6.10.3", 33 | "query-string": "^7.1.1", 34 | "request": "^2.83.0", 35 | "sequelize": "^6.17.0", 36 | "static-favicon": "~1.0.0", 37 | "superagent": "^7.1.3" 38 | }, 39 | "devDependencies": { 40 | "async": "^3.2.3", 41 | "cross-env": "^7.0.3", 42 | "debug": "^4.3.3", 43 | "download": "^8.0.0", 44 | "eslint": "^8.10.0", 45 | "eslint-config-prettier": "^8.5.0", 46 | "eslint-plugin-prettier": "^4.0.0", 47 | "express-jsdoc-swagger": "^1.6.7", 48 | "express-routemap": "^1.6.0", 49 | "fs": "^0.0.1-security", 50 | "html-entities": "^1.2.1", 51 | "json2csv": "^5.0.7", 52 | "mkdirp": "^1.0.4", 53 | "module-alias": "^2.2.2", 54 | "nodemon": "^3.0.1", 55 | "prettier": "^2.6.2" 56 | }, 57 | "_moduleAliases": { 58 | "@": "." 59 | }, 60 | "_moduleDirectories": [ 61 | "node_modules_custom" 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | require('module-alias/register'); 2 | const express = require('express'); 3 | const path = require('path'); 4 | const cookieParser = require('cookie-parser'); 5 | const app = express(); 6 | const router = express.Router(); 7 | require('dotenv').config({ 8 | override: true, 9 | path: path.join(process.cwd(), `.env.${process.env.NODE_ENV}`) 10 | }); 11 | console.log(process.env.ApiSign); 12 | const interceptor = require('@/src/middlewares/interceptor'); 13 | const resAPI = require('@/src/middlewares/resAPI'); 14 | require('./utils/swaggerUI')(app); 15 | // 设置静态资源地址 16 | app.use('/public', express.static('public')); 17 | app.use('/docs', express.static('docs')); 18 | app.use(cookieParser()); 19 | app.use(express.urlencoded({ extended: false })); 20 | app.use(express.json()); 21 | const arrRoutes = require('./routers'); 22 | app.get('/favicon.ico', (req, res) => res.end()); 23 | app 24 | .set('view engine', 'ejs') 25 | // .set('views', path.join(__dirname, 'src/views')) 26 | .engine('html', require('ejs').__express); 27 | 28 | app.use(function (req, res, next) { 29 | res.header('Access-Control-Allow-Origin', '*'); 30 | res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); 31 | next(); 32 | }); 33 | 34 | // app.use的使用顺序需要注意 35 | 36 | // 接口返回封装 37 | app.use(resAPI); 38 | // 请求拦截处理 39 | app.use(interceptor); 40 | 41 | for (const route of arrRoutes) { 42 | app.use(route.path, require(route.component)); 43 | } 44 | app.use(router); 45 | app.listen(3001, () => { 46 | console.log('Web server started at port 3001!'); 47 | }); 48 | module.exports = app; 49 | -------------------------------------------------------------------------------- /src/config/orm.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 对象关系映射(ORM) 3 | */ 4 | const Sequelize = require('sequelize'); 5 | // new Sequelize("表名","用户名","密码",配置) 6 | const sequelize = new Sequelize(process.env.database, process.env.username, process.env.password, { 7 | host: process.env.host, 8 | dialect: 'mysql', 9 | timezone: '+08:00' 10 | }); 11 | sequelize 12 | .authenticate() 13 | .then(function () { 14 | console.log('Database connection has been established successfully.'); 15 | }) 16 | .catch(function (err) { 17 | console.log('Unable to connect to the database:', err); 18 | }); 19 | 20 | module.exports = sequelize; 21 | -------------------------------------------------------------------------------- /src/controller/163/joke.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const superagent = require('superagent'); 3 | const cheerio = require('cheerio'); 4 | /** 5 | * get /api/163/joke 6 | * @summary 搞笑段子 7 | * @tags 163 8 | * @description 搞笑段子 9 | * @param {string} page.query.required - 分页 10 | */ 11 | app.get('/', function (req, res) { 12 | const pageSize = (req.query.page || 1); 13 | superagent 14 | .get(`https://duanzi.cn/page/${pageSize}/`) 15 | .set('Content-Type', 'text/html; charset=UTF-8') 16 | .set( 17 | 'user-agent', 18 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36' 19 | ) 20 | .end((err, data) => { 21 | let tmp = []; 22 | try { 23 | const $ = cheerio.load(data.text, { decodeEntities: false }); 24 | $('#sticky .item').each(function (index, item) { 25 | let title = $(item).find('h2 a').text(); 26 | let intro = $(item).children('.intro').text(); 27 | let list = { 28 | title, 29 | intro 30 | }; 31 | tmp.push(list); 32 | }); 33 | res.API(tmp); 34 | } catch (e) { 35 | return res.API_ERROR('系统请求错误'); 36 | } 37 | }); 38 | }); 39 | 40 | module.exports = app; 41 | -------------------------------------------------------------------------------- /src/controller/163/tt-news-detail.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | /** 4 | * GET /api/tt/news-detail 5 | * @tags 163 6 | * @summary 头条新闻详情 7 | * @description 头条新闻详情 8 | * @param {string} item_id.query.required - item_id 9 | */ 10 | app.get('/', function (req, res) { 11 | const itemId = req.query.item_id || '6424603234748334594'; 12 | const host = 'm.toutiao.com'; 13 | const path = `/i${itemId}/info/`; 14 | request 15 | .httpGet({ host, path, status: true }) 16 | .then(function (body) { 17 | res.API(JSON.parse(body).data); 18 | }) 19 | .catch(function (err) { 20 | res.API_ERROR('网络好像有点问题', 500); 21 | console.log(err); 22 | }); 23 | }); 24 | 25 | module.exports = app; 26 | -------------------------------------------------------------------------------- /src/controller/163/tt-news-list.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * GET /api/tt/news-list 6 | * @tags 163 7 | * @summary 头条新闻 8 | * @description 0 热点新闻 1 社会新闻 2 娱乐新闻 3体育新闻 4美文 散文 5科技 6 财经 7 时尚 9 | * @param {string} type.query.required - 0 热点新闻 1 社会新闻 2 娱乐新闻 3体育新闻 4美文 散文 5科技 6 财经 7 时尚 10 | */ 11 | app.get('/', function (req, res) { 12 | const type = parseInt(req.query.type) || 8; 13 | // 0 热点新闻 1 社会新闻 2 娱乐新闻 3体育新闻 4美文 散文 5科技 6 财经 7 时尚 14 | const map = { 15 | 0: '/list/?tag=news_hot&ac=wap&count=20&format=json_raw&as=A1A59982B911729&cp=5929E12752796E1&min_behot_time=0', 16 | 1: '/list/?tag=news_society&ac=wap&count=20&format=json_raw&as=A195B9F229018CD&cp=592991783C9D8E1&min_behot_time=0', 17 | 2: '/list/?tag=news_entertainment&ac=wap&count=20&format=json_raw&as=A1C51992996195E&cp=5929D119B58EFE1&min_behot_time=0', 18 | 3: '/list/?tag=news_sports&ac=wap&count=20&format=json_raw&as=A1054902B911A1E&cp=592991AA81AEAE1&min_behot_time=0', 19 | 4: '/list/?tag=news_essay&ac=wap&count=20&format=json_raw&as=A195495279C19DE&cp=5929C1F91DFEEE1&min_behot_time=0', 20 | 5: '/list/?tag=news_tech&ac=wap&count=20&format=json_raw&as=A1854972BABC6FF&cp=592A9CC64FCFAE1&max_behot_time=0', 21 | 6: '/list/?tag=news_finance&ac=wap&count=20&format=json_raw&as=A145E9025A6C78B&cp=592ACC87687B1E1&max_behot_time=0', 22 | 7: '/list/?tag=news_fashion&ac=wap&count=20&format=json_raw&as=A1353902AA9C7F9&cp=592ADCD7CF89AE1&max_behot_time=0', 23 | 8: '/list/?tag=news_hot&ac=wap&count=20&format=json_raw&as=A1A59982B911729&cp=5929E12752796E1&min_behot_time=0' 24 | }; 25 | const path = map[type]; 26 | const host = 'm.toutiao.com'; 27 | const headers = { 28 | Cookie: 29 | '_S_DPR=1; _S_IPAD=0; _S_UA=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F96.0.4664.45%20Safari%2F537.36; tt_webid=7072000147563791879; n_mh=CbLxGSOPsHz0SsnNxB9g86-VHADgPoHSyMEyLMiYWl0; sid_guard=b8141b6ad8fce590bf5e304210446b9d%7C1646578466%7C5183999%7CThu%2C+05-May-2022+14%3A54%3A25+GMT; odin_tt=eaecc8d794b0dbb81811c80eb8665ee4f260adcdf07a2c8f838ebfd59ec8a19fc20bce1291a94078ecb824f7aae215f1; _S_WIN_WH=1920_937; x-jupiter-uuid=16521057696803428; W2atIF=1; _tea_utm_cache_1698=undefined; MONITOR_WEB_ID=37ddc9cb-21f3-4dbc-9664-be2e0db5615a; MONITOR_DEVICE_ID=0746beac-30f7-4078-86a1-7257eb151dda; msToken=tAWf2RQqEFcZsZXzrlpngmsorNRcHXwssGIeXQy0B3Q91GUaKIGdDgIjIh4AJBVmxpke85KkHGNIGA-d0TDcgjSWZylxhG0wgkXFKxI6SBI=; _tea_utm_cache_1286=undefined; MONITOR_WEB_ID=7072000147563791879; ttwid=1%7CWa5kxH4M2MLb0RBlgKurcNu5qHAM1Kvn9CnyNo_1SAo%7C1652105797%7C6913a9f311963485a4c04840b710094c4dcf6556b8a3a70f1e20196a9e3451d7' 30 | }; 31 | request 32 | .httpGet({ host, path, status: true, headers }) 33 | .then(function (result) { 34 | res.API(JSON.parse(result).data); 35 | }) 36 | .catch(function (err) { 37 | res.API_ERROR('网络好像有点问题', 500); 38 | console.log(err); 39 | }); 40 | }); 41 | module.exports = app; 42 | -------------------------------------------------------------------------------- /src/controller/163/video-detail.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const crawlerRequest = require('@/src/utils/crawler-request'); 3 | /** 4 | * get /api/163/video-detail 5 | * @summary 视频详情 6 | * @tags 163 7 | * @description 视频详情 8 | * @param {string} vid.query.required - 视频id list接口中的vid 9 | */ 10 | app.get('/', function (req, res) { 11 | const vid = req.query.vid || 'VW4GNCU88'; 12 | const url = `https://3g.163.com/v/video/${vid}.html?offset=46&ver=c`; 13 | crawlerRequest({ url }) 14 | .then($ => { 15 | const detail = { 16 | title: $('title').text(), 17 | cover: $('.main_video').attr('poster'), 18 | mp4: $('.main_video').find('source').eq(0).attr('src'), 19 | mp3u8: $('.main_video').find('source').eq(1).attr('src'), 20 | author: $('.video_info .detail .source').text(), 21 | time: $('.video_info .detail .time').text() 22 | }; 23 | res.API(detail); 24 | }) 25 | .catch(err => { 26 | console.log(err, 222); 27 | res.API_ERROR('请求异常', 5001); 28 | }); 29 | }); 30 | module.exports = app; 31 | -------------------------------------------------------------------------------- /src/controller/163/video-list.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * get /api/163/video-list 6 | * @summary 163视频 7 | * @tags 163 8 | * @description 163视频 搞笑:Video_Funny 新闻现场:Video_Scene 萌物:Video_Adorable 猎奇:Video_Curious 音乐 :Video_Music 小品 :Video_Opusculum 影视:Video_Movie 军武 Video_Military 9 | * @param {string} page.query.required - 分页 10 | * @param {string} type.query.required - 类型 默认推荐 11 | */ 12 | app.get('/', function (req, res) { 13 | const pageSize = (req.query.page || 1) * 10 - 10; 14 | const type = req.query.type || 'Video_Recom'; 15 | const host = '3g.163.com'; 16 | const path = `/touch/nc/api/video/recommend/${type}/${pageSize}-20.do?callback=videoList`; 17 | const headers = { 18 | cookie: 19 | '_ntes_nuid=023d7a659e5cbbdc2607333212932bd6; nts_mail_user=1928@163.com:-1:1; mail_psc_fingerprint=e4bd802xc7ea01af6f85e7e0ef53b721a4; NTES_P_UTID=ktgfQhlP5otFsulnlUMJYrToekM8NqS9|1634049413; _ntes_nnid=023d7a659e5cbbdc2607333212932bd6,1636285469627; NTES_SESS=JWjEObG_Ca0IWnSqEOMs7Kd6BgUWRXuRrnjvE1HFWEAqWh3VWELSHaXAL5fuEGj9xxhCpDAMFeHwp50x_g9cRTDeT18Xr7SPIg_XtGMy.Oc6vHWRcV.WQkYlIZWJtUc7nNJhcN25i9ZGZmhFI948zcUT2dejqDaV4gME.Rx_t9jk2yUeKIt11k_shJIXUpLu5E1O17gkq_6wQPczrY0PBJV4e; S_INFO=1651495800|0|0&60##|ecitlm|; P_INFO=ecitlm@163.com|1651495800|0|mailmaster_ios|00&99|gud&1650948779&mailmaster_ios#gud&440300#10#0#0|150716&0|mailmaster_ios|ecitlm@163.com; ANTICSRF=78d18fda20a9568eb768ecda3fa17b87; hb_MA-9D99-92DF8361BA33_source=reg.163.com; _antanalysis_s_id=1652097239772; UM_distinctid=180a8ab52b4a0c-0b93ba648cb7bb-1f343371-1fa400-180a8ab52b5906; CNZZDATA1253186237=1859623887-1652088672-%7C1652088672; _ntes_newsapp_install=false; ariaDefaultTheme=undefined; CNZZDATA1256116812=240549915-1652095287-https%253A%252F%252F3g.163.com%252F%7C1652095287', 20 | accept: 21 | 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' 22 | }; 23 | request 24 | .httpGet({ host, path, headers, status: true }) 25 | .then(function (body) { 26 | console.log(body); 27 | let result = JSON.parse(body.match(/\[.*?\]/g)); 28 | console.log(result); 29 | let r = result.map(item => { 30 | return { 31 | title: item.title, 32 | cover: item.cover, 33 | vid: item.vid, 34 | ptime: item.ptime, 35 | topicName: item.topicName, 36 | replyid: item.replyid, 37 | topicSid: item.topicSid 38 | }; 39 | }); 40 | return res.API(r); 41 | }) 42 | .catch(function (err) { 43 | res.API_ERROR('服务器异常'); 44 | console.log(err); 45 | }); 46 | }); 47 | 48 | module.exports = app; 49 | -------------------------------------------------------------------------------- /src/controller/bank-card.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('@/src/utils/request'); 3 | 4 | /** 5 | * GET /api/bank-card 6 | * @tags 卡类信息 7 | * @summary 根据银行卡号解析卡信息 8 | * @description 根据银行卡号解析卡信息 9 | * @param {string} cardNo.query.required - card号 10 | */ 11 | app.get('/', function (req, res) { 12 | let cardNo = req.query.cardNo; 13 | if (!cardNo) { 14 | return res.API_ERROR('请输入卡号', 300); 15 | } 16 | let host = 'ccdcapi.alipay.com'; 17 | let path = `/validateAndCacheCardInfo.json?cardNo=${cardNo}&cardBinCheck=true`; 18 | let data = {}; 19 | // false:http请求 true:https请求 20 | request 21 | .httpGet({ host, data, path, https: true }) 22 | .then(function (body) { 23 | body = JSON.parse(body); 24 | if (body.validated) { 25 | res.API(body); 26 | } else { 27 | res.API_ERROR('卡验证未通过', 300); 28 | } 29 | }) 30 | .catch(function (err) { 31 | res.API_ERROR('网络好像有点问题', 400); 32 | console.log(err); 33 | }); 34 | }); 35 | 36 | module.exports = app; 37 | -------------------------------------------------------------------------------- /src/controller/down-img.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const cheerio = require('cheerio'); 3 | const app = express(); 4 | const download = require('download'); 5 | const request = require('request'); 6 | const Iconv = require('iconv-lite'); 7 | 8 | /** 9 | * GET /api/down-img/ 10 | * @summary 彼岸桌面图片 11 | * @description 彼岸桌面图片、并下载 12 | * @param {string} page.query.required - page 13 | */ 14 | function list(req, res) { 15 | const page = req.query.page == 1 ? '' : '_' + req.query.page; 16 | let url = `http://www.netbian.com/meinv/index${page}.htm`; 17 | let headers = { 18 | 'Proxy-Connection': 'keep-alive', 19 | Host: 'www.netbian.com', 20 | Referer: 'http://www.netbian.com/meinv/index.htm', 21 | Accept: 22 | 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 23 | 'Upgrade-Insecure-Requests': 1, 24 | Connection: 'keep-alive', 25 | 'User-Agent': 26 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' 27 | }; 28 | request( 29 | { 30 | url: url, 31 | encoding: null, 32 | headers: headers 33 | }, 34 | function (error, response, body) { 35 | console.log(body); 36 | if (response && response.statusCode === 200) { 37 | body = Iconv.decode(body, 'gb2312'); 38 | const $ = cheerio.load(body, { decodeEntities: false }); 39 | let tmp = []; 40 | $('.list li').each(function (i, ele) { 41 | let img = $(ele).find('img').attr('src'); 42 | let bigImg = img.replace('small', '').split('16')[0] + '.jpg'; 43 | let title = $(ele).text(); 44 | let imgList = { 45 | img, 46 | bigImg, 47 | title 48 | }; 49 | tmp.push(imgList); 50 | }); 51 | res.API(tmp); 52 | downloadImg(tmp); 53 | } else { 54 | res.API_ERROR('数据请求异常', 5001); 55 | } 56 | } 57 | ); 58 | } 59 | app.get('/', function (req, res) { 60 | list(req, res); 61 | }); 62 | 63 | // 异步执行函数,用于下载图片 64 | async function downloadImg(list) { 65 | Promise.all( 66 | list.map(async item => { 67 | await download(item.bigImg, 'dist', { filename: item.title + '.jpg' }); 68 | console.log(item.title + '......正在下载'); 69 | }) 70 | ) 71 | .then(() => { 72 | console.log('Download complete'); 73 | }) 74 | .catch(err => { 75 | console.log(err); 76 | }); 77 | } 78 | module.exports = app; 79 | -------------------------------------------------------------------------------- /src/controller/history-today/history-today-detail.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const queryDetail = require('@/src/models/history-today/history-today-detail'); 3 | const { validationResult } = require('express-validator'); 4 | const { detailRule } = require('./rule'); 5 | 6 | /** 7 | * GET /api/history-today-detail 8 | * @summary 历史上的今天列表 9 | * @tags 历史的今天 10 | * @description 历史上的今天列表 11 | * @param {string} date.query.required - 12-31 12 | * @param {string} content_id.query.required - 详情id 12092 13 | */ 14 | app.get('/', detailRule, (req, res) => { 15 | let err = validationResult(req); 16 | if (!err.isEmpty()) { 17 | return res.API_ERROR(err.mapped().date && err.mapped().date.msg, 1002, err.mapped()); 18 | } else { 19 | return queryDetail(req, res); 20 | } 21 | }); 22 | module.exports = app; 23 | -------------------------------------------------------------------------------- /src/controller/history-today/history-today.js: -------------------------------------------------------------------------------- 1 | const queryList = require('@/src/models/history-today/history-today'); 2 | const app = require('express')(); 3 | const { validationResult, check } = require('express-validator'); 4 | const validator = [ 5 | check('date').isLength({ min: 5, max: 5 }).withMessage('日期参数格式错误:mm-dd') 6 | ]; 7 | /** 8 | * GET /api/history-today 9 | * @tags 历史的今天 10 | * @summary 历史上的今天列表 11 | * @description 历史上的今天列表 12 | * @param {string} date.query.required - 12-31 13 | */ 14 | app.get('/', ...validator, (req, res) => { 15 | let err = validationResult(req); 16 | console.log(err); 17 | if (!err.isEmpty()) { 18 | return res.API_ERROR(err.mapped().date.msg, 1002, err.mapped()); 19 | } else { 20 | return queryList(req, res); 21 | } 22 | }); 23 | module.exports = app; 24 | -------------------------------------------------------------------------------- /src/controller/history-today/rule.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 参数验证规则 3 | */ 4 | const { check } = require('express-validator'); 5 | exports.detailRule = [ 6 | check('date', '日期参数格式错误:mm-dd').isLength({ min: 5, max: 5 }), 7 | check('content_id', 'content_id上送错误') 8 | .isInt({ gt: 0, lt: 100000 }) 9 | .isLength({ min: 1, max: 7 }) 10 | .isInt() 11 | ]; 12 | -------------------------------------------------------------------------------- /src/controller/icon-list.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | app.get('/', function (req, res) { 3 | const iconList = [ 4 | { 5 | icon: '../../images/dx.svg', 6 | name: '高校查询', 7 | url: '/pages/university/index' 8 | }, 9 | { 10 | icon: '../../images/star.svg', 11 | name: '星座运势', 12 | url: '/pages/star/index' 13 | }, 14 | { 15 | icon: '../../images/qrcode.svg', 16 | name: '维码生成', 17 | url: '/pages/qrcode/index' 18 | }, 19 | { 20 | icon: '../../images/idcard.svg', 21 | name: '身份证解析', 22 | url: '/pages/idcard/index' 23 | }, 24 | { 25 | icon: '../../images/mobile.svg', 26 | name: '手机归属地', 27 | url: '/pages/mobile/index' 28 | }, 29 | { 30 | icon: '../../images/history.svg', 31 | name: '历史的今天', 32 | url: '/pages/todayOnHistory/eventList/index' 33 | }, 34 | { 35 | icon: '../../images/bankcard.svg', 36 | name: '银行卡信息', 37 | url: '/pages/bankCard/index' 38 | }, 39 | { 40 | icon: '../../images/pinyin2.svg', 41 | name: '查拼音', 42 | url: '/pages/pinyin/index' 43 | }, 44 | { 45 | icon: '../../images/chinese.svg', 46 | name: '数字转大写', 47 | url: '/pages/numberToChinese/index' 48 | }, 49 | { 50 | icon: '../../images/jitang.svg', 51 | name: '鸡汤文', 52 | url: '/pages/sentence/index' 53 | }, 54 | { 55 | icon: '../../images/idiom.svg', 56 | name: '成语词典', 57 | url: '/pages/idiom/index' 58 | }, 59 | { 60 | icon: '../../images/gs.svg', 61 | name: '个税计算', 62 | url: '' 63 | } 64 | ]; 65 | res.API(iconList); 66 | }); 67 | 68 | module.exports = app; 69 | -------------------------------------------------------------------------------- /src/controller/idcard-info.js: -------------------------------------------------------------------------------- 1 | const idCard = require('idcard'); 2 | const lunarCalendarFix = require('lunar-calendar-fix'); 3 | const app = require('express')(); 4 | const { query, validationResult } = require('express-validator'); 5 | 6 | /** 7 | * GET /api/idcard-info 8 | * @tags 卡类信息 9 | * @summary 身份证信息解析 10 | * @description 根据身份证号解析基本信息、包括省市区 11 | * @param {string} cardNo.query.required - 身份证号码 12 | */ 13 | app.get( 14 | '/', 15 | query('cardNo').isLength({ min: 18, max: 18 }).withMessage('cardNo格式错误'), 16 | (req, res) => { 17 | const err = validationResult(req); 18 | console.log(err); 19 | if (!err.isEmpty()) { 20 | return res.send({ 21 | code: 1002, 22 | data: err.mapped(), 23 | msg: err.mapped().cardNo.msg 24 | }); 25 | } 26 | 27 | let cardNo = req.query.cardNo; 28 | let cardInfo = idCard.info(cardNo); 29 | if (cardInfo && cardInfo.valid) { 30 | let birthday = cardInfo.birthday; 31 | const reg = /(\d{4})(\d{2})(\d{2})/; 32 | reg.test(birthday); 33 | const data = lunarCalendarFix.solarToLunar(RegExp.$1, RegExp.$2, RegExp.$3); 34 | cardInfo.zodiac = data.zodiac; 35 | cardInfo.GanZhiYear = data.GanZhiYear; 36 | cardInfo.nongli = `农历${data.lunarMonthName}${data.lunarDayName}日`; 37 | } 38 | res.API(cardInfo); 39 | } 40 | ); 41 | 42 | module.exports = app; 43 | -------------------------------------------------------------------------------- /src/controller/idiom.js: -------------------------------------------------------------------------------- 1 | const query = require('@/src/models/idiom/idiom'); 2 | const app = require('express')(); 3 | 4 | /** 5 | * GET /api/idiom 6 | * @summary 汉语词典数据 7 | * @description 汉语词典数据 8 | * @param {string} word.query.required - 关键字 9 | */ 10 | app.get('/', function (req, res) { 11 | query(req, res); 12 | }); 13 | module.exports = app; 14 | -------------------------------------------------------------------------------- /src/controller/job/lagou-positionsearch.js: -------------------------------------------------------------------------------- 1 | // 音乐新歌榜 2 | const app = require('express')(); 3 | const superagent = require('superagent'); 4 | 5 | /** 6 | * get /api/music/new-songs 7 | * @tags 工作职位 8 | * @summary 拉勾职位搜索 9 | * @description 拉勾职位搜索 10 | * @param {string} keyword.query.required - 搜索关键字 11 | * @param {string} city.query.required - 深圳|北京|上海|广州|南京|南昌 12 | */ 13 | app.get('/', function (req, res) { 14 | let query = req.query; 15 | let data = { 16 | pageNo: 1, 17 | pageSize: 15, 18 | city: query.city, 19 | sort: 0, 20 | keyword: query.keyword, 21 | isAd: '1' 22 | }; 23 | superagent 24 | .post('https://gate.lagou.com/v1/entry/positionsearch/searchPosition/v2') 25 | .set('Content-Type', 'application/json') 26 | .send(data) // sends a JSON post body 27 | .set('X-L-REQ-HEADER', '{ deviceType: 1 }') 28 | .set('Referer', 'https://m.lagou.com/') 29 | .set( 30 | 'user-agent', 31 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36' 32 | ) 33 | .end((err, data) => { 34 | try { 35 | data = JSON.parse(data.text); 36 | if (data.content) { 37 | return res.API(data.content); 38 | } else { 39 | return res.API_ERROR('系统请求错误'); 40 | } 41 | } catch (e) { 42 | return res.API_ERROR('系统请求错误'); 43 | } 44 | }); 45 | }); 46 | 47 | module.exports = app; 48 | -------------------------------------------------------------------------------- /src/controller/job/position-info.js: -------------------------------------------------------------------------------- 1 | const cheerio = require('cheerio'); 2 | const app = require('express')(); 3 | const request = require('request'); 4 | const Iconv = require('iconv-lite'); 5 | const Entities = require('html-entities').XmlEntities; 6 | const entities = new Entities(); 7 | 8 | function list(req, res) { 9 | // let positionId = parseInt(req.params.positionId); 10 | let url = 'https://m.lagou.com/wn/jobs/10426927.html?deliverFrom=JOBLIST_DELIVERY'; 11 | let headers = { 12 | connection: 'keep-alive', 13 | Cookie: 14 | '__cfduid=d34c02daf3555deb8443c4202ca0ca7d41511794384; gif-click-load=off; _ga=GA1.2.498763940.1511794387; _gid=GA1.2.1281594283.1512647401', 15 | accept: 16 | 'text/html, application/xhtml+xml, application/xml; q=0.9, image/webp,image/apng, */*;q=0.8', 17 | 'User-Agent': 18 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' 19 | }; 20 | request( 21 | { 22 | url: url, 23 | encoding: null, 24 | headers: headers, 25 | timeout: 5000 26 | }, 27 | function (error, response, body) { 28 | if (response && response.statusCode === 200) { 29 | body = Iconv.decode(body, 'utf-8'); 30 | console.log(body); 31 | $ = cheerio.load(body); 32 | let data = { 33 | title: $('title').text(), 34 | publishtime: $('.publish_time').text(), 35 | job: $('.job-name').find('.name').text(), 36 | salary: $('.ceil-salary').text(), 37 | workyear: $('.salary').next('span').next('span').text(), 38 | education: $('.salary').next('span').next('span').next('span').text(), 39 | workaddress: $('input[name="workAddress"]').val(), 40 | positionAddress: $('input[name="positionAddress"]').val(), 41 | temptation: $('.job-advantage').text(), 42 | content: entities.decode($('.job_bt').find('div').html()) 43 | }; 44 | console.log(data); 45 | res.API(data); 46 | } else { 47 | res.API_ERROR('接口请求异常', 500); 48 | } 49 | } 50 | ); 51 | } 52 | 53 | app.get('/:positionId', function (req, res) { 54 | list(req, res); 55 | }); 56 | module.exports = app; 57 | -------------------------------------------------------------------------------- /src/controller/jwt.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const Token = require('@/src/utils/jwt'); 3 | app.get('/', function (req, res) { 4 | // 加密 5 | const token = Token.encrypt({ id: 1 }, '1d'); 6 | res.API(token); 7 | 8 | // const str = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjQ4MTc0NDA4LCJleHAiOjE2NDgxNzQ0Njh9.iqrpT44gIa5Qs1Ii1lSu5NuIZoJv-uPCBGRRiE7IFl4'; 9 | // const r = Token.decrypt(str); 10 | // res.API(r); 11 | }); 12 | module.exports = app; 13 | -------------------------------------------------------------------------------- /src/controller/lunar-calendar.js: -------------------------------------------------------------------------------- 1 | const lunarCalendarFix = require('lunar-calendar-fix'); 2 | const app = require('express')(); 3 | const { validationResult, check, matchedData } = require('express-validator'); 4 | const reg = /(\d{4})-(\d{2})-(\d{2})/; 5 | /** 6 | * GET /api/lunar-calendar 7 | * @summary 黄历假日接口 8 | * @param {string} date.query.required - 年月日yyyy-mm-dd 9 | */ 10 | app.get('/', check('date', '请输入格式正确的日期格式:yyyy-mm-dd').matches(reg), (req, res) => { 11 | // 获取报错的数据 12 | let err = validationResult(req); 13 | 14 | // 获取匹配的数据 15 | let allData = matchedData(req); 16 | if (!err.isEmpty()) { 17 | return res.send({ 18 | code: 1002, 19 | data: err.mapped(), 20 | msg: err.mapped().date.msg 21 | }); 22 | } 23 | reg.test(allData.date); 24 | const data = lunarCalendarFix.solarToLunar(RegExp.$1, RegExp.$2, RegExp.$3); 25 | res.API(data); 26 | }); 27 | 28 | module.exports = app; 29 | -------------------------------------------------------------------------------- /src/controller/music/new-songs.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/new-songs 6 | * @tags 酷狗音乐 7 | * @summary 音乐新歌榜 8 | * @description 酷狗音乐新歌榜 9 | */ 10 | app.post('/', function (req, res) { 11 | let host = 'm.kugou.com'; 12 | let path = '/?json=true'; 13 | let data = {}; 14 | request 15 | .httpGet({ host, data, path }) 16 | .then(function (body) { 17 | console.log(body); 18 | res.API(JSON.parse(body)['data']); 19 | }) 20 | .catch(function (err) { 21 | res.API_ERROR('服务器异常'); 22 | console.log(err); 23 | }); 24 | }); 25 | 26 | module.exports = app; 27 | -------------------------------------------------------------------------------- /src/controller/music/plist-songs.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/plist-songs 6 | * @tags 酷狗音乐 7 | * @summary 音乐歌单下的音乐列表 8 | * @description 音乐歌单下的音乐列表 9 | */ 10 | app.post('/:specialid', function (req, res) { 11 | let specialid = req.params.specialid; 12 | let host = 'm.kugou.com'; 13 | let path = `/plist/list/${specialid}?json=true`; 14 | request 15 | .httpGet({ host, path }) 16 | .then(function (body) { 17 | console.log(body); 18 | res.API(JSON.parse(body)['list']); 19 | }) 20 | .catch(function (err) { 21 | res.API_ERROR('服务器异常', 500); 22 | console.log(err); 23 | }); 24 | }); 25 | 26 | module.exports = app; 27 | -------------------------------------------------------------------------------- /src/controller/music/plist.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/plist 6 | * @tags 酷狗音乐 7 | * @summary 音乐歌单 8 | * @description 酷狗音乐歌单 9 | */ 10 | app.post('/', function (req, res) { 11 | let host = 'm.kugou.com'; 12 | let path = '/plist/index&json=true'; 13 | let data = {}; 14 | // false:http请求 true:https请求 15 | request 16 | .httpGet({ host, data, path }) 17 | .then(function (body) { 18 | res.API(JSON.parse(body)['plist']); 19 | }) 20 | .catch(function (err) { 21 | res.API_ERROR('服务器异常', 500); 22 | console.log(err); 23 | }); 24 | }); 25 | 26 | module.exports = app; 27 | -------------------------------------------------------------------------------- /src/controller/music/rank-list-info.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/rank-list-info 6 | * @tags 酷狗音乐 7 | * @summary 排行榜下的音乐列表 8 | * @description 排行榜下的音乐列表 9 | */ 10 | app.post('/:rankId', function (req, res) { 11 | let rankId = req.params.rankId; 12 | let host = 'm.kugou.com'; 13 | let path = `/rank/info/${rankId}&json=true`; 14 | request 15 | .httpGet({ host, path }) 16 | .then(function (body) { 17 | body = JSON.parse(body); 18 | let result = { 19 | info: body['info'], 20 | songs: body['songs'], 21 | pagesize: body['pagesize'] 22 | }; 23 | res.API(result); 24 | }) 25 | .catch(function (err) { 26 | res.API_ERROR('服务器异常', 500); 27 | console.log(err); 28 | }); 29 | }); 30 | 31 | module.exports = app; 32 | -------------------------------------------------------------------------------- /src/controller/music/rank-list.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/rank-list 6 | * @tags 酷狗音乐 7 | * @summary 音乐排行榜 8 | * @description 酷狗音乐排行榜 9 | */ 10 | app.post('/', function (req, res) { 11 | let host = 'm.kugou.com'; 12 | let path = '/rank/list&json=true'; 13 | let data = {}; 14 | request 15 | .httpGet({ host, data, path }) 16 | .then(function (body) { 17 | console.log(body); 18 | res.API(JSON.parse(body)['rank']); 19 | }) 20 | .catch(function (err) { 21 | res.API_ERROR('服务器异常', 500); 22 | console.log(err); 23 | }); 24 | }); 25 | 26 | module.exports = app; 27 | -------------------------------------------------------------------------------- /src/controller/music/search.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/search 6 | * @tags 酷狗音乐 7 | * @summary 音乐搜索 8 | * @description 酷狗音乐搜索 9 | * @param {string} keyword.params.required - 搜索关键字 10 | */ 11 | app.post('/', function (req, res) { 12 | console.log(req.params); 13 | let keyword = encodeURIComponent(req.params.keyword); 14 | console.log(); 15 | let host = 'mobilecdn.kugou.com'; 16 | let path = `/api/v3/search/song?format=json&keyword=${keyword}&page=1&pagesize=20&showtype=1`; 17 | let data = {}; 18 | // false:http请求 true:https请求 19 | request 20 | .httpGet({ host, data, path }) 21 | .then(function (body) { 22 | res.API(JSON.parse(body)['data']); 23 | }) 24 | .catch(function (err) { 25 | res.API_ERROR('服务器异常', 500); 26 | console.log(err); 27 | }); 28 | }); 29 | 30 | module.exports = app; 31 | -------------------------------------------------------------------------------- /src/controller/music/singer-classify.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/singer-classify 6 | * @tags 酷狗音乐 7 | * @summary 歌手分类 8 | * @description 歌手分类 9 | */ 10 | app.post('/', function (req, res) { 11 | let host = 'm.kugou.com'; 12 | let path = '/singer/class&json=true'; 13 | // false:http请求 true:https请求 14 | request 15 | .httpGet({ host, path }) 16 | .then(function (body) { 17 | res.API(JSON.parse(body)['list']); 18 | }) 19 | .catch(function (err) { 20 | res.API_ERROR('服务器异常', 500); 21 | console.log(err); 22 | }); 23 | }); 24 | 25 | module.exports = app; 26 | -------------------------------------------------------------------------------- /src/controller/music/singer-info.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/singer-info 6 | * @tags 酷狗音乐 7 | * @summary 歌手详细信息 8 | * @description 歌手详细信息 9 | */ 10 | app.get('/:singerid', function (req, res) { 11 | let singerid = req.params.singerid; 12 | let host = 'm.kugou.com'; 13 | let path = `/singer/info/${singerid}&json=true`; 14 | // false:http请求 true:https请求 15 | request 16 | .httpMobileGet({ host, path }) 17 | .then(function (body) { 18 | body = JSON.parse(body); 19 | let result = { 20 | info: body['info'], 21 | songs: body['songs'] 22 | }; 23 | res.API(result); 24 | }) 25 | .catch(function (err) { 26 | res.API_ERROR('服务器异常', 500); 27 | console.log(err); 28 | }); 29 | }); 30 | 31 | module.exports = app; 32 | -------------------------------------------------------------------------------- /src/controller/music/singer-list.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/songer-list 6 | * @tags 酷狗音乐 7 | * @summary 歌手分类下面的某一类歌手 8 | * @description 歌手分类下面的某一类歌手 9 | */ 10 | app.post('/:classid', function (req, res) { 11 | let classid = req.params.classid; 12 | let host = 'm.kugou.com'; 13 | let path = `/singer/list/${classid}&json=true`; 14 | // false:http请求 true:https请求 15 | request 16 | .httpGet({ host, path }) 17 | .then(function (body) { 18 | body = JSON.parse(body); 19 | let result = { 20 | classname: body['classname'], 21 | classid: body['classid'], 22 | singers: body['singers'] 23 | }; 24 | res.API(result); 25 | }) 26 | .catch(function (err) { 27 | res.API_ERROR('服务器异常', 500); 28 | console.log(err); 29 | }); 30 | }); 31 | 32 | module.exports = app; 33 | -------------------------------------------------------------------------------- /src/controller/music/song-info.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/song-info 6 | * @tags 酷狗音乐 7 | * @summary 音乐详情信息 8 | * @description 音乐详情信息 9 | */ 10 | app.post('/:hash', function (req, res) { 11 | let hash = req.params.hash; 12 | let host = 'm.kugou.com'; 13 | let path = `/app/i/getSongInfo.php?cmd=playInfo&hash=${hash}`; 14 | let data = {}; 15 | // false:http请求 true:https请求 16 | request 17 | .httpGet({ host, data, path }) 18 | .then(function (body) { 19 | res.API(JSON.parse(body)); 20 | }) 21 | .catch(function (err) { 22 | res.API_ERROR('服务器异常', 500); 23 | console.log(err); 24 | }); 25 | }); 26 | 27 | module.exports = app; 28 | -------------------------------------------------------------------------------- /src/controller/music/song-lrc.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('../../utils/request.js'); 3 | 4 | /** 5 | * POST /api/music/song-lrc 6 | * @tags 酷狗音乐 7 | * @summary 取音乐歌词 8 | * @description 获取音乐歌词 9 | */ 10 | 11 | // 获取音乐歌词 12 | app.post('/:hash', function (req, res) { 13 | let hash = req.params.hash; 14 | let host = 'm.kugou.com'; 15 | let path = `/app/i/krc.php?cmd=100&hash=${hash}&timelength=3012000`; 16 | let data = {}; 17 | // false:http请求 true:https请求 18 | request 19 | .httpGet({ host, data, path }) 20 | .then(function (body) { 21 | res.API(body); 22 | }) 23 | .catch(function (err) { 24 | res.API_ERROR('服务器异常', 500); 25 | console.log(err); 26 | }); 27 | }); 28 | 29 | module.exports = app; 30 | -------------------------------------------------------------------------------- /src/controller/star-detail/juhe-star-detail.js: -------------------------------------------------------------------------------- 1 | const queryDetail = require('@/src/models/star-detail/juhe-star-detail'); 2 | const app = require('express')(); 3 | // const apicache = require('apicache'); 4 | // let cache = apicache.middleware; 5 | // cache('5 minutes'), 6 | const { validationResult, check } = require('express-validator'); 7 | const rule = [check('consName').isLength({ min: 3, max: 3 }).withMessage('星座名称错误')]; 8 | /** 9 | * GET /api/juhe-star-detail 10 | * @summary 星座运势 11 | * @description 星座运势 12 | * @param {string} consName.query.required - 星座名称:白羊座 13 | */ 14 | app.get('/', ...rule, (req, res) => { 15 | let err = validationResult(req); 16 | if (!err.isEmpty()) { 17 | return res.send({ 18 | code: 1002, 19 | data: err.mapped(), 20 | msg: err.mapped().consName.msg 21 | }); 22 | } else { 23 | return queryDetail(req, res); 24 | } 25 | }); 26 | module.exports = app; 27 | -------------------------------------------------------------------------------- /src/controller/star-detail/star-detail.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('@/src/utils/request'); 3 | app.get('/', function (req, res) { 4 | let star = req.query.star; 5 | if (!star) { 6 | res.API_ERROR('星座不能为空', 300); 7 | return; 8 | } 9 | let host = 'ali-star-lucky.showapi.com'; 10 | let path = '/star?'; 11 | let data = { 12 | needMonth: 1, 13 | needTomorrow: 1, 14 | needWeek: 1, 15 | needYear: 0, 16 | star: star 17 | }; 18 | let headers = { 19 | Authorization: 'APPCODE ' + process.env.STAR_APPCODE 20 | }; 21 | request 22 | .httpGet({ host, data, path, headers, https: true }) 23 | .then(function (body) { 24 | body = JSON.parse(body); 25 | if (body.showapi_res_code === 0) { 26 | res.API(body['showapi_res_body']); 27 | } else { 28 | res.API_ERROR('验证未通过', 300); 29 | } 30 | }) 31 | .catch(function (err) { 32 | res.API_ERROR('网络好像有点问题', 400); 33 | console.log(err); 34 | }); 35 | }); 36 | 37 | module.exports = app; 38 | -------------------------------------------------------------------------------- /src/controller/tang300.js: -------------------------------------------------------------------------------- 1 | const query = require('@/src/models/poetry/tang300'); 2 | const app = require('express')(); 3 | 4 | /** 5 | * GET /api/tang300 6 | * @summary 唐诗300首 7 | * @description 唐诗300首 8 | * @param {string} contents.query.required - 关键字 9 | * @param {number} page.query.required - 页码 10 | */ 11 | app.get('/', async function (req, res) { 12 | if(!req.query.contents) res.API_ERROR('请输入关键字', 300); 13 | await query(req, res); 14 | }); 15 | module.exports = app; 16 | -------------------------------------------------------------------------------- /src/controller/university/rule.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 参数验证 3 | */ 4 | const { check, validationResult } = require('express-validator'); 5 | exports.universityRule = [ 6 | check('type', '参数格式错误:985|211|一流大学|一流学科') 7 | .default('') 8 | .isLength({ min: 0, max: 6 }) 9 | .isIn(['985', '211', '一流大学A类', '一流大学B类', '一流学科', '']), 10 | check('page', '分页数不符').default(1).isInt({ gt: 0 }).isLength({ min: 1, max: 3 }), 11 | check('schoolname', '院校名称').default('').isLength({ min: 0, max: 20 }) 12 | ]; 13 | exports.ruleResult = (req, res) => { 14 | let err = validationResult(req); 15 | if (!err.isEmpty()) { 16 | const [{ msg }] = err.errors; 17 | return res.send({ 18 | code: 1002, 19 | data: err.mapped(), 20 | msg: msg 21 | }); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /src/controller/university/university.js: -------------------------------------------------------------------------------- 1 | const universityQuery = require('@/src/models/university/university'); 2 | const { universityRule } = require('./rule'); 3 | const { validationResult } = require('express-validator'); 4 | 5 | const app = require('express')(); 6 | 7 | /** 8 | * GET /api/university 9 | * @summary 全国高校信息 10 | * @description 全国高校信息 11 | * @param {string} type.query.required - 类型 985|211|一流大学|一流学科 12 | * @param {string} schoolname.query - 学校名称 13 | */ 14 | app.get('/', universityRule, (req, res) => { 15 | // 参数验证抛错 16 | let err = validationResult(req); 17 | if (!err.isEmpty()) { 18 | const [{ msg }] = err.errors; 19 | return res.send({ 20 | code: 1002, 21 | data: err.mapped(), 22 | msg: msg 23 | }); 24 | } 25 | return universityQuery(req, res); 26 | }); 27 | module.exports = app; 28 | -------------------------------------------------------------------------------- /src/controller/we-app/getUserInfo.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | const request = require('@/src/utils/request'); 3 | const queryUser = require('@/src/models/we-app/wx-login'); 4 | 5 | /** 6 | * 获取用户信息 7 | * @param req 8 | * @param res 9 | */ 10 | function getUserInfo(req, res) { 11 | let host = 'api.weixin.qq.com'; 12 | let path = '/sns/jscode2session?'; 13 | let data = { 14 | appid: process.env.appid, //自己小程序后台管理的appid,可登录小程序后台查看 15 | secret: process.env.secret, //小程序后台管理的secret,可登录小程序后台查看 16 | grant_type: 'authorization_code', // 授权(必填)默认值 17 | js_code: req.query.code //获取小程序传来的code 18 | }; 19 | request 20 | .httpGet({ host, data, path, https: true }) 21 | .then(function (body) { 22 | console.log(body); 23 | body = JSON.parse(body); 24 | let openid = body.openid; // 得到openid 25 | let sessionKey = body.session_key; // 得到session_key 26 | if (body.errcode) { 27 | res.send({ 28 | code: 1003, 29 | data: body, 30 | msg: '请求失败' 31 | }); 32 | } else { 33 | queryUser(req, res, sessionKey, openid); 34 | } 35 | }) 36 | .catch(function (err) { 37 | console.log(err); 38 | return res.send({ 39 | code: 400, 40 | msg: '网络好像有点问题' 41 | }); 42 | }); 43 | } 44 | /** 45 | * GET /api/getUserInfo 46 | * @tags 用户 47 | * @summary 获取微信用户信息 48 | * @description 获取微信用户信息 49 | * @param {string} code.query.required - 微信wx.login code 50 | */ 51 | app.get('/', (req, res) => { 52 | //const params = req.query; 53 | getUserInfo(req, res); 54 | }); 55 | 56 | module.exports = app; 57 | -------------------------------------------------------------------------------- /src/controller/web/404.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const app = require('express')(); 3 | app.get('*', function (req, res) { 4 | res.render('web/404.html', { 5 | title: '404' 6 | }); 7 | }); 8 | module.exports = app; 9 | -------------------------------------------------------------------------------- /src/controller/web/index.js: -------------------------------------------------------------------------------- 1 | const app = require('express')(); 2 | app.get('/', function (req, res) { 3 | // res.header('Content-Type:text/html; charset=utf-8'); 4 | res.render('index.html', { 5 | title: '欢迎使用' 6 | }); 7 | }); 8 | 9 | module.exports = app; 10 | -------------------------------------------------------------------------------- /src/entity/historyTodayOrm.js: -------------------------------------------------------------------------------- 1 | const historyTodayOrm = require('@/src/config/orm'); 2 | const { DataTypes } = require('sequelize'); 3 | const HisToday = historyTodayOrm.define( 4 | 'HisToday', 5 | { 6 | date: { 7 | type: DataTypes.STRING, 8 | allowNull: true 9 | }, 10 | title: { 11 | type: DataTypes.STRING, 12 | allowNull: false 13 | }, 14 | year: { 15 | type: DataTypes.STRING, 16 | allowNull: false 17 | }, 18 | content_id: { 19 | type: DataTypes.STRING, 20 | allowNull: true 21 | }, 22 | rich_text: { 23 | type: DataTypes.STRING 24 | } 25 | }, 26 | { 27 | tableName: 'his_today', 28 | deletedAt: false, 29 | createdAt: false, 30 | updatedAt: false 31 | } 32 | ); 33 | 34 | module.exports = HisToday; 35 | -------------------------------------------------------------------------------- /src/entity/idiomOrm.js: -------------------------------------------------------------------------------- 1 | const idiomOrm = require('@/src/config/orm'); 2 | const { DataTypes } = require('sequelize'); 3 | 4 | const idiom = idiomOrm.define( 5 | 'idiom', 6 | { 7 | derivation: { 8 | type: DataTypes.STRING, 9 | allowNull: true 10 | }, 11 | example: { 12 | type: DataTypes.STRING, 13 | allowNull: false 14 | }, 15 | explanation: { 16 | type: DataTypes.STRING, 17 | allowNull: false 18 | }, 19 | pinyin: { 20 | type: DataTypes.STRING, 21 | allowNull: true 22 | }, 23 | abbreviation: { 24 | type: DataTypes.STRING, 25 | allowNull: true 26 | }, 27 | word: { 28 | type: DataTypes.STRING 29 | } 30 | }, 31 | { 32 | tableName: 'idiom', 33 | deletedAt: false, 34 | createdAt: false, 35 | updatedAt: false 36 | } 37 | ); 38 | 39 | module.exports = idiom; 40 | -------------------------------------------------------------------------------- /src/entity/poetryOrm.js: -------------------------------------------------------------------------------- 1 | const poetryOrm = require('@/src/config/orm'); 2 | const { DataTypes } = require('sequelize'); 3 | const Tang300 = poetryOrm.define( 4 | 'Tang300', 5 | { 6 | id: { 7 | type: DataTypes.INTEGER, 8 | primaryKey: true 9 | }, 10 | contents: { 11 | type: DataTypes.STRING, 12 | allowNull: false 13 | }, 14 | type: { 15 | type: DataTypes.STRING, 16 | allowNull: false 17 | }, 18 | author: { 19 | type: DataTypes.STRING, 20 | allowNull: true 21 | }, 22 | title: { 23 | type: DataTypes.STRING 24 | } 25 | }, 26 | { 27 | tableName: 'tang300', 28 | deletedAt: false, 29 | createdAt: false, 30 | updatedAt: false 31 | } 32 | ); 33 | 34 | module.exports = Tang300; 35 | -------------------------------------------------------------------------------- /src/entity/starDetailOrm.js: -------------------------------------------------------------------------------- 1 | const starDetailOrm = require('@/src/config/orm'); 2 | const { DataTypes } = require('sequelize'); 3 | const starDetail = starDetailOrm.define( 4 | 'starDetail', 5 | { 6 | date: { 7 | type: DataTypes.STRING 8 | }, 9 | consName: { 10 | type: DataTypes.STRING 11 | }, 12 | today: { 13 | type: DataTypes.TEXT 14 | }, 15 | tomorrow: { 16 | type: DataTypes.TEXT 17 | }, 18 | week: { 19 | type: DataTypes.TEXT 20 | }, 21 | month: { 22 | type: DataTypes.TEXT 23 | }, 24 | year: { 25 | type: DataTypes.TEXT 26 | } 27 | }, 28 | { 29 | tableName: 'star_detail', 30 | deletedAt: false, 31 | createdAt: false, 32 | updatedAt: false 33 | } 34 | ); 35 | 36 | module.exports = starDetail; 37 | -------------------------------------------------------------------------------- /src/entity/universityOrm.js: -------------------------------------------------------------------------------- 1 | const universityOrm = require('@/src/config/orm'); 2 | const { DataTypes } = require('sequelize'); 3 | // eslint-disable-next-line no-unused-vars 4 | const University = universityOrm.define( 5 | 'university', 6 | { 7 | code: { 8 | type: DataTypes.STRING, 9 | allowNull: true 10 | }, 11 | schoolname: { 12 | type: DataTypes.STRING, 13 | allowNull: false 14 | }, 15 | province: { 16 | type: DataTypes.STRING, 17 | allowNull: false 18 | }, 19 | city: { 20 | type: DataTypes.STRING, 21 | allowNull: true 22 | }, 23 | department: { 24 | type: DataTypes.STRING 25 | }, 26 | level: { 27 | type: DataTypes.STRING 28 | }, 29 | type: { 30 | type: DataTypes.STRING 31 | }, 32 | link: { 33 | type: DataTypes.STRING 34 | } 35 | }, 36 | { 37 | tableName: 'university', 38 | deletedAt: false, 39 | createdAt: false, 40 | updatedAt: false 41 | } 42 | ); 43 | 44 | module.exports = University; 45 | -------------------------------------------------------------------------------- /src/entity/userOrm.js: -------------------------------------------------------------------------------- 1 | const orm = require('@/src/config/orm'); 2 | const { DataTypes } = require('sequelize'); 3 | const User = orm.define( 4 | 'User', 5 | { 6 | // 在这里定义模型属性 7 | loginName: { 8 | type: DataTypes.STRING, 9 | allowNull: false 10 | }, 11 | id: { 12 | type: DataTypes.INTEGER, 13 | allowNull: false, 14 | primaryKey: true 15 | }, 16 | chineseName: { 17 | type: DataTypes.STRING 18 | // allowNull 默认为 true 19 | } 20 | }, 21 | { 22 | tableName: 'user', 23 | deletedAt: false, 24 | createdAt: false, 25 | updatedAt: false 26 | } 27 | ); 28 | 29 | module.exports = User; 30 | -------------------------------------------------------------------------------- /src/entity/weAppOrm.js: -------------------------------------------------------------------------------- 1 | const weAppOrm = require('@/src/config/orm'); 2 | const { DataTypes } = require('sequelize'); 3 | const wxUser = weAppOrm.define( 4 | 'wxUser', 5 | { 6 | avatarUrl: { 7 | type: DataTypes.STRING 8 | }, 9 | city: { 10 | type: DataTypes.STRING 11 | }, 12 | province: { 13 | type: DataTypes.STRING 14 | }, 15 | country: { 16 | type: DataTypes.STRING 17 | }, 18 | nickName: { 19 | type: DataTypes.STRING 20 | }, 21 | gender: { 22 | type: DataTypes.STRING 23 | }, 24 | language: { 25 | type: DataTypes.STRING 26 | }, 27 | openid: { 28 | type: DataTypes.STRING, 29 | allowNull: false 30 | } 31 | }, 32 | { 33 | tableName: 'wx_user', 34 | deletedAt: false, 35 | createdAt: true, 36 | updatedAt: false 37 | } 38 | ); 39 | 40 | module.exports = wxUser; 41 | -------------------------------------------------------------------------------- /src/middlewares/interceptor.js: -------------------------------------------------------------------------------- 1 | const APISign = require('@/src/utils/api-sign'); 2 | module.exports = function (req, res, next) { 3 | console.log(process.env.NODE_ENV); 4 | // 对非API地址放行 5 | if (req.path.indexOf('api/') < 0) { 6 | return next(); 7 | } 8 | 9 | // 获取请求头信息、作为签名参数 10 | const headerInfo = { 11 | sign: req.headers['sign'], 12 | timestamp: req.headers['timestamp'] 13 | }; 14 | console.log(req.path); 15 | if (!APISign(headerInfo)) { 16 | return res.status(400).API_ERROR('非法请求,您的IP已被记录,请谨慎操作', 1003); 17 | } 18 | next(); 19 | }; 20 | -------------------------------------------------------------------------------- /src/middlewares/openPath.js: -------------------------------------------------------------------------------- 1 | const openUrl = ['/', '/web/login', '/web/loginApi', '/api/badjs']; 2 | module.exports = openUrl; 3 | -------------------------------------------------------------------------------- /src/middlewares/resAPI.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 重载接口返回格式封装 3 | * @param req 4 | * @param res 5 | * @param next 6 | */ 7 | module.exports = function (req, res, next) { 8 | const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; 9 | res.API = (data, msg = 'success') => { 10 | let json = { 11 | msg: msg, 12 | data: data, 13 | code: 200, 14 | ip 15 | }; 16 | return res.json(json); 17 | }; 18 | 19 | res.API_ERROR = (msg, code, data = null) => { 20 | let json = { 21 | msg, 22 | data, 23 | code, 24 | ip 25 | }; 26 | return res.json(json); 27 | }; 28 | next(); 29 | }; 30 | -------------------------------------------------------------------------------- /src/models/history-today/history-today-detail.js: -------------------------------------------------------------------------------- 1 | const HisToday = require('../../entity/historyTodayOrm'); 2 | const crawlerRequest = require('@/src/utils/crawler-request'); 3 | 4 | function spiderData(req, res) { 5 | let { date, content_id } = req.query; 6 | let url = `https://www.chazidian.com/d/${date}/${content_id}/`; 7 | crawlerRequest({ url }) 8 | .then($ => { 9 | const rich_text = $('.hist_actcont') 10 | .prop('outerHTML') 11 | .replace(//gi, ''); 12 | const title = $('.hist_actcont h1').text(); 13 | if (rich_text) { 14 | updateDB(rich_text, content_id).then(r => { 15 | console.log('success', r); 16 | }); 17 | } 18 | res.API({ 19 | rich_text, 20 | title 21 | }); 22 | }) 23 | .catch(() => { 24 | res.API_ERROR('请求异常', 500); 25 | }); 26 | } 27 | 28 | async function queryDetail(req, res) { 29 | const project = await HisToday.findOne({ 30 | where: { content_id: req.query.content_id }, 31 | attributes: ['title', 'content_id', 'rich_text'] //返回特定字段 32 | }); 33 | console.log(project); 34 | if (!project) { 35 | res.API_ERROR('不存在该条数据', 1001); 36 | } 37 | if (project && project.rich_text) { 38 | return res.API(project); 39 | } else { 40 | spiderData(req, res); 41 | } 42 | } 43 | async function updateDB(val, content_id) { 44 | return await HisToday.update( 45 | { 46 | rich_text: val 47 | }, 48 | { 49 | where: { 50 | content_id: content_id 51 | } 52 | } 53 | ); 54 | } 55 | 56 | module.exports = queryDetail; 57 | -------------------------------------------------------------------------------- /src/models/history-today/history-today.js: -------------------------------------------------------------------------------- 1 | const HisToday = require('../../entity/historyTodayOrm'); 2 | const crawlerRequest = require('@/src/utils/crawler-request'); 3 | 4 | function spiderData(req, res) { 5 | let date = req.query.date; 6 | let url = `https://www.chazidian.com/d/${date}/`; 7 | crawlerRequest({ url }) 8 | .then($ => { 9 | let link = []; 10 | $('.histday_cont') 11 | .eq(0) 12 | .find('ul li') 13 | .each(function () { 14 | let year = $(this).find('a').first().text(); 15 | let title = $(this).find('a').last().text(); 16 | let href = $(this).find('a').last().attr('href'); 17 | let tmp = { 18 | year, 19 | title: title, 20 | date, 21 | content_id: href.replace('https://www.chazidian.com/d/', '').match(/\/(\S*)\//)[1] 22 | }; 23 | link.push(tmp); 24 | }); 25 | createDB(link).then(r => { 26 | console.log(r); 27 | }); 28 | res.API(link); 29 | }) 30 | .catch(err => { 31 | console.log(err, 222); 32 | res.API_ERROR('请求异常', 5001); 33 | }); 34 | } 35 | async function queryList(req, res) { 36 | const project = await HisToday.findAll({ 37 | where: { date: req.query.date }, 38 | attributes: ['date', 'title', 'year', 'content_id'] //返回特定字段 39 | }); 40 | 41 | if (project.length) { 42 | res.API(project); 43 | } else { 44 | spiderData(req, res); 45 | } 46 | } 47 | 48 | async function createDB(data) { 49 | return await HisToday.bulkCreate(data); 50 | } 51 | 52 | module.exports = queryList; 53 | -------------------------------------------------------------------------------- /src/models/idiom/CSV.js: -------------------------------------------------------------------------------- 1 | // const CHENGYU = require('./ORM'); 2 | // 3 | // const fs = require('fs'); 4 | // const path = require('path'); 5 | // const configFile = path.resolve(__dirname, './idiom.json'); 6 | // const Json2csvParser = require('json2csv').Parser; 7 | // 8 | // async function createDB() { 9 | // 10 | // const data = fs.readFileSync(configFile, 'UTF-8').toString(); 11 | // let config = JSON.parse(data); 12 | // 13 | // const fields = ['derivation', 'example', 'explanation', 'pinyin','word','abbreviation']; 14 | // const json2csvParser = new Json2csvParser({ fields }); 15 | // const csv = json2csvParser.parse(config); 16 | // 17 | // fs.writeFile('./成语.csv', csv, function(err) { 18 | // if(err) { 19 | // // return console.log(err); 20 | // } 21 | // 22 | // console.log('The file was saved!'); 23 | // }); 24 | // 25 | // 26 | // 27 | // 28 | // // return await CHENGYU.bulkCreate(config).catch(err=>{ 29 | // // console.log(err); 30 | // // }); 31 | // } 32 | // 33 | // module.exports = createDB; 34 | -------------------------------------------------------------------------------- /src/models/idiom/idiom.js: -------------------------------------------------------------------------------- 1 | let Sequelize = require('sequelize'); 2 | let Op = Sequelize.Op; 3 | const Idiom = require('../../entity/idiomOrm'); 4 | 5 | async function query(req, res) { 6 | const word = req.query.word; 7 | let whereInfo = { 8 | word: { 9 | [Op.like]: `%${word}%` 10 | } 11 | }; 12 | const result = await Idiom.findAndCountAll({ 13 | order: [['id', 'ASC']], // 正常升序 14 | where: whereInfo, 15 | limit: 15 16 | }); 17 | const data = { 18 | result: result.rows, 19 | pagination: { 20 | total: result.count 21 | } 22 | }; 23 | if (result.rows) { 24 | res.API(data); 25 | } 26 | } 27 | 28 | module.exports = query; 29 | -------------------------------------------------------------------------------- /src/models/poetry/tang300.js: -------------------------------------------------------------------------------- 1 | let Sequelize = require('sequelize'); 2 | let Op = Sequelize.Op; 3 | const Tang300 = require('../../entity/poetryOrm'); 4 | async function Tang300Query(req, res) { 5 | const contents = req.query.contents || ''; 6 | const pageSize = 10; 7 | const page = req.query.page || 1; 8 | let whereInfo = {}; 9 | if (contents) { 10 | whereInfo.contents = { 11 | [Op.like]: `%${contents}%` 12 | }; 13 | } 14 | const result = await Tang300.findAndCountAll({ 15 | order: [['id', 'ASC']], // 正常升序 16 | where: whereInfo, 17 | attributes: { 18 | exclude: ['id'] 19 | }, 20 | offset: (page - 1) * pageSize, 21 | limit: pageSize 22 | }); 23 | const data = { 24 | result: result.rows, 25 | pagination: { 26 | page, 27 | pageSize, 28 | total: result.count 29 | } 30 | }; 31 | if (result.rows) { 32 | res.API(data); 33 | } 34 | } 35 | module.exports = Tang300Query; 36 | -------------------------------------------------------------------------------- /src/models/star-detail/juhe-star-detail.js: -------------------------------------------------------------------------------- 1 | const dayjs = require('dayjs'); 2 | const starDetail = require('../../entity/starDetailOrm'); 3 | const request = require('@/src/utils/request'); 4 | // 5 | function spiderData(req, res) { 6 | let host = 'web.juhe.cn'; 7 | let path = '/constellation/getAll?'; 8 | let data = { 9 | consName: req.query.consName, 10 | key: 'a8f4e872b83a4bc901cf1ff42f2dcd83' 11 | }; 12 | request 13 | .httpGet({ host, data, path, https: true }) 14 | .then(function (body) { 15 | body = JSON.parse(body); 16 | if (body.resultcode === '200') { 17 | res.API(body); 18 | createDB(body, req); 19 | } else { 20 | res.API_ERROR('验证未通过', 300); 21 | } 22 | }) 23 | .catch(function (err) { 24 | res.API_ERROR('网络好像有点问题', 400); 25 | console.log(err); 26 | }); 27 | } 28 | async function queryDetail(req, res) { 29 | const data = await starDetail 30 | .findOne({ 31 | where: { 32 | date: dayjs().format('YYYY-MM-DD'), 33 | consName: req.query.consName 34 | }, 35 | attributes: ['date', 'consName', 'year', 'today', 'month', 'week', 'tomorrow'] //返回特定字段 36 | }) 37 | .catch(err => { 38 | console.log(err); 39 | }); 40 | if (data) { 41 | data.year = JSON.parse(data.year); 42 | data.month = JSON.parse(data.month); 43 | data.week = JSON.parse(data.week); 44 | data.today = data.today && JSON.parse(data.today); 45 | data.tomorrow = data.tomorrow && JSON.parse(data.tomorrow); 46 | res.API(data); 47 | } else { 48 | spiderData(req, res); 49 | } 50 | } 51 | 52 | function createDB(resData, req) { 53 | let data = { 54 | today: JSON.stringify(resData.today), 55 | tomorrow: JSON.stringify(resData.tomorrow), 56 | week: JSON.stringify(resData.week), 57 | month: JSON.stringify(resData.month), 58 | year: JSON.stringify(resData.year), 59 | date: dayjs().format('YYYY-MM-DD'), 60 | consName: req.query.consName 61 | }; 62 | return starDetail.create(data); 63 | } 64 | 65 | module.exports = queryDetail; 66 | -------------------------------------------------------------------------------- /src/models/university/university.js: -------------------------------------------------------------------------------- 1 | let Sequelize = require('sequelize'); 2 | let Op = Sequelize.Op; 3 | const University = require('../../entity/universityOrm'); 4 | async function universityQuery(req, res) { 5 | const type = req.query.type || ''; 6 | const pageSize = 10; 7 | const page = req.query.page || 1; 8 | const province = req.query.province; 9 | const schoolname = req.query.schoolname || ''; 10 | 11 | let whereInfo = { 12 | type: { 13 | [Op.like]: `%${type}%` 14 | }, 15 | schoolname: { 16 | [Op.like]: `%${schoolname}%` 17 | } 18 | }; 19 | 20 | if (province && province !== 'null' && province !== 'undefined') { 21 | whereInfo.province = province; 22 | } 23 | 24 | // if(!schoolname && schoolname ==='null' && schoolname ==='undefined'){ 25 | // delete whereInfo.schoolname; 26 | // 27 | // } 28 | 29 | const result = await University.findAndCountAll({ 30 | order: [['id', 'ASC']], // 正常升序 31 | where: whereInfo, 32 | offset: (page - 1) * pageSize, 33 | limit: pageSize 34 | }); 35 | const data = { 36 | result: result.rows, 37 | pagination: { 38 | page, 39 | pageSize, 40 | total: result.count 41 | } 42 | }; 43 | if (result.rows) { 44 | res.API(data); 45 | } 46 | } 47 | // module.exports = { 48 | // universityQuery 49 | // }; 50 | 51 | module.exports = universityQuery; 52 | -------------------------------------------------------------------------------- /src/models/user/User.js: -------------------------------------------------------------------------------- 1 | const UserORM = require('../../entity/userOrm'); 2 | async function query(req, res) { 3 | const data = await UserORM.findOne({ 4 | where: { id: req.query.id } 5 | }); 6 | res.API(data); 7 | } 8 | 9 | module.exports = query; 10 | -------------------------------------------------------------------------------- /src/models/we-app/WXBizDataCrypt.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto'); 2 | class WXBizDataCrypt { 3 | constructor(appId, sessionKey) { 4 | this.appId = appId; 5 | this.sessionKey = sessionKey; 6 | } 7 | decryptData(encryptedData, iv) { 8 | let decoded = ''; 9 | // base64 decode 10 | let sessionKey = Buffer.from(this.sessionKey, 'base64'); 11 | encryptedData = Buffer.from(encryptedData, 'base64'); 12 | iv = Buffer.from(iv, 'base64'); 13 | 14 | try { 15 | // 解密 16 | let decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv); 17 | // 设置自动 padding 为 true,删除填充补位 18 | decipher.setAutoPadding(true); 19 | decoded = decipher.update(encryptedData, 'binary', 'utf8'); 20 | decoded += decipher.final('utf8'); 21 | decoded = JSON.parse(decoded); 22 | } catch (err) { 23 | throw new Error('Illegal Buffer', err); 24 | } 25 | 26 | if (decoded.watermark.appid !== this.appId) { 27 | throw new Error('Illegal Buffer'); 28 | } 29 | 30 | return decoded; 31 | } 32 | } 33 | // function WXBizDataCrypt(appId, sessionKey) { 34 | // this.appId = appId; 35 | // this.sessionKey = sessionKey; 36 | // } 37 | 38 | // WXBizDataCrypt.prototype.decryptData = function (encryptedData, iv) { 39 | 40 | 41 | 42 | 43 | // let decoded = ''; 44 | // // base64 decode 45 | // let sessionKey = Buffer.from(this.sessionKey, 'base64'); 46 | // encryptedData = Buffer.from(encryptedData, 'base64'); 47 | // iv = Buffer.from(iv, 'base64'); 48 | // 49 | // try { 50 | // // 解密 51 | // let decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv); 52 | // // 设置自动 padding 为 true,删除填充补位 53 | // decipher.setAutoPadding(true); 54 | // decoded = decipher.update(encryptedData, 'binary', 'utf8'); 55 | // decoded += decipher.final('utf8'); 56 | // decoded = JSON.parse(decoded); 57 | // } catch (err) { 58 | // throw new Error('Illegal Buffer', err); 59 | // } 60 | // 61 | // if (decoded.watermark.appid !== this.appId) { 62 | // throw new Error('Illegal Buffer'); 63 | // } 64 | // 65 | // return decoded; 66 | // }; 67 | 68 | module.exports = WXBizDataCrypt; 69 | -------------------------------------------------------------------------------- /src/models/we-app/wx-login.js: -------------------------------------------------------------------------------- 1 | const wxUser = require('../../entity/weAppOrm'); 2 | const WXBizDataCrypt = require('./WXBizDataCrypt'); 3 | 4 | /** 5 | * 1.获取用户openid 6 | * 2.根据用户id查询 用户信息 7 | * 3.如果没有查询到、通过获取解密数据、将数据保存数据库、返回数据 8 | */ 9 | async function getUserProfile(req, res, sessionKey, openid) { 10 | const appId = process.env.appid; 11 | const encryptedData = req.query.encryptedData; 12 | const iv = req.query.iv; 13 | const pc = await new WXBizDataCrypt(appId, sessionKey); 14 | const data = pc.decryptData(encryptedData, iv); 15 | data.openid = openid; 16 | createDB(data); 17 | return res.API(data); 18 | } 19 | 20 | async function queryUser(req, res, sessionKey, openid) { 21 | console.log(sessionKey, openid); 22 | try { 23 | const data = await wxUser.findOne({ 24 | where: { 25 | openid: openid 26 | } 27 | }); 28 | if (data) { 29 | res.API(data); 30 | } else { 31 | await getUserProfile(req, res, sessionKey, openid); 32 | } 33 | } catch (e) { 34 | console.log(e); 35 | } 36 | } 37 | function createDB(data) { 38 | return wxUser.create(data).catch(err => { 39 | console.log(err); 40 | }); 41 | } 42 | 43 | module.exports = queryUser; 44 | -------------------------------------------------------------------------------- /src/routers.js: -------------------------------------------------------------------------------- 1 | const arrRoutes = [ 2 | { 3 | path: '/', 4 | component: './controller/web/index' 5 | }, 6 | { 7 | path: '/api/bank-card', 8 | component: './controller/bank-card' 9 | }, 10 | { 11 | path: '/api/jwt', 12 | component: './controller/jwt' 13 | }, 14 | { 15 | path: '/api/wx-login', 16 | component: './controller/we-app/getUserInfo' 17 | }, 18 | { 19 | path: '/api/icon-list', 20 | component: './controller/icon-list' 21 | }, 22 | { 23 | path: '/api/idiom', 24 | component: './controller/idiom' 25 | }, 26 | { 27 | path: '/api/star-detail', 28 | component: './controller/star-detail/star-detail' 29 | }, 30 | { 31 | path: '/api/juhe-star-detail', 32 | component: './controller/star-detail/juhe-star-detail' 33 | }, 34 | { 35 | path: '/api/idcard-info', 36 | component: './controller/idcard-info' 37 | }, 38 | { 39 | path: '/api/lunar-calendar', 40 | component: './controller/lunar-calendar' 41 | }, 42 | { 43 | path: '/api/university', 44 | component: './controller/university/university' 45 | }, 46 | { 47 | path: '/api/history-today', 48 | component: './controller/history-today/history-today' 49 | }, 50 | { 51 | path: '/api/history-today-detail', 52 | component: './controller/history-today/history-today-detail' 53 | }, 54 | { 55 | path: '/api/down-img', 56 | component: './controller/down-img' 57 | }, 58 | { 59 | path: '/api/tang300', 60 | component: './controller/tang300' 61 | }, 62 | { 63 | path: '/api/music/new-songs', 64 | component: './controller/music/new-songs' 65 | }, 66 | { 67 | path: '/api/music/rank-list', 68 | component: './controller/music/rank-list' 69 | }, 70 | { 71 | path: '/api/rank-list-info', 72 | component: './controller/music/rank-list-info' 73 | }, 74 | { 75 | path: '/api/music/search', 76 | component: './controller/music/search' 77 | }, 78 | { 79 | path: '/api/music/plist', 80 | component: './controller/music/plist' 81 | }, 82 | { 83 | path: '/api/music/song-lrc', 84 | component: './controller/music/song-lrc' 85 | }, 86 | { 87 | path: '/api/music/plist-songs', 88 | component: './controller/music/plist-songs' 89 | }, 90 | { 91 | path: '/api/music/song-info', 92 | component: './controller/music/song-info' 93 | }, 94 | { 95 | path: '/api/music/singer-info', 96 | component: './controller/music/singer-info' 97 | }, 98 | { 99 | path: '/api/music/singer-list', 100 | component: './controller/music/singer-list' 101 | }, 102 | { 103 | path: '/api/music/singer-classify', 104 | component: './controller/music/singer-classify' 105 | }, 106 | { 107 | path: '/api/job/lagou-positionsearch', 108 | component: './controller/job/lagou-positionsearch' 109 | }, 110 | { 111 | path: '/api/job/position-info', 112 | component: './controller/job/position-info' 113 | }, 114 | { 115 | path: '/api/163/joke', 116 | component: './controller/163/joke' 117 | }, 118 | { 119 | path: '/api/163/video-list', 120 | component: './controller/163/video-list' 121 | }, 122 | { 123 | path: '/api/163/video-detail', 124 | component: './controller/163/video-detail' 125 | }, 126 | { 127 | path: '/api/tt-news-list', 128 | component: './controller/163/tt-news-list' 129 | }, 130 | { 131 | path: '/api/tt-news-detail', 132 | component: './controller/163/tt-news-detail' 133 | }, 134 | { 135 | path: '*', 136 | component: './controller/web/404' 137 | } 138 | ]; 139 | module.exports = arrRoutes; 140 | -------------------------------------------------------------------------------- /src/utils/api-sign.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 1.时间戳拦截限制 3 | * 2.签名验证 4 | */ 5 | const md5 = require('md5'); 6 | const log4js = require('./log4'); 7 | const errLog = log4js.getLogger('err'); 8 | const ApiSign = function (data) { 9 | // 如果配置项不需要签名 10 | if (process.env.ApiSign === 'false') return true; 11 | // 签名判断逻辑 12 | const time = new Date().getTime() - data.timestamp; 13 | if (time > 120000) return false; 14 | const signStr = md5(`appKey=${process.env.appKey}timeStamp=${data.timestamp}`); 15 | if (signStr !== data.sign) { 16 | errLog.error( 17 | `签名报文:appKey=${process.env.appKey}timeStamp=${data.timestamp},signStr=${signStr}` 18 | ); 19 | return false; 20 | } 21 | return true; 22 | }; 23 | 24 | module.exports = ApiSign; 25 | -------------------------------------------------------------------------------- /src/utils/crawler-request.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | const Iconv = require('iconv-lite'); 3 | const cheerio = require('cheerio'); 4 | const log4js = require('./log4.js'); 5 | const errLog = log4js.getLogger('err'); 6 | 7 | /** 8 | * 页面爬虫方法 9 | * @param url 10 | * @param headers 11 | * @param req 12 | * @param res 13 | * @returns {Promise} 14 | */ 15 | function crawlerRequest({ url, headers, req, res }) { 16 | return new Promise((resolve, reject) => { 17 | let defaultHeaders = { 18 | Connection: 'keep-alive', 19 | 'User-Agent': 20 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' 21 | }; 22 | request( 23 | { 24 | url: url, 25 | encoding: null, 26 | headers: Object.assign({}, defaultHeaders, headers) 27 | }, 28 | function (error, response, body) { 29 | if (response && response.statusCode === 200) { 30 | body = Iconv.decode(body, 'utf-8'); 31 | let $ = cheerio.load(body); 32 | resolve($); 33 | } else { 34 | errLog.error(url, headers, req, res); 35 | reject(error); 36 | } 37 | } 38 | ); 39 | }); 40 | } 41 | module.exports = crawlerRequest; 42 | -------------------------------------------------------------------------------- /src/utils/jwt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description 3 | * @param {type} 4 | * @date: 2022/4/1 5 | * @return: {} 6 | */ 7 | const jwt = require('jsonwebtoken'); 8 | const jwtSecret = process.env.jwtSecret; 9 | class Token { 10 | static encrypt(data, time) { 11 | // data加密数据,time过期时间 12 | return jwt.sign(data, jwtSecret, { expiresIn: time }); 13 | } 14 | static decrypt(token) { 15 | try { 16 | let data = jwt.verify(token, jwtSecret); 17 | return { 18 | token: true, 19 | id: data.id 20 | }; 21 | } catch (e) { 22 | return { 23 | token: false, 24 | data: e 25 | }; 26 | } 27 | } 28 | } 29 | module.exports = Token; 30 | -------------------------------------------------------------------------------- /src/utils/log4.js: -------------------------------------------------------------------------------- 1 | const log4js = require('log4js'); 2 | log4js.configure({ 3 | replaceConsole: true, 4 | // pm2: true, 5 | appenders: { 6 | stdout: { 7 | //控制台输出 8 | type: 'console' 9 | }, 10 | req: { 11 | //请求转发日志 12 | type: 'dateFile', //指定日志文件按时间打印 13 | filename: 'logs/reqlog/req', //指定输出文件路径 14 | pattern: 'yyyy-MM-dd.log', 15 | alwaysIncludePattern: true 16 | }, 17 | err: { 18 | //错误日志 19 | type: 'dateFile', 20 | filename: 'logs/errlog/err', 21 | pattern: 'yyyy-MM-dd.log', 22 | alwaysIncludePattern: true 23 | }, 24 | oth: { 25 | //其他日志 26 | type: 'dateFile', 27 | filename: 'logs/othlog/oth', 28 | pattern: 'yyyy-MM-dd.log', 29 | alwaysIncludePattern: true 30 | } 31 | }, 32 | categories: { 33 | //appenders:采用的appender,取appenders项,level:设置级别 34 | default: { 35 | appenders: ['stdout', 'req'], 36 | level: 'debug' 37 | }, 38 | err: { 39 | appenders: ['stdout', 'err'], 40 | level: 'error' 41 | } 42 | } 43 | }); 44 | 45 | exports.getLogger = function (name) { 46 | //name取categories项 47 | return log4js.getLogger(name || 'default'); 48 | }; 49 | //用来与express结合 50 | exports.useLogger = function (app, logger) { 51 | app.use( 52 | log4js.connectLogger(logger || log4js.getLogger('default'), { 53 | //自定义输出格式 54 | format: 55 | '[:remote-addr :method :url :status :response-timems][:referrer HTTP/:http-version :user-agent]' 56 | }) 57 | ); 58 | }; 59 | 60 | // 打印debug级别的日志信息: 61 | // logger.info('req的值是:' + req); 62 | // 打印error级别的日志信息: 63 | // errLog.error(e); 64 | -------------------------------------------------------------------------------- /src/utils/request.js: -------------------------------------------------------------------------------- 1 | let http = require('http'); 2 | const querystring = require('query-string'); 3 | 4 | /** 5 | * Request 模拟请求封装 6 | */ 7 | class Request { 8 | static PromiseData(options) { 9 | return new Promise(function (resolve, reject) { 10 | let body = ''; 11 | let getReq = http.request(options, function (response) { 12 | response.on('data', function (chunk) { 13 | body += chunk; 14 | }); 15 | response.on('end', () => { 16 | resolve(body); 17 | }); 18 | response.on('error', err => { 19 | reject(err); 20 | }); 21 | }); 22 | getReq.end(); 23 | }); 24 | } 25 | static httpGet(config) { 26 | const header = config.headers || {}; 27 | let options = { 28 | host: config.host, 29 | port: 80, 30 | path: config.path + querystring.stringify(config.data), 31 | method: 'GET', 32 | encoding: null, 33 | headers: { 34 | // 'Content-Type': 'application/json', 35 | 'User-Agent': 36 | 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36' 37 | } 38 | }; 39 | options.headers = Object.assign({}, options.headers, header); 40 | console.log(options); 41 | // 判断是否为https请求 42 | if (config.https) { 43 | http = require('https'); 44 | options.port = 443; 45 | } 46 | return this.PromiseData(options); 47 | } 48 | 49 | static ajaxGet(host, data, path, status) { 50 | console.log('===================HttpGet====================='); 51 | let options = { 52 | host: host, 53 | port: 80, 54 | path: path + querystring.stringify(data), 55 | method: 'GET', 56 | encoding: null, 57 | headers: { 58 | 'Content-Type': 'application/json', 59 | 'X-Requested-With': 'XMLHttpRequest', 60 | Connection: 'keep-alive', 61 | Accept: 'application/json, text/javascript, */*; q=0.01', 62 | 'User-Agent': 63 | 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36' 64 | } 65 | }; 66 | // 判断是否为https请求 67 | if (status) { 68 | http = require('https'); 69 | options.port = 443; 70 | } 71 | return this.PromiseData(options); 72 | } 73 | 74 | static httpMobileGet(host, data, path, status) { 75 | console.log('===================httpMobileGet====================='); 76 | let options = { 77 | host: host, 78 | port: 80, 79 | path: path + querystring.stringify(data), 80 | method: 'GET', 81 | encoding: null, 82 | headers: { 83 | 'Content-Type': 'application/json', 84 | 'User-Agent': 85 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4' 86 | } 87 | }; 88 | // 判断是否为https请求 89 | if (status) { 90 | http = require('https'); 91 | options.port = 443; 92 | } 93 | return this.PromiseData(options); 94 | } 95 | 96 | static httpPost({ host, data, path, status, headers = {} }) { 97 | console.log(headers); 98 | // data = querystring.stringify(data); 99 | console.log('---------httpPost---------------'); 100 | console.log(data); 101 | let options = { 102 | host: host, 103 | port: '80', 104 | path: path, 105 | formData: data, 106 | method: 'post', 107 | headers: Object.assign( 108 | { 109 | // 'Content-Type': 'application/x-www-form-urlencoded', 110 | 'User-Agent': 111 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36' 112 | // 'Content-Length': Buffer.byteLength(data) // 返回字符串实际占据的字节长度 113 | }, 114 | headers 115 | ) 116 | }; 117 | // 判断是否为https请求 118 | if (status) { 119 | http = require('https'); 120 | options.port = 443; 121 | } 122 | console.log(options); 123 | return this.PromiseData(options); 124 | } 125 | } 126 | 127 | module.exports = Request; 128 | -------------------------------------------------------------------------------- /src/utils/swaggerUI.js: -------------------------------------------------------------------------------- 1 | const expressJSDocSwagger = require('express-jsdoc-swagger'); 2 | 3 | const options = { 4 | info: { 5 | version: '1.0.0', 6 | title: 'v-tools-server接口文档', 7 | description: 8 | '基于node+express爬虫 API接口项目,包括全国高校信息、成语诗歌、星座运势、历史的今天、音乐数据接口、图片壁纸、搞笑视频、热点新闻资讯 详情接口数据' 9 | }, 10 | security: { 11 | BasicAuth: { 12 | type: 'http', 13 | scheme: 'basic' 14 | } 15 | }, 16 | filesPattern: ['../controller/**/*.js'], // Glob pattern to find your jsdoc files 17 | swaggerUIPath: '/api-docs', // SwaggerUI will be render in this url. Default: '/api-docs' 18 | baseDir: __dirname 19 | }; 20 | 21 | module.exports = function (app) { 22 | expressJSDocSwagger(app)(options); 23 | }; 24 | -------------------------------------------------------------------------------- /views/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 404 6 | 7 | 24 | 25 | 26 | 27 | 28 |
29 |

<%=title %>

30 |

你可能迷路了

31 |
32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | v-tools server 6 | 7 | 24 | Document 25 | 26 | 27 | 28 |
29 |

<%=title %>

30 |

基于node+express爬虫 API接口项目,包括全国高校信息、成语诗歌、星座运势、历史的今天、音乐数据接口、图片壁纸、搞笑视频、热点新闻资讯 详情接口数据

31 |

接口可用于研究需求、项目学习,部分接口来源于网络爬虫,请勿用于商业推广以及其他获利用途,如有版权问题请告知删除!

32 |

API接口列表

33 |
34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /views/web/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 404 6 | 7 | 24 | 25 | 26 | 27 | 28 |
29 |

<%=title %>

30 |

你可能迷路了

31 |
32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /webstorm.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | function resolve(dir) { 4 | return path.join(__dirname, '.', dir); 5 | } 6 | 7 | module.exports = { 8 | context: path.join(__dirname, './'), 9 | resolve: { 10 | extensions: ['.js'], 11 | alias: { 12 | '@': resolve(path.join(__dirname, '')), 13 | $s: resolve(path.join(__dirname, 'server')) 14 | } 15 | } 16 | }; 17 | --------------------------------------------------------------------------------