From 0a573538efcb5eb0ac9be4d342d21a5a6c2a5f79 Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Wed, 9 Aug 2023 11:33:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E6=8C=87=E6=B4=BE=E8=B4=A3?= =?UTF-8?q?=E4=BB=BB=E4=BA=BA=E6=8F=90=E9=86=92=2090%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.vscode/launch.json | 4 ++- .../data/anspectionNotificationPhone.js | 28 ++++++++++++++- api/app/lib/routes/data/index.js | 3 ++ api/config.js | 16 +++++++-- api/package.json | 3 +- api/utils/push.js | 35 +++++++++++++++++++ .../sections/fillion/actions/appointTask.js | 11 ++++++ .../components/feedback/nominateModalcopy.js | 5 ++- web/client/src/utils/webapi.js | 5 +-- 9 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 api/utils/push.js diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 118cef79..d1954ea4 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -27,9 +27,11 @@ // "--yingshiKey d0704fb9d5d14a6682c1c1d592c12512", // "--yingshiSecret 93d023269495b86be62cdfdcf34a6cd1", - "--yingshiKey 5d16a667e1c2423d9d0d634f781810b4", "--yingshiSecret 0cc4e1ec4e6a53ea3dabeb09cd5f468b", + + "--smsKey LTAI5tAFdjz7j38aNF2C9Qe8", + "--smsSecret 1trYkmiqfBtvZL6BxkNH2uQcQQPs0S", ] }, { diff --git a/api/app/lib/controllers/data/anspectionNotificationPhone.js b/api/app/lib/controllers/data/anspectionNotificationPhone.js index 079f37bc..3490e955 100644 --- a/api/app/lib/controllers/data/anspectionNotificationPhone.js +++ b/api/app/lib/controllers/data/anspectionNotificationPhone.js @@ -1,5 +1,6 @@ 'use strict'; const moment = require('moment') +const { pushBySms } = require('../../../../utils/push.js'); async function getAnspectionNotificationPhone(ctx) { try { @@ -47,7 +48,32 @@ async function addAnspectionNotificationPhone(ctx) { } } +function pushAppointSMS(opts) { + return async function (ctx) { + try { + const { phone = [] } = ctx.request.body + if (phone.length) { + await pushBySms({ + accessKey: opts.sms.accessKey, + accessSecret: opts.sms.accessSecret, + phone: phone, + templateCode: 'SMS_273640525', + }) + } else { + throw '缺少请求参数'; + } + + ctx.status = 204; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : '短信推送失败' + } + } + } +} module.exports = { - getAnspectionNotificationPhone, addAnspectionNotificationPhone + getAnspectionNotificationPhone, addAnspectionNotificationPhone, pushAppointSMS }; \ No newline at end of file diff --git a/api/app/lib/routes/data/index.js b/api/app/lib/routes/data/index.js index 5c2bde4a..522b1cc8 100644 --- a/api/app/lib/routes/data/index.js +++ b/api/app/lib/routes/data/index.js @@ -214,4 +214,7 @@ module.exports = function (app, router, opts) { //添加 app.fs.api.logAttr['POST/anspection/notification/phone'] = { content: '导入道路数据', visible: true }; router.post('/anspection/notification/phone', anspectionNotificationPhone.addAnspectionNotificationPhone); + + app.fs.api.logAttr['POST/pushAppointSMS'] = { content: '推送指派短信', visible: true }; + router.post('/pushAppointSMS', anspectionNotificationPhone.pushAppointSMS(opts)); }; diff --git a/api/config.js b/api/config.js index bf4f6e63..96b1ae99 100644 --- a/api/config.js +++ b/api/config.js @@ -19,6 +19,9 @@ args.option('qndmn', 'qiniuDomain'); // args.option('yingshiKey', '萤石 KEY') args.option('yingshiSecret', '萤石 SECRET') +// 短信-阿里云 +args.option('smsKey', 'smsAccessKey'); +args.option('smsSecret', 'smsSecretKey'); const flags = args.parse(process.argv); @@ -32,6 +35,10 @@ const QINIU_SK = process.env.ANXINCLOUD_QINIU_SECRETKEY || flags.qnsk; // const YINGSHI_KEY = process.env.YINGSHI_KEY || flags.yingshiKey; const YINGSHI_SECRET = process.env.YINGSHI_SECRET || flags.yingshiSecret; + +const SMS_KEY = process.env.SMS_KEY || flags.smsKey; +const SMS_SECRET = process.env.SMS_SECRET || flags.smsSecret; + // 萤石服务的地址 const YINGSHI_URL = process.env.YINGSHI_URL || flags.yingshiUrl || 'https://open.ys7.com/api'; // 智调系统基础数据接口 @@ -39,7 +46,8 @@ const ZHIDIAO_URL = process.env.ZHIDIAO_URL || flags.zhidiaoUrl || 'http://61.13 if ( !FS_UNIAPP_DB || - !YINGSHI_KEY || !YINGSHI_SECRET) { + !YINGSHI_KEY || !YINGSHI_SECRET || + !SMS_KEY || !SMS_SECRET) { console.log('缺少启动参数,异常退出'); args.showHelp(); process.exit(-1); @@ -82,7 +90,11 @@ const product = { root: ZHIDIAO_URL, params: {} } - ] + ], + sms: { + accessKey: SMS_KEY, + accessSecret: SMS_SECRET + }, } } ], diff --git a/api/package.json b/api/package.json index 4e66560a..747055b6 100644 --- a/api/package.json +++ b/api/package.json @@ -5,7 +5,7 @@ "main": "server.js", "scripts": { "test": "set DEBUG=true&&\"node_modules/.bin/mocha\" --harmony --reporter spec app/test/*.test.js", - "start": "set NODE_ENV=development&&node server -p 4001 -g postgres://postgres://postgres:123@10.8.30.32:5432/highways4good -f http://localhost:14000 --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-highways4good --qndmn http://rfkimpwbb.hn-bkt.clouddn.com", + "start": "set NODE_ENV=development&&node server -p 4001 -g postgres://postgres://postgres:123@10.8.30.32:5432/highways4good -f http://localhost:14000 --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-highways4good --qndmn http://rfkimpwbb.hn-bkt.clouddn.com --smsKey LTAI5tAFdjz7j38aNF2C9Qe8 --smsSecret 1trYkmiqfBtvZL6BxkNH2uQcQQPs0S", "start:linux": "export NODE_ENV=development&&node server -p 4001 -g postgres://FashionAdmin:123456@10.8.30.39:5432/pm1", "automate": "sequelize-automate -c sequelize-automate.config.js" }, @@ -13,6 +13,7 @@ "license": "MIT", "repository": {}, "dependencies": { + "@alicloud/pop-core": "^1.7.12", "@fs/attachment": "^1.0.0", "archiver": "3.0.0", "args": "^3.0.7", diff --git a/api/utils/push.js b/api/utils/push.js new file mode 100644 index 00000000..723d3661 --- /dev/null +++ b/api/utils/push.js @@ -0,0 +1,35 @@ +'use strict'; + +const Core = require('@alicloud/pop-core'); + +const pushBySms = async ({ phone = [], templateCode, accessKey, accessSecret } = {}) => { + try { + if (phone.length) { + const client = new Core({ + accessKeyId: accessKey, + accessKeySecret: accessSecret, + endpoint: 'http://dysmsapi.aliyuncs.com', // 固定 + apiVersion: '2017-05-25' // 固定 + }); + const SendSmsRes = await client.request('SendSms', { + "PhoneNumbers": phone.join(','), // 接收短信的手机号码。 + "SignName": "隧道智慧运维助手", // 短信签名名称。必须是已添加、并通过审核的短信签名。 + "TemplateCode": templateCode, // 短信模板ID。必须是已添加、并通过审核的短信签名;且发送国际/港澳台消息时,请使用国际/港澳台短信模版。 + "TemplateParam": JSON.stringify({ + struction: 'test', + point: 'test', + number: 1 + }) // 短信模板变量对应的实际值,JSON格式。 + }, { + method: 'POST' + }); + return SendSmsRes + } + } catch (error) { + throw error + } +} + +module.exports = { + pushBySms, +} \ No newline at end of file diff --git a/web/client/src/sections/fillion/actions/appointTask.js b/web/client/src/sections/fillion/actions/appointTask.js index 17ab84f5..4b359c3e 100644 --- a/web/client/src/sections/fillion/actions/appointTask.js +++ b/web/client/src/sections/fillion/actions/appointTask.js @@ -10,4 +10,15 @@ export function appointTask(query) { url: ApiTable.appointTask, msg: { option: '指派任务' }, }); +} + +export function pushAppointSMS(data) { + return dispatch => basicAction({ + type: 'post', + data, + dispatch: dispatch, + actionType: 'PUSH_APPOINT_SMS', + url: ApiTable.pushAppointSMS, + msg: { option: '发送指派信息' }, + }); } \ No newline at end of file diff --git a/web/client/src/sections/fillion/components/feedback/nominateModalcopy.js b/web/client/src/sections/fillion/components/feedback/nominateModalcopy.js index 0af1d4d7..7d3381a2 100644 --- a/web/client/src/sections/fillion/components/feedback/nominateModalcopy.js +++ b/web/client/src/sections/fillion/components/feedback/nominateModalcopy.js @@ -4,7 +4,7 @@ import { connect } from 'react-redux'; import { Spin, TreeSelect, Modal, Form, Select, Input } from 'antd'; import ProForm, { ProFormText, ModalForm, ProFormSwitch, ProFormTreeSelect, ProFormSelect } from '@ant-design/pro-form'; import { getDepUser } from '../../../organization/actions/user' -import { appointTask } from '../../actions/appointTask' +import { appointTask, pushAppointSMS } from '../../actions/appointTask' import moment from 'moment' import { v4 as uuidv4 } from 'uuid'; @@ -45,8 +45,7 @@ const NominateModal = (props) => { setDepUsers([]) form.resetFields() // const phone = depUsers.find(u => u.value == values.nameId)?.phone; - // console.log(phone, 'phone') - // dispatch(pushAppointSMS({ phone, info: 'info...' })) + // dispatch(pushAppointSMS({ phone: [phone] })) } }) }) diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index 3d4e17fb..bd8533c0 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -310,8 +310,9 @@ export const ApiTable = { modifyRoadadministration:'editRoadadministration/:id', delRoadadministration:'delRoadadministration/:id', addRoadadministration:'/addRoadadministration', - getRoadadministration:'/getRoadadministration' - + getRoadadministration:'/getRoadadministration', + // 发送短信 + pushAppointSMS: 'pushAppointSMS', };