@axolo/egg-aliyun-dysms
v0.2.0
Published
Aliyun Dysms plugin for Egg.js.
Downloads
20
Maintainers
Readme
egg-aliyun-dysms
Aliyun Dysms plugin for Egg.js.
Install
npm i @axolo/egg-aliyun-dysms --save
Usage
// {app_root}/config/plugin.js
exports.aliyunDysms = {
enable: true,
package: '@axolo/egg-aliyun-dysms',
};
Configuration
Config Aliyun
to define Aliyun OpenAPI SDK.
// {app_root}/config/config.default.js
exports.aliyunDysms = {
default: {
Aliyun: require('@alicloud/pop-core'),
endpoint: 'https://dysmsapi.aliyuncs.com',
apiVersion: '2017-05-25',
accessKeyId: 'ACCESS_KEY_ID',
accessKeySecret: 'ACCESS_KEY_SECRET',
},
clients: {
auth: { // client
SendSms: { // action
params: { // action params
RegionId: 'cn-hangzhou',
SignName: 'SIGN_NAME',
TemplateCode: 'TEMPLATE_CODE',
},
options: { // request options
method: 'POST',
},
},
},
},
};
Example
'use strict';
const Service = require('egg').Service;
class SmsService extends Service {
async authCode(phone, code) {
const { app } = this;
const sms = app.aliyunDysms.get('auth');
const action = 'SendSms';
const config = sms.config[action];
const PhoneNumbers = phone;
const TemplateParam = JSON.stringify({ code });
const sendParams = { ...config.params, PhoneNumbers, TemplateParam };
const sendOptions = { ...config.options };
const send = await sms.request(action, sendParams, sendOptions);
return send;
}
}
module.exports = SmsService;
see config/config.default.js for more detail.
see Aliyun SMS SDK Documents for more detail.
see Aliyun OpenAPI SDK for more detail.
Questions & Suggestions
Please open an issue here.