@yoooloo42/beat 1.0.29 → 1.0.31

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,10 +1,15 @@
1
1
  {
2
2
  "name": "@yoooloo42/beat",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "",
5
5
  "type": "module",
6
+ "main": "dist/index.cjs.js",
7
+ "module": "dist/index.esm.js",
6
8
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
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"
8
13
  },
9
14
  "repository": {
10
15
  "type": "git",
@@ -20,25 +25,32 @@
20
25
  "@alicloud/ocr20191230": "^4.0.1",
21
26
  "@alicloud/openapi-client": "^0.4.15",
22
27
  "@alicloud/pop-core": "^1.8.0",
23
- "@yoooloo42/bean": "^1.0.16",
28
+ "@yoooloo42/bean": "^1.0.21",
24
29
  "aliyun-api-gateway": "^1.1.6",
25
30
  "axios": "^1.13.2",
26
31
  "cheerio": "^1.1.2",
32
+ "mongodb": "^7.0.0",
27
33
  "multer": "^2.0.2",
28
34
  "nodemailer": "^7.0.10",
29
35
  "xml2js": "^0.6.2"
30
36
  },
31
37
  "exports": {
32
- "./Ali/*": "./src/Ali/*.js",
33
- "./crypto/*": "./src/crypto/*.js",
34
- "./Email/*": "./src/Email/*.js",
35
- "./Feie/*": "./src/Feie/*.js",
36
- "./FileDB/*": "./src/FileDB/*.js",
37
- "./WeChat/*": "./src/WeChat/*.js",
38
- "./WeChat-Pay/*": "./src/WeChat-Pay/*.js",
39
- "./Yizoo/*": "./src/Yizoo/*.js"
38
+ ".": {
39
+ "import": "./dist/index.esm.js",
40
+ "require": "./dist/index.cjs.js"
41
+ },
42
+ "./*": "./*",
43
+ "./dist/*": "./dist/*"
40
44
  },
41
45
  "files": [
42
- "src"
43
- ]
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
+ }
44
56
  }
@@ -1,71 +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 {
67
- carplate
68
- }
69
- export default {
70
- carplate
71
- }
@@ -1,73 +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 {
69
- carplate
70
- }
71
- export default {
72
- carplate
73
- }
@@ -1,88 +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 {
84
- carplate
85
- }
86
- export default {
87
- carplate
88
- }
package/src/Ali/SMS.js DELETED
@@ -1,89 +0,0 @@
1
- import random from '@yoooloo42/bean/unclassified/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
- export {
83
- sms,
84
- sendVercode
85
- }
86
- export default {
87
- sms,
88
- sendVercode
89
- }
package/src/Ali/index.js DELETED
@@ -1,17 +0,0 @@
1
- import Carplate_AppKey from './Carplate-AppKey.js'
2
- import Carplate_AppCode from './Carplate-AppCode.js'
3
- import Carplate_VIAPI from './Carplate-VIAPI.js'
4
- import SMS from './SMS.js'
5
-
6
- export {
7
- Carplate_AppKey,
8
- Carplate_AppCode,
9
- Carplate_VIAPI,
10
- SMS
11
- }
12
- export default {
13
- Carplate_AppKey,
14
- Carplate_AppCode,
15
- Carplate_VIAPI,
16
- SMS
17
- }
@@ -1,113 +0,0 @@
1
- import nodemailer from 'nodemailer';
2
- import random from '@yoooloo42/bean/unclassified/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
- export {
107
- sendEmail,
108
- sendVercode
109
- }
110
- export default {
111
- sendEmail,
112
- sendVercode
113
- }
package/src/Feie/index.js DELETED
@@ -1,170 +0,0 @@
1
- // 飞鹅票据打印机
2
-
3
- import http from 'http'
4
- import qs from 'querystring'
5
- import Hash from '../crypto/Hash.js'
6
- const host = 'api.feieyun.cn',
7
- port = '80',
8
- path = '/Api/Open/'
9
-
10
- // 添加打印机(支持批量)
11
- function Open_printerAddlist (para) {
12
- // para.user
13
- // para.ukey
14
- // para.snList 打印机列表
15
-
16
- // ---------- 参数 snList 示例 ----------
17
- // 格式说明:打印机编号(必填)#打印机识别码(必填)#备注名称(选填)#流量卡号码(选填),多台打印机请换行(\n),每次最多100行(台)
18
- // var snList = "sn1#key1#note1#carnum1\nsn2#key2#note2#carnum2"
19
- // addprinter ( snList ) ;
20
-
21
- // ---------- 返回值示例 ----------
22
- // 正确的例子:{"msg":"ok","ret":0,"data":{"ok":["sn#key#note#carnum","316500011#abcdefgh#快餐前台"],"no":["316500012#abcdefgh#快餐前台#13688889999
23
- // (错误:识别码不正确)"]},"serverExecutedTime":3} 错误:{"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
24
-
25
- return new Promise(function (resolve, reject) {
26
- let stime = Math.floor(new Date().getTime() / 1000) //时间戳
27
- let sig = Hash.sha1(para.user + para.ukey + stime) //签名
28
-
29
- let post_data = {
30
- user: para.user,
31
- stime,
32
- sig,
33
- apiname: 'Open_printerAddlist',
34
- printerContent: para.snList
35
- }
36
- let content = qs.stringify(post_data)
37
- let options = {
38
- hostname: host,
39
- port,
40
- path,
41
- method: 'POST',
42
- headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
43
- }
44
-
45
- //发起请求
46
- let req = http.request(options, function (res) {
47
- res.setEncoding('utf-8')
48
- res.on('data', function (response) {
49
- let response0 = JSON.parse(response)
50
-
51
- if (response0.msg === 'ok' || response0.ret === 0) {
52
- resolve({code: 0, message: '增加打印机成功'})
53
- } else {
54
- resolve({code: 1, message: '增加打印机失败:' + response0.msg})
55
- }
56
- })
57
- })
58
- req.on('error', function (err) {
59
- resolve({code: 1, message: '请求失败:' + err})
60
- })
61
- req.write(content)
62
- req.end()
63
- })
64
- }
65
-
66
- // 打印
67
- function Open_printMsg(para){
68
- // para.user
69
- // para.ukey
70
- // para.sn 打印机编号(9 位数字)
71
- // para.note 打印机备注名称
72
- // para.orderInfo 打印内容
73
-
74
- // 提示:调用打印接口之前,必须登录后台在该账号下添加打印机,或者通过 API 接口,把打印机添加到该账号下面
75
-
76
- // ---------- 返回值示例 ----------
77
- // 正确的例子:{"msg":"ok","ret":0,"data":"xxxx_xxxx_xxxxxxxxx","serverExecutedTime":6}
78
- // 错误:{"msg":"错误信息.","ret":非零错误码,"data":null,"serverExecutedTime":5}
79
-
80
- /*
81
- 标签说明:
82
- 单标签:
83
- "<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
84
- "<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
85
- 成对标签:
86
- "<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
87
- <W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐
88
-
89
- 拼凑订单内容时,可参考下面的示例
90
- 根据打印纸张的宽度,自行调整内容的格式,可参考下面的示例
91
- var orderInfo ;
92
- orderInfo = "<CB>测试打印</CB><BR>" ; //标题字体如需居中放大,就需要用标签套上
93
- orderInfo += "名称      单价 数量 金额<BR>" ;
94
- orderInfo += "--------------------------------<BR>" ;
95
- orderInfo += "番       1.0 1 1.0<BR>" ;
96
- orderInfo += "番茄      10.0 10 10.0<BR>" ;
97
- orderInfo += "番茄炒     10.0 100 100.0<BR>" ;
98
- orderInfo += "番茄炒粉    100.0 100 100.0<BR>" ;
99
- orderInfo += "番茄炒粉粉   1000.0 1 100.0<BR>" ;
100
- orderInfo += "番茄炒粉粉粉粉 100.0 100 100.0<BR>" ;
101
- orderInfo += "番茄炒粉粉粉粉 15.0 1 15.0<BR>" ;
102
- orderInfo += "备注:快点送到xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<BR>" ;
103
- orderInfo += "--------------------------------<BR>" ;
104
- orderInfo += "合计:xx.0元<BR>" ;
105
- orderInfo += "送货地点:xxxxxxxxxxxxxxxxx<BR>" ;
106
- orderInfo += "联系电话:138000000000<BR>" ;
107
- orderInfo += "订餐时间:2011-01-06 19:30:10<BR><BR>" ;
108
- orderInfo += "----------请扫描二维码----------" ;
109
- orderInfo += "<QR>http://www.dzist.com</QR>" ; //把二维码字符串用标签套上即可自动生成二维码
110
- */
111
-
112
- return new Promise(function (resolve, reject) {
113
- let stime = Math.floor(new Date().getTime() / 1000) //时间戳
114
- let sig = Hash.sha1(para.user + para.ukey + stime) //签名
115
-
116
- let post_data = {
117
- user: para.user,
118
- stime,
119
- sig,
120
- apiname: 'Open_printMsg',
121
- sn: para.sn,
122
- content: para.orderInfo,
123
- times: '1' //打印联数,默认为1
124
- }
125
- let content = qs.stringify(post_data)
126
- let options = {
127
- hostname: host,
128
- port,
129
- path,
130
- method: 'POST',
131
- headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
132
- }
133
-
134
- let req = http.request(options, function (res) {
135
- res.setEncoding('utf-8')
136
- res.on('data', function (response) {
137
- let response0 = JSON.parse(response)
138
-
139
- if (response0.msg === 'ok' || response0.ret === 0) {
140
- resolve({
141
- code: 0,
142
- message: para.sn + ' ' + para.note + ' 打印成功'
143
- })
144
- } else {
145
- resolve({
146
- code: 1,
147
- message: para.sn + ' ' + para.note + ' 打印失败:' + response0.msg
148
- })
149
- }
150
- })
151
- })
152
- req.on('error', function (err) {
153
- resolve({
154
- code: 1,
155
- message: para.sn + ' ' + para.note + ' 请求失败:' + err
156
- })
157
- })
158
- req.write(content)
159
- req.end()
160
- })
161
- }
162
-
163
- export {
164
- Open_printerAddlist,
165
- Open_printMsg
166
- }
167
- export default {
168
- Open_printerAddlist,
169
- Open_printMsg
170
- }