From 9e2b6277ec20d6589659a90f1079868cb7f847a4 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 2 Aug 2022 09:20:08 +0800 Subject: [PATCH] =?UTF-8?q?api=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/app/lib/utils/push.js | 62 +++++++++++++++++++ code/VideoAccess-VCMP/api/config.js | 35 ++++++++++- code/VideoAccess-VCMP/api/package.json | 2 + code/VideoAccess-VCMP/web/package.json | 2 +- 4 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 code/VideoAccess-VCMP/api/app/lib/utils/push.js diff --git a/code/VideoAccess-VCMP/api/app/lib/utils/push.js b/code/VideoAccess-VCMP/api/app/lib/utils/push.js new file mode 100644 index 0000000..a46dc9e --- /dev/null +++ b/code/VideoAccess-VCMP/api/app/lib/utils/push.js @@ -0,0 +1,62 @@ +'use strict'; + +const moment = require('moment') +const Core = require('@alicloud/pop-core'); +const nodemailer = require('nodemailer') + +module.exports = function (app, opts) { + const pushBySms = async ({ phone = [] } = {}) => { + try { + if (phone.length) { + const client = new Core({ + accessKeyId: opts.sms.accessKey, + accessKeySecret: opts.sms.accessSecret, + endpoint: 'http://dysmsapi.aliyuncs.com',//固定 + apiVersion: '2017-05-25'//固定 + }); + const SendSmsRes = await client.request('SendSms', { + "PhoneNumbers": `${phone.join(',')}`,//接收短信的手机号码。 + "SignName": "安心云",//短信签名名称。必须是已添加、并通过审核的短信签名。 + "TemplateCode": "SMS_216403225",//短信模板ID。必须是已添加、并通过审核的短信签名;且发送国际/港澳台消息时,请使用国际/港澳台短信模版。 + "TemplateParam": `{"code":${code}}`//短信模板变量对应的实际值,JSON格式。 + }, { + method: 'POST' + }); + return SendSmsRes + } + } catch (error) { + throw error + } + } + + const pushByEmail = async () => { + try { + let transporter = nodemailer.createTransport({ + host: opts.email.host, + port: opts.email.port, + secure: true, + auth: { + user: opts.email.sender.address, + pass: opts.email.sender.password, + } + }); + + // send mail with defined transport object + await transporter.sendMail({ + from: 'grazing-stars@qq.com', // sender address + to: email, // list of receivers 逗号分隔字符串 + subject: title, // Subject line + text: text, // plain text body + html: html, // html body + attachments: attachments + }); + } catch (error) { + throw error + } + } + + return { + pushByEmail, + pushBySms, + } +} \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/config.js b/code/VideoAccess-VCMP/api/config.js index 5bcf54d..013b890 100644 --- a/code/VideoAccess-VCMP/api/config.js +++ b/code/VideoAccess-VCMP/api/config.js @@ -35,20 +35,29 @@ const flags = args.parse(process.argv); const IOT_VIDEO_ACCESS_DB = process.env.IOT_VIDEO_ACCESS_DB || flags.pg; const IOT_VIDEO_ACCESS_LOCAL_SVR_ORIGIN = process.env.IOT_VIDEO_ACCESS_LOCAL_SVR_ORIGIN || flags.fileHost; +// Redis 参数 const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口 const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码 +// 鉴权 api const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi; +// 安心云api const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl; +// 高德地图的参数 const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3'; const GOD_KEY = process.env.GOD_KEY || flags.godKey; +// 萤石服务的地址 const YINGSHI_URL = process.env.YINGSHI_URL || flags.yingshiUrl || 'https://open.ys7.com/api'; -const MQTT_VIDEO_SERVER = process.env.MQTT_VIDEO_SERVER || flags.mqttVideoServer; +// 视频后台服务的地址 const IOT_VIDEO_SERVER_URL = process.env.IOT_VIDEO_SERVER_URL || flags.iotVideoServerUrl +// 视频后台 mqtt 信息推送地址 +const MQTT_VIDEO_SERVER = process.env.MQTT_VIDEO_SERVER || flags.mqttVideoServer; + +// 几种国标摄像头播放地址前缀 const CAMERA_PLAY_WS_HOST = process.env.CAMERA_PLAY_WS_HOST || flags.cameraPlayWsHost; const CAMERA_PLAY_HTTP_FLV_HOST = process.env.CAMERA_PLAY_HTTP_FLV_HOST || flags.cameraPlayHttpFlvHost; const CAMERA_PLAY_HLS_HOST = process.env.CAMERA_PLAY_HLS_HOST || flags.cameraPlayHlsHost; @@ -100,6 +109,30 @@ const product = { rtmp: CAMERA_PLAY_RTMP_HOST, rtsp: CAMERA_PLAY_RTSP_HOST, }, + sms: { + ///阿里云-安心云 + accessKey: 'LTAI5tAFdjz7j38aNF2C9Qe8', + accessSecret: '1trYkmiqfBtvZL6BxkNH2uQcQQPs0S' + }, + email: { + // enabled: true, + // host: 'smtp.exmail.qq.com', + // port: 465, + // sender: { + // name: '知物云', + // address: 'no-reply@zhiwucloud.com', + // password: 'Zwy123456_' + // }, + + // enabled: true, + // host: 'smtp.exmail.qq.com', + // port: 465, + // sender: { + // name: '知物云', + // address: 'no-reply@zhiwucloud.com', + // password: 'Zwy123456_' + // } + }, pssaRequest: [ {// name 会作为一个 request 出现在 ctx.app.fs name: 'authRequest', diff --git a/code/VideoAccess-VCMP/api/package.json b/code/VideoAccess-VCMP/api/package.json index 8dcbcd7..7eafc29 100644 --- a/code/VideoAccess-VCMP/api/package.json +++ b/code/VideoAccess-VCMP/api/package.json @@ -13,6 +13,7 @@ "license": "MIT", "repository": {}, "dependencies": { + "@alicloud/pop-core": "^1.7.12", "@fs/attachment": "^1.0.0", "args": "^3.0.7", "better-xlsx": "^0.7.6", @@ -25,6 +26,7 @@ "moment": "^2.24.0", "mqtt": "^4.3.7", "node-schedule": "^2.1.0", + "nodemailer": "^6.7.7", "path": "^0.12.7", "path-to-regexp": "^3.0.0", "pg": "^7.9.0", diff --git a/code/VideoAccess-VCMP/web/package.json b/code/VideoAccess-VCMP/web/package.json index 224ad8d..92c61fc 100644 --- a/code/VideoAccess-VCMP/web/package.json +++ b/code/VideoAccess-VCMP/web/package.json @@ -7,7 +7,7 @@ "test": "mocha", "start-vite": "cross-env NODE_ENV=developmentVite npm run start-params", "start": "cross-env NODE_ENV=development npm run start-params", - "start-params": "node server -p 5000 -u http://10.8.30.29:4000 --apiVcmpUrl http://localhost:4000 --apiAuthUrl http://10.8.30.29:4200 --apiAnxinyunUrl http://10.8.30.29:4100 --iotAuthWeb http://localhost:5200 --iotVideoServer ws://221.230.55.27:8081", + "start-params": "node server -p 5000 -u http://10.8.30.24:4000 --apiVcmpUrl http://localhost:4000 --apiAuthUrl http://10.8.30.24:4200 --apiAnxinyunUrl http://10.8.30.24:4100 --iotAuthWeb http://localhost:5200 --iotVideoServer ws://221.230.55.27:8081", "deploy": "export NODE_ENV=production&& npm run build && node server", "build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js", "build": "export NODE_ENV=production&&webpack --config webpack.config.prod.js"