liujiangyong
10 months ago
4 changed files with 94 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const path = require('path'); |
||||
|
const fs = require('fs'); |
||||
|
|
||||
|
module.exports = async function (app, opts) { |
||||
|
fs.readdirSync(__dirname).forEach((filename) => { |
||||
|
if (!['index.js'].some(f => filename == f)) { |
||||
|
const utils = require(`./${filename}`)(app, opts) |
||||
|
console.log(`载入 ${filename} 工具集成功`); |
||||
|
app.fs.utils = { |
||||
|
...app.fs.utils, |
||||
|
...utils, |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}; |
@ -0,0 +1,36 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const moment = require('moment') |
||||
|
const Core = require('@alicloud/pop-core'); |
||||
|
|
||||
|
|
||||
|
module.exports = function (app, opts) { |
||||
|
const pushBySms = async ({ phone = [], templateCode, templateParam } = {}) => { |
||||
|
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": templateCode,//短信模板ID。必须是已添加、并通过审核的短信签名;且发送国际/港澳台消息时,请使用国际/港澳台短信模版。
|
||||
|
"TemplateParam": JSON.stringify(templateParam)//短信模板变量对应的实际值,JSON格式。
|
||||
|
}, { |
||||
|
method: 'POST' |
||||
|
}); |
||||
|
return SendSmsRes |
||||
|
} |
||||
|
} catch (error) { |
||||
|
throw error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
|
||||
|
pushBySms, |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue