q-koa 8.0.1 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/file/services/aliSms.js +24 -21
- package/package.json +1 -1
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
const Core = require('@alicloud/pop-core')
|
|
2
2
|
const { lodash } = require('q-koa')
|
|
3
|
-
module.exports = class
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
module.exports = class Singleton {
|
|
4
|
+
constructor(key) {
|
|
5
|
+
this.key = key
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 单例模式
|
|
9
|
+
*/
|
|
10
|
+
if (!Singleton.instance) {
|
|
11
|
+
Singleton.instance = this
|
|
12
|
+
}
|
|
13
|
+
const previous = Singleton.instance.getConfig()
|
|
14
|
+
if (!lodash.isEqual(previous, key)) {
|
|
15
|
+
Singleton.instance = this
|
|
15
16
|
}
|
|
17
|
+
return Singleton.instance
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
init() {
|
|
16
21
|
this.client = new Core({
|
|
17
|
-
accessKeyId: this.
|
|
18
|
-
accessKeySecret: this.
|
|
22
|
+
accessKeyId: this.key.accessKeyId,
|
|
23
|
+
accessKeySecret: this.key.accessKeySecret,
|
|
19
24
|
endpoint: 'https://dysmsapi.aliyuncs.com',
|
|
20
25
|
apiVersion: '2017-05-25',
|
|
21
26
|
})
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
async send({ mobile, TemplateCode, TemplateParam }) {
|
|
25
|
-
|
|
30
|
+
console.log('JSON.stringify(TemplateParam)')
|
|
26
31
|
const result = await this.client.request(
|
|
27
32
|
'SendSms',
|
|
28
33
|
{
|
|
29
34
|
PhoneNumbers: mobile,
|
|
30
|
-
SignName: this.
|
|
35
|
+
SignName: this.key.SignName,
|
|
31
36
|
TemplateCode,
|
|
32
|
-
TemplateParam: JSON.stringify(
|
|
33
|
-
code: this.config.param,
|
|
34
|
-
}),
|
|
37
|
+
TemplateParam: JSON.stringify(TemplateParam),
|
|
35
38
|
},
|
|
36
39
|
{
|
|
37
40
|
method: 'POST',
|
|
@@ -40,7 +43,7 @@ module.exports = class Sms {
|
|
|
40
43
|
return result
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
return this.
|
|
46
|
+
getConfig() {
|
|
47
|
+
return this.key
|
|
45
48
|
}
|
|
46
49
|
}
|