巴林闲侠
2 years ago
4 changed files with 99 additions and 2 deletions
@ -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, |
|||
} |
|||
} |
Loading…
Reference in new issue