-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·51 lines (46 loc) · 1.44 KB
/
index.js
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
const MNS = require('aliyun-mns');
class AliMnsSms {
constructor(options) {
var mnsConfig = {
accessKeyId: options.accessKeyId,
secretAccessKey: options.secretAccessKey,
endpoint: options.endpoint,
apiVersion: '2015-06-06' // 调用MNS接口的版本号,当前版本为2015-06-06
};
this._mns = new MNS(mnsConfig);
this._topic = this._mns.topic('sms.topic-cn-hangzhou');
this._message = this._topic.message();
}
/**
* Send single sms via ali mns
* @param {*} options
*/
sendSingleSMS(options, callback) {
var param = {
SmsParams: JSON.stringify(options.smsParams),
TemplateCode: options.templateCode,
Type: 'singleContent',
FreeSignName: options.freeSignName,
Receiver: options.receiver
};
this._message.publish({
MessageBody: 'message',
MessageAttributes: {
DirectSMS: JSON.stringify(param)
}
})
.then(res => {
console.log('Sussess:', res)
if (callback) {
callback(res);
}
})
.catch(res => {
console.error('Failed:', res)
if (callback) {
callback(res);
}
});
}
}
module.exports = AliMnsSms;