@yoooloo42/beat 1.0.27 → 1.0.30

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 CHANGED
@@ -1,42 +1,56 @@
1
1
  {
2
- "name": "@yoooloo42/beat",
3
- "version": "1.0.27",
4
- "description": "",
5
- "type": "module",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/13993193075/beat.git"
12
- },
13
- "author": "",
14
- "license": "ISC",
15
- "bugs": {
16
- "url": "https://github.com/13993193075/beat/issues"
17
- },
18
- "homepage": "https://github.com/13993193075/beat#readme",
19
- "dependencies": {
20
- "@alicloud/ocr20191230": "^4.0.1",
21
- "@alicloud/openapi-client": "^0.4.15",
22
- "@alicloud/pop-core": "^1.8.0",
23
- "@yoooloo42/bean": "^1.0.14",
24
- "aliyun-api-gateway": "^1.1.6",
25
- "axios": "^1.13.2",
26
- "cheerio": "^1.1.2",
27
- "multer": "^2.0.2",
28
- "nodemailer": "^7.0.10",
29
- "xml2js": "^0.6.2"
30
- },
31
- "exports": {
32
- "./libs/*": "./src/libs/*.js",
33
- "./libs/Ali/*": "./src/libs/Ali/*.js",
34
- "./libs/crypto/*": "./src/libs/crypto/*.js",
35
- "./libs/FileDB/*": "./src/libs/FileDB/*.js",
36
- "./libs/WeChat/*": "./src/libs/WeChat/*.js",
37
- "./libs/WeChat-Pay/*": "./src/libs/WeChat-Pay/*.js"
38
- },
39
- "files": [
40
- "src"
41
- ]
2
+ "name": "@yoooloo42/beat",
3
+ "version": "1.0.30",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "dist/index.cjs.js",
7
+ "module": "dist/index.esm.js",
8
+ "scripts": {
9
+ "clean": "rm -rf dist",
10
+ "build": "npm run clean && rollup -c",
11
+ "build:prod": "cross-env NODE_ENV=production npm run build",
12
+ "watch": "rollup -c -w"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/13993193075/beat.git"
17
+ },
18
+ "author": "",
19
+ "license": "ISC",
20
+ "bugs": {
21
+ "url": "https://github.com/13993193075/beat/issues"
22
+ },
23
+ "homepage": "https://github.com/13993193075/beat#readme",
24
+ "dependencies": {
25
+ "@alicloud/ocr20191230": "^4.0.1",
26
+ "@alicloud/openapi-client": "^0.4.15",
27
+ "@alicloud/pop-core": "^1.8.0",
28
+ "@yoooloo42/bean": "^1.0.21",
29
+ "aliyun-api-gateway": "^1.1.6",
30
+ "axios": "^1.13.2",
31
+ "cheerio": "^1.1.2",
32
+ "mongodb": "^7.0.0",
33
+ "multer": "^2.0.2",
34
+ "nodemailer": "^7.0.10",
35
+ "xml2js": "^0.6.2"
36
+ },
37
+ "exports": {
38
+ ".": {
39
+ "import": "./dist/index.esm.js",
40
+ "require": "./dist/index.cjs.js"
41
+ },
42
+ "./*": "./*",
43
+ "./dist/*": "./dist/*"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ],
48
+ "devDependencies": {
49
+ "@rollup/plugin-commonjs": "^29.0.0",
50
+ "@rollup/plugin-json": "^6.1.0",
51
+ "@rollup/plugin-node-resolve": "^16.0.3",
52
+ "@rollup/plugin-terser": "^0.4.4",
53
+ "cross-env": "^10.1.0",
54
+ "rollup": "^4.53.2"
55
+ }
42
56
  }
@@ -1,70 +0,0 @@
1
- // 优化后的第二个程序:API签名认证调用方法(AppKey & AppSecret)
2
-
3
- import ali from 'aliyun-api-gateway'
4
-
5
- /**
6
- * 使用阿里云市场 API 网关进行车牌识别 (AppKey & AppSecret 签名认证)
7
- * @param {object} para - 参数对象
8
- * @param {string} para.imageUrl - 图片的公网 URL
9
- * @param {string} [para.appKey] - 可选,AppKey,优先从环境变量 ALIBABA_CLOUD_APP_KEY 获取
10
- * @param {string} [para.appSecret] - 可选,AppSecret,优先从环境变量 ALIBABA_CLOUD_APP_SECRET 获取
11
- * @returns {Promise<object>} 包含识别结果的对象
12
- */
13
- async function carplate(para) {
14
- // 1. **规范:** 优先从环境变量读取 AppKey 和 AppSecret,提高安全性。
15
- const appKey = para.appKey || process.env.ALIBABA_CLOUD_APP_KEY;
16
- const appSecret = para.appSecret || process.env.ALIBABA_CLOUD_APP_SECRET;
17
-
18
- if (!appKey || !appSecret) {
19
- return {
20
- code: -1,
21
- message: "AppKey 或 AppSecret 缺失,请配置或传入!"
22
- };
23
- }
24
-
25
- const Client = ali.Client
26
- const client = new Client(appKey, appSecret)
27
-
28
- try {
29
- const requestUrl = 'https://ocrcp.market.alicloudapi.com/rest/160601/ocr/ocr_vehicle_plate.json'
30
-
31
- // 发起 POST 请求
32
- const result = await client.post(requestUrl, {
33
- data: {
34
- 'image': para.imageUrl,
35
- 'configure': '{"multi_crop":false}'
36
- },
37
- headers: {
38
- accept: 'application/json'
39
- }
40
- })
41
-
42
- // 2. 检查返回结构,确保结果有效
43
- if (result && result.plates && result.plates.length > 0) {
44
- return {
45
- code: 0,
46
- message: "车牌识别成功",
47
- result: result.plates[0]
48
- }
49
- } else {
50
- return {
51
- code: 1,
52
- message: "车牌识别成功,但未检测到有效车牌。",
53
- result: null
54
- };
55
- }
56
-
57
- } catch (err) {
58
- // 3. **规范:** 使用 try...catch 捕获错误,并返回非零 code
59
- const errorMessage = err.message || err.stack || "未知错误";
60
-
61
- return {
62
- code: -1,
63
- message: "车牌识别失败:" + errorMessage
64
- }
65
- }
66
- }
67
-
68
- export default {
69
- carplate
70
- }
@@ -1,68 +0,0 @@
1
- // 优化后的第一个程序:API简单身份认证调用方法(APPCODE)
2
-
3
- import ali from 'aliyun-api-gateway'
4
-
5
- /**
6
- * 使用阿里云市场 API 网关进行车牌识别 (APPCODE 认证)
7
- * @param {object} para - 参数对象
8
- * @param {string} para.imageUrl - 图片的公网 URL
9
- * @param {string} [para.appCode] - 可选,APPCODE,优先从环境变量 ALIBABA_CLOUD_APPCODE 获取
10
- * @returns {Promise<object>} 包含识别结果的对象
11
- */
12
- async function carplate(para) {
13
- // 1. **规范:** 优先从环境变量读取 APPCODE,提高安全性。
14
- const appCode = para.appCode || process.env.ALIBABA_CLOUD_APPCODE;
15
-
16
- if (!appCode) {
17
- return {
18
- code: -1,
19
- message: "APPCODE 缺失,请配置环境变量 ALIBABA_CLOUD_APPCODE 或传入!"
20
- };
21
- }
22
-
23
- const SimpleClient = ali.SimpleClient
24
- const client = new SimpleClient(appCode)
25
-
26
- try {
27
- const requestUrl = 'https://ocrcp.market.alicloudapi.com/rest/160601/ocr/ocr_vehicle_plate.json'
28
-
29
- // 发起 POST 请求
30
- const result = await client.post(requestUrl, {
31
- data: {
32
- 'image': para.imageUrl,
33
- 'configure': '{"multi_crop":false}'
34
- },
35
- headers: {
36
- accept: 'application/json'
37
- }
38
- })
39
-
40
- // 2. 检查返回结构,确保结果有效
41
- if (result && result.plates && result.plates.length > 0) {
42
- return {
43
- code: 0,
44
- message: "车牌识别成功",
45
- result: result.plates[0]
46
- }
47
- } else {
48
- return {
49
- code: 1,
50
- message: "车牌识别成功,但未检测到有效车牌。",
51
- result: null
52
- };
53
- }
54
-
55
- } catch (err) {
56
- // 3. **规范:** 使用 try...catch 捕获错误,并返回非零 code
57
- const errorMessage = err.message || err.stack || "未知错误";
58
-
59
- return {
60
- code: -1,
61
- message: "车牌识别失败:" + errorMessage
62
- }
63
- }
64
- }
65
-
66
- export default {
67
- carplate
68
- }
@@ -1,85 +0,0 @@
1
- // 规范优化后的车牌识别程序 (基于 VIAPI 官方 SDK)
2
-
3
- import OcrClient from '@alicloud/ocr20191230'
4
- import OpenapiClient from '@alicloud/openapi-client'
5
- import TeaUtil from '@alicloud/tea-util'
6
-
7
- /**
8
- * 使用阿里云 VIAPI 官方 SDK 进行车牌识别 (AccessKey 认证)
9
- * @param {object} para - 参数对象
10
- * @param {string} para.imageUrl - 图片的公网 URL
11
- * @param {string} [para.accessKeyId] - 可选,AccessKey ID,优先从环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 获取
12
- * @param {string} [para.accessKeySecret] - 可选,AccessKey Secret,优先从环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET 获取
13
- * @returns {Promise<object>} 包含识别结果的对象
14
- */
15
- async function carplate(para) {
16
- // 1. **规范:** 优先从环境变量读取密钥,提高安全性。
17
- const accessKeyId = para.accessKeyId || process.env.ALIBABA_CLOUD_ACCESS_KEY_ID || 'YOUR_DEFAULT_ACCESS_KEY_ID';
18
- const accessKeySecret = para.accessKeySecret || process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET || 'YOUR_DEFAULT_ACCESS_KEY_SECRET';
19
-
20
- // **注意:生产环境中必须配置环境变量,并移除默认硬编码值!**
21
-
22
- if (!accessKeyId || !accessKeySecret) {
23
- throw new Error("AccessKeyId 和 AccessKeySecret 缺失,请配置或传入!");
24
- }
25
-
26
- const config = new OpenapiClient.Config({
27
- accessKeyId: accessKeyId,
28
- accessKeySecret: accessKeySecret
29
- });
30
-
31
- // 访问的域名
32
- config.endpoint = `ocr.cn-shanghai.aliyuncs.com`;
33
- const client = new OcrClient.default(config);
34
-
35
- try {
36
- // 2. **规范:** 使用 RecognizeLicensePlateRequest,直接传入 ImageURL 字符串,简化调用
37
- let recognizeLicensePlateRequest = new OcrClient.RecognizeLicensePlateRequest({
38
- imageURL: para.imageUrl, // 直接传入 URL 字符串
39
- });
40
-
41
- let runtime = new TeaUtil.RuntimeOptions({
42
- // 可以配置网络超时等参数
43
- connectTimeout: 5000,
44
- readTimeout: 10000,
45
- });
46
-
47
- const response = await client.recognizeLicensePlateWithOptions(recognizeLicensePlateRequest, runtime);
48
-
49
- // 确保结果有效
50
- if (response.body && response.body.data && response.body.data.plates && response.body.data.plates.length > 0) {
51
- return {
52
- code: 0,
53
- message: "车牌识别成功",
54
- result: response.body.data.plates[0]
55
- };
56
- } else {
57
- return {
58
- code: 1,
59
- message: "车牌识别成功,但未检测到有效车牌。",
60
- result: null
61
- };
62
- }
63
-
64
- } catch (error) {
65
- // 3. **规范:** 使用 try...catch 捕获错误,并 reject 或 throw Error,而不是返回 code: 0。
66
-
67
- // 提取阿里云的错误码和信息
68
- const errorCode = error.data ? error.data.Code : 'UNKNOWN_ERROR';
69
- const errorMessage = error.message || '未知错误';
70
-
71
- // 统一返回失败信息
72
- return {
73
- code: -1, // 使用 -1 或其他负值表示系统级/网络级错误
74
- message: `车牌识别失败: [${errorCode}] ${errorMessage}`,
75
- error: error
76
- };
77
-
78
- // 另一种规范是直接 throw Error,让调用方处理
79
- // throw new Error(`车牌识别失败: [${errorCode}] ${errorMessage}`);
80
- }
81
- }
82
-
83
- export default {
84
- carplate
85
- }
@@ -1,86 +0,0 @@
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
- // accessKeyId: ' ',
22
- // accessKeySecret: ' ',
23
- // signName: ' ',
24
- // templateCode: ' '
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('发送短信成功:', result)
52
- resolve({code: 0, message: '发送短信成功',
53
- result
54
- })
55
- /*
56
- 如果手机没有收到短信,那通常是以下原因之一(与您的代码逻辑无关):
57
- 短信额度/欠费:检查您的阿里云账户是否有足够的短信余额;
58
- 短信模板或签名审核:确认您的签名(litafire)和模板(SMS_182679443)在阿里云控制台中已审核通过且启用;
59
- 频率限制:同一手机号在短时间内频繁发送可能会被阿里云限制。
60
- */
61
- },
62
- err => {
63
- console.log('发送短信失败:', err)
64
- resolve({code: 1, message: '发送短信失败',
65
- err
66
- })
67
- }
68
- )
69
- })
70
- }
71
-
72
- // 发送验证码
73
- function sendVercode(cellphone, codeLength = 6, clientBox){
74
- return new Promise(function (resolve, reject) {
75
- const vercode = random.vercode6N(codeLength);
76
- sms(cellphone, vercode, clientBox).then(result=>{
77
- resolve(Object.assign(result, {vercode}))
78
- })
79
- })
80
- }
81
-
82
- const beat = {
83
- sms,
84
- sendVercode
85
- }
86
- export default beat
package/src/libs/Email.js DELETED
@@ -1,110 +0,0 @@
1
- import nodemailer from 'nodemailer';
2
- import random from '@yoooloo42/bean/utils/random';
3
-
4
- /**
5
- * Node.js 项目中发送电子邮件的函数
6
- * @param {string} to - 收件人邮箱地址
7
- * @param {string} subject - 邮件主题
8
- * @param {string} htmlContent - 邮件的 HTML 内容(正文)
9
- * @param {string} [textContent] - 邮件的纯文本内容(可选,作为 HTML 无法显示的备用)
10
- */
11
- async function sendEmail(to, subject, htmlContent, textContent = '') {
12
- // ⚠️ 1. 配置 Transporter (SMTP 服务器设置)
13
- //
14
- // 如果使用 Gmail:
15
- // - 您需要启用“两步验证”并生成一个“应用专用密码”(App Password),而不是使用您的主账户密码。
16
- // - 否则,Google 可能会阻止登录。
17
- const transporter = nodemailer.createTransport({
18
- // host: 'smtp.exmail.qq.com', // 替换为你的 SMTP 服务器地址 (例如: 'smtp.gmail.com', 'smtp-mail.outlook.com')
19
- // port: 465, // 常用端口: 465 (安全连接) 或 587 (TLS)
20
- // secure: true, // true 为 465 端口, false 为其它端口
21
- service: '126',
22
- auth: {
23
- // user: 'your_email@example.com', // 替换为你的发件箱地址
24
- user: 'lyxdrwhy000@126.com',
25
- // pass: 'your_app_password' // 替换为你的邮箱密码或“应用专用密码”
26
- pass: 'JSQNIEMQCCPCVSJW'
27
- }
28
- });
29
-
30
- // 2. 构造邮件内容对象
31
- const mailOptions = {
32
- // from: '"Your Name" <your_email@example.com>', // 发件人信息 (会显示在收件箱中)
33
- from: `"Stellarium - 企业应用集成平台" <lyxdrwhy000@126.com>`,
34
- to: to, // 收件人地址
35
- subject: subject, // 邮件主题
36
- html: htmlContent, // 邮件 HTML 正文
37
- text: textContent // 邮件纯文本正文 (可选)
38
- // 附件可以在这里添加:
39
- /* attachments: [
40
- {
41
- filename: 'report.pdf',
42
- path: '/path/to/your/report.pdf'
43
- }
44
- ] */
45
- };
46
-
47
- try {
48
- // 3. 发送邮件
49
- let info = await transporter.sendMail(mailOptions);
50
-
51
- console.log('邮件发送成功:');
52
- console.log('收件人:', to);
53
- console.log('主题:', subject);
54
- console.log('Message ID:', info.messageId);
55
-
56
- return { success: true, messageId: info.messageId };
57
-
58
- } catch (error) {
59
- console.error('邮件发送失败:', error);
60
- return { success: false, error: error.message };
61
- }
62
- }
63
-
64
- /**
65
- * 发送包含验证码的邮件
66
- * * @param {string} recipientEmail - 收件人邮箱地址
67
- * @param {number} [codeLength=6] - 验证码长度
68
- * @param {number} [expirationMinutes=5] - 验证码有效时间(分钟)
69
- * @returns {Promise<{success: boolean, code?: string, error?: string}>} - 包含发送结果和生成的验证码
70
- */
71
- async function sendVercode(recipientEmail, codeLength = 6, expirationMinutes = 5) {
72
- // 1. 生成验证码
73
- const verificationCode = random.vercode6(codeLength);
74
-
75
- // 2. 构造邮件内容
76
- const subject = `Email验证码服务`;
77
- const htmlContent = `
78
- <div style="font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; padding: 20px;">
79
- <h2 style="color: #333;">验证码已发送</h2>
80
- <p>以下是您的验证码,请妥善保管:</p>
81
- <div style="background-color: #f5f5f5; padding: 15px; text-align: center; border-radius: 5px; margin: 20px 0;">
82
- <span style="font-size: 30px; font-weight: bold; color: #007bff;">${verificationCode}</span>
83
- </div>
84
- <p style="color: #e44d26;">注意:该验证码将在 ${expirationMinutes} 分钟内失效</p>
85
- <p style="font-size: 12px; color: #999;">如果不是您本人操作,请忽略此邮件</p>
86
- </div>
87
- `;
88
-
89
- // 3. 调用核心发送函数
90
- const sendResult = await sendEmail(recipientEmail, subject, htmlContent);
91
-
92
- // 4. 返回结果和验证码
93
- if (sendResult.success) {
94
- return {
95
- success: true,
96
- vercode: verificationCode
97
- };
98
- } else {
99
- return {
100
- success: false,
101
- error: sendResult.error || '邮件发送失败'
102
- };
103
- }
104
- }
105
-
106
- const beat = {
107
- sendEmail,
108
- sendVercode
109
- }
110
- export default beat