@yoooloo42/beat 1.0.10 → 1.0.12
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 +3 -2
- package/src/libs/Ali-SMS.js +85 -0
- package/src/libs/Ali-SMS.js.txt +2 -0
- package/src/libs/Email.js +11 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoooloo42/beat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
},
|
|
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.13",
|
|
20
21
|
"nodemailer": "^7.0.10"
|
|
21
22
|
},
|
|
22
23
|
"exports": {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import random from '@yoooloo42/bean/utils/random';
|
|
2
|
+
// 从 Node.js 内置模块导入工具
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
// 创建一个 require 函数
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
// 引入阿里云 SDK 核心依赖
|
|
7
|
+
const Core = require('@alicloud/pop-core')
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 向指定手机号发送短信
|
|
11
|
+
* @param {string} cellphone 接收短信的手机号(例如: '13800000000')
|
|
12
|
+
* @param {object} shortMessageCode 短信模板中的变量对象中code的值(短信有效内容)
|
|
13
|
+
* @param {object} clientBox 客户端参数
|
|
14
|
+
* @returns {Promise<object>} 返回阿里云 API 的响应对象
|
|
15
|
+
*/
|
|
16
|
+
const clientBoxInit = {
|
|
17
|
+
action: 'SendSms',
|
|
18
|
+
apiVersion: '2017-05-25',
|
|
19
|
+
regionId: 'cn-hangzhou', // 短信服务 API 的区域,通常使用杭州(cn-hangzhou)
|
|
20
|
+
endpoint: 'https://dysmsapi.aliyuncs.com', // 短信服务的 Endpoint
|
|
21
|
+
signName: 'litafire',
|
|
22
|
+
templateCode: 'SMS_497935086',
|
|
23
|
+
accessKeyId: ' ',
|
|
24
|
+
accessKeySecret: ' ',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sms(cellphone, shortMessageCode, clientBox) {
|
|
28
|
+
clientBox = Object.assign(clientBoxInit, clientBox)
|
|
29
|
+
return new Promise(function (resolve, reject) {
|
|
30
|
+
const client = new Core({
|
|
31
|
+
accessKeyId: clientBox.accessKeyId,
|
|
32
|
+
accessKeySecret: clientBox.accessKeySecret,
|
|
33
|
+
endpoint: clientBox.endpoint,
|
|
34
|
+
apiVersion: clientBox.apiVersion
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const params = {
|
|
38
|
+
'RegionId': clientBox.regionId,
|
|
39
|
+
'PhoneNumbers': cellphone,
|
|
40
|
+
'SignName': clientBox.signName,
|
|
41
|
+
'TemplateCode': clientBox.templateCode,
|
|
42
|
+
'TemplateParam': JSON.stringify({code: shortMessageCode})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const requestOption = {
|
|
46
|
+
method: 'POST'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
client.request(clientBox.action, params, requestOption).then(
|
|
50
|
+
result => {
|
|
51
|
+
console.log('测试 000', result)
|
|
52
|
+
resolve({code: 0, message: '发送短信成功',
|
|
53
|
+
result
|
|
54
|
+
})
|
|
55
|
+
/*
|
|
56
|
+
如果手机没有收到短信,那通常是以下原因之一(与您的代码逻辑无关):
|
|
57
|
+
短信额度/欠费:检查您的阿里云账户是否有足够的短信余额;
|
|
58
|
+
短信模板或签名审核:确认您的签名(litafire)和模板(SMS_182679443)在阿里云控制台中已审核通过且启用;
|
|
59
|
+
频率限制:同一手机号在短时间内频繁发送可能会被阿里云限制。
|
|
60
|
+
*/
|
|
61
|
+
},
|
|
62
|
+
err => {
|
|
63
|
+
resolve({code: 1, message: '发送短信失败',
|
|
64
|
+
err
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 发送验证码
|
|
72
|
+
function sendVercode(cellphone, codeLength = 6){
|
|
73
|
+
return new Promise(function (resolve, reject) {
|
|
74
|
+
const vercode = random.vercode6N(codeLength);
|
|
75
|
+
sms(cellphone, vercode).then(result=>{
|
|
76
|
+
resolve(Object.assign(result, {vercode}))
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const beat = {
|
|
82
|
+
sms,
|
|
83
|
+
sendVercode
|
|
84
|
+
}
|
|
85
|
+
export default beat
|
package/src/libs/Email.js
CHANGED
|
@@ -48,15 +48,15 @@ async function sendEmail(to, subject, htmlContent, textContent = '') {
|
|
|
48
48
|
// 3. 发送邮件
|
|
49
49
|
let info = await transporter.sendMail(mailOptions);
|
|
50
50
|
|
|
51
|
-
console.log('
|
|
52
|
-
console.log('
|
|
53
|
-
console.log('
|
|
54
|
-
console.log('
|
|
55
|
-
|
|
51
|
+
console.log('邮件发送成功:');
|
|
52
|
+
console.log('收件人:', to);
|
|
53
|
+
console.log('主题:', subject);
|
|
54
|
+
console.log('Message ID:', info.messageId);
|
|
55
|
+
|
|
56
56
|
return { success: true, messageId: info.messageId };
|
|
57
57
|
|
|
58
58
|
} catch (error) {
|
|
59
|
-
console.error('
|
|
59
|
+
console.error('邮件发送失败:', error);
|
|
60
60
|
return { success: false, error: error.message };
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -73,17 +73,16 @@ async function sendVercode(recipientEmail, codeLength = 6, expirationMinutes = 5
|
|
|
73
73
|
const verificationCode = random.vercode6(codeLength);
|
|
74
74
|
|
|
75
75
|
// 2. 构造邮件内容
|
|
76
|
-
const subject =
|
|
77
|
-
|
|
76
|
+
const subject = `Email验证码服务`;
|
|
78
77
|
const htmlContent = `
|
|
79
78
|
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; padding: 20px;">
|
|
80
|
-
<h2 style="color: #333;"
|
|
81
|
-
<p
|
|
79
|
+
<h2 style="color: #333;">验证码已发送</h2>
|
|
80
|
+
<p>以下是您的验证码,请妥善保管:</p>
|
|
82
81
|
<div style="background-color: #f5f5f5; padding: 15px; text-align: center; border-radius: 5px; margin: 20px 0;">
|
|
83
82
|
<span style="font-size: 30px; font-weight: bold; color: #007bff;">${verificationCode}</span>
|
|
84
83
|
</div>
|
|
85
|
-
<p style="color: #e44d26;"
|
|
86
|
-
<p style="font-size: 12px; color: #999;"
|
|
84
|
+
<p style="color: #e44d26;">注意:该验证码将在 ${expirationMinutes} 分钟内失效</p>
|
|
85
|
+
<p style="font-size: 12px; color: #999;">如果不是您本人操作,请忽略此邮件</p>
|
|
87
86
|
</div>
|
|
88
87
|
`;
|
|
89
88
|
|