@yoooloo42/beat 1.0.11 → 1.0.13
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/package.json +2 -2
- package/src/libs/Ali-SMS.js +17 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoooloo42/beat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"homepage": "https://github.com/13993193075/beat#readme",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@alicloud/pop-core": "^1.8.0",
|
|
20
|
-
"@yoooloo42/bean": "^1.0.
|
|
20
|
+
"@yoooloo42/bean": "^1.0.13",
|
|
21
21
|
"nodemailer": "^7.0.10"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
package/src/libs/Ali-SMS.js
CHANGED
|
@@ -6,25 +6,24 @@ const require = createRequire(import.meta.url);
|
|
|
6
6
|
// 引入阿里云 SDK 核心依赖
|
|
7
7
|
const Core = require('@alicloud/pop-core')
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* 向指定手机号发送短信
|
|
11
|
+
* @param {string} cellphone 接收短信的手机号(例如: '13800000000')
|
|
12
|
+
* @param {object} shortMessageCode 短信模板中的变量对象中code的值(短信有效内容)
|
|
13
|
+
* @param {object} clientBox 客户端参数
|
|
14
|
+
* @returns {Promise<object>} 返回阿里云 API 的响应对象
|
|
15
|
+
*/
|
|
9
16
|
const clientBoxInit = {
|
|
10
17
|
action: 'SendSms',
|
|
11
18
|
apiVersion: '2017-05-25',
|
|
12
|
-
accessKeyId: "LTAI5tJeX6TS7bqbLzKxJKrd",
|
|
13
|
-
accessKeySecret : "qIhbZJaUyYeLI60yXFyT28k1q4uUde",
|
|
14
19
|
regionId: 'cn-hangzhou', // 短信服务 API 的区域,通常使用杭州(cn-hangzhou)
|
|
15
20
|
endpoint: 'https://dysmsapi.aliyuncs.com', // 短信服务的 Endpoint
|
|
16
21
|
signName: 'litafire',
|
|
17
|
-
templateCode: '
|
|
22
|
+
templateCode: 'SMS_497935086'
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @param {string} cellphone 接收短信的手机号(例如: '13800000000')
|
|
23
|
-
* @param {object} shortMessageCode 短信模板中的变量对象中code的值(短信有效内容)
|
|
24
|
-
* @param {object} clientBox 客户端参数
|
|
25
|
-
* @returns {Promise<object>} 返回阿里云 API 的响应对象
|
|
26
|
-
*/
|
|
27
|
-
function sms(cellphone, shortMessageCode, clientBox = clientBoxInit) {
|
|
25
|
+
function sms(cellphone, shortMessageCode, clientBox) {
|
|
26
|
+
clientBox = Object.assign(clientBoxInit, clientBox)
|
|
28
27
|
return new Promise(function (resolve, reject) {
|
|
29
28
|
const client = new Core({
|
|
30
29
|
accessKeyId: clientBox.accessKeyId,
|
|
@@ -47,6 +46,7 @@ function sms(cellphone, shortMessageCode, clientBox = clientBoxInit) {
|
|
|
47
46
|
|
|
48
47
|
client.request(clientBox.action, params, requestOption).then(
|
|
49
48
|
result => {
|
|
49
|
+
console.log('测试 000', result)
|
|
50
50
|
resolve({code: 0, message: '发送短信成功',
|
|
51
51
|
result
|
|
52
52
|
})
|
|
@@ -58,7 +58,9 @@ function sms(cellphone, shortMessageCode, clientBox = clientBoxInit) {
|
|
|
58
58
|
*/
|
|
59
59
|
},
|
|
60
60
|
err => {
|
|
61
|
-
resolve({code: 1, message: '
|
|
61
|
+
resolve({code: 1, message: '发送短信失败',
|
|
62
|
+
err
|
|
63
|
+
})
|
|
62
64
|
}
|
|
63
65
|
)
|
|
64
66
|
})
|
|
@@ -67,13 +69,9 @@ function sms(cellphone, shortMessageCode, clientBox = clientBoxInit) {
|
|
|
67
69
|
// 发送验证码
|
|
68
70
|
function sendVercode(cellphone, codeLength = 6){
|
|
69
71
|
return new Promise(function (resolve, reject) {
|
|
70
|
-
const vercode = random.
|
|
72
|
+
const vercode = random.vercode6N(codeLength);
|
|
71
73
|
sms(cellphone, vercode).then(result=>{
|
|
72
|
-
|
|
73
|
-
resolve({code: 0, message: `发送验证码${vercode}成功`})
|
|
74
|
-
}else{
|
|
75
|
-
resolve({code: 1, message: `发送验证码${vercode}失败`})
|
|
76
|
-
}
|
|
74
|
+
resolve(Object.assign(result, {vercode}))
|
|
77
75
|
})
|
|
78
76
|
})
|
|
79
77
|
}
|
|
@@ -82,12 +80,4 @@ const beat = {
|
|
|
82
80
|
sms,
|
|
83
81
|
sendVercode
|
|
84
82
|
}
|
|
85
|
-
export default beat
|
|
86
|
-
|
|
87
|
-
/*
|
|
88
|
-
sendVercode('13993193075').then(result=>{
|
|
89
|
-
console.log(result.message)
|
|
90
|
-
}).catch(err=>{
|
|
91
|
-
console.log(err)
|
|
92
|
-
})
|
|
93
|
-
*/
|
|
83
|
+
export default beat
|