Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | 3x 3x 3x 3x | const aliyunSMS = require('../../../libs/aliyun-sms');
const mail = require('../../../libs/mail');
/**
* @api {post} common/sendEmail 发送邮件
* @apiDescription 作者:samy
*
* @apiGroup common
* @apiName sendEmail
* @apiSampleRequest common/sendEmail
* @apiPermission user
*
* @apiParam {String} to 收件人邮箱
* @apiParam {String} subject 标题
* @apiParam {String} content 内容
*
* @apiUse Header
* @apiUse Response
*/
exports.sendEmail = async(req, res, next) => {
let body = req.body
try {
let msg
if (!body.to) {
msg = '收件人不能为空'
}
if (!body.subject) {
msg = '标题不能为空'
}
if (!body.content) {
msg = '内容不能为空'
}
if (msg) {
return res.resMid.resBody(res, 422, msg)
}
let doc = {
to: body.to,
subject: body.subject,
content: body.content,
desc: body.subject,
};
await mail.sendMail(doc)
res.resMid.resBody(res, '', '发送成功')
} catch (err) {
res.throw(err)
}
}
/**
* @api {post} common/sendMessage 发送短信
* @apiDescription 作者:samy
*
* @apiGroup common
* @apiName sendMessage
* @apiSampleRequest common/sendMessage
* @apiPermission user
*
* @apiParam {String} phone 手机号码
* @apiParam {String} content 内容
*
* @apiUse Header
* @apiUse Response
*/
exports.sendMessage = async(req, res, next) => {
let body = req.body
try {
let msg
let phone = body.phone
let content = body.content
if (!phone) {
msg = '手机号码不能为空'
}
if (!content) {
msg = '内容不能为空'
}
if (msg) {
return res.resMid.resBody(res, 422, msg)
}
await aliyunSMS.messageNotify(phone, content)
res.resMid.resBody(res, '', '发送成功')
} catch (err) {
res.throw(err)
}
} |