mm_os 2.1.9 → 2.2.1
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/com/event/index.js +1 -0
- package/core/com/eventer/com.js +41 -17
- package/core/com/mqtt/config.tpl.json +34 -10
- package/core/com/mqtt/drive.js +420 -48
- package/core/com/mqtt/index.js +321 -39
- package/core/com/mqtt/mm_mqtt.js +327 -0
- package/core/com/mqtt/script.js +9 -8
- package/core/com/plugin/config.tpl.json +6 -0
- package/core/com/plugin/drive.js +12 -8
- package/demo/app/test/event_api/client/event.json +3 -1
- package/demo/app/test/event_api/client/main.js +1 -0
- package/demo/app/test/mqtt/df/index.js +364 -0
- package/demo/app/test/mqtt/df/mqtt.json +34 -0
- package/demo/app/test/mqtt/test/index.js +38 -0
- package/demo/app/test/mqtt/test/mqtt.json +24 -0
- package/demo/app/test/mqtt/zs/index.js +430 -0
- package/demo/app/test/mqtt/zs/mqtt.json +34 -0
- package/demo/com/server/com.json +4 -0
- package/demo/com/server/index.js +447 -0
- package/demo/config/development.json +3 -3
- package/demo/config/local.json +4 -4
- package/demo/config/test.json +1 -1
- package/demo/index.js +9 -0
- package/index.js +0 -1
- package/middleware/cors/index.js +6 -7
- package/middleware/waf_ip/index.js +2 -2
- package/middleware/waf_ip/middleware.json +2 -1
- package/middleware/web_event/index.js +5 -3
- package/package.json +3 -3
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 查询个人记录
|
|
3
|
+
* @param {String} clientid 客户端ID
|
|
4
|
+
* @param {Object} param
|
|
5
|
+
*/
|
|
6
|
+
exports.get_log = function(clientid, param) {
|
|
7
|
+
return this.push("get_suc_record", clientid, param);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 考勤打卡(无)
|
|
12
|
+
* @param {String} clientid 客户端ID
|
|
13
|
+
* @param {Object} uuid 用户唯一标识
|
|
14
|
+
* @param {String} avatar base64头像
|
|
15
|
+
* @param {Number} longtime 超时回馈
|
|
16
|
+
*/
|
|
17
|
+
exports.sign_in = function(clientid, uuid, avatar) {
|
|
18
|
+
// return this.push("PullRecordOnlyPic", clientid, {
|
|
19
|
+
// "personID": uuid,
|
|
20
|
+
// "picinfo": avatar
|
|
21
|
+
// });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 下发二维码(无)
|
|
26
|
+
* @param {String} clientid
|
|
27
|
+
* @param {Object} param
|
|
28
|
+
* @param {Number} longtime 超时回馈
|
|
29
|
+
*/
|
|
30
|
+
exports.push_qrcode = function(clientid, param) {
|
|
31
|
+
// return this.push("ShowQRCode", clientid, param);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 以图搜人(无)
|
|
36
|
+
* @param {String} clientid 客户端ID
|
|
37
|
+
* @param {Object} avatar 人脸照片
|
|
38
|
+
* @param {Number} longtime 超时回馈
|
|
39
|
+
*/
|
|
40
|
+
exports.get_member_pic = function(clientid, avatar) {
|
|
41
|
+
// return this.push("GetPictureSearch", clientid, {
|
|
42
|
+
// "facesluiceId": clientid,
|
|
43
|
+
// "MaxSimilarity": 80,
|
|
44
|
+
// "MaxNum": 1,
|
|
45
|
+
// "picinfo": avatar
|
|
46
|
+
// });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 远程开门
|
|
51
|
+
* @param {String} clientid 客户端ID
|
|
52
|
+
* @param {String} uuid 用户唯一标识
|
|
53
|
+
* @param {Boolean} pass 是否可通行 true为是
|
|
54
|
+
* @param {String} tip 提示
|
|
55
|
+
*/
|
|
56
|
+
exports.unlock = function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
|
|
57
|
+
return this.push("gpio control", clientid, {
|
|
58
|
+
// 0不开门,1开门
|
|
59
|
+
"ctrl_type": pass ? "on" : "off"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 删除成员
|
|
65
|
+
* @param {String} clientid 客户端ID
|
|
66
|
+
* @param {String} uuid 用户唯一标识
|
|
67
|
+
* @param {Number} longtime 超时回馈
|
|
68
|
+
*/
|
|
69
|
+
exports.del_member = function(clientid, uuid) {
|
|
70
|
+
var res = this.push("delete_face", clientid, {
|
|
71
|
+
"per_id": uuid,
|
|
72
|
+
"type": 0
|
|
73
|
+
});
|
|
74
|
+
var bl = res.code == 0;
|
|
75
|
+
return $.ret.bl(bl, res.reply || "删除成功");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 批量删除成员
|
|
80
|
+
* @param {String} clientid 客户端ID
|
|
81
|
+
* @param {Object} arr 成员列表
|
|
82
|
+
* @param {Number} longtime 超时回馈
|
|
83
|
+
*/
|
|
84
|
+
exports.del_member_batch = async function(clientid, arr, longtime) {
|
|
85
|
+
var list = [];
|
|
86
|
+
for (var i = 0; i < arr.length; i++) {
|
|
87
|
+
var uuid = arr[i];
|
|
88
|
+
var res = await this.push("delete_face", clientid, {
|
|
89
|
+
"per_id": uuid,
|
|
90
|
+
"type": 0
|
|
91
|
+
});
|
|
92
|
+
var bl = false;
|
|
93
|
+
if (res.code == 0) {
|
|
94
|
+
bl = true;
|
|
95
|
+
}
|
|
96
|
+
list.push({
|
|
97
|
+
uuid,
|
|
98
|
+
bl,
|
|
99
|
+
tip: res.reply || "删除成功"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return list;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 重启设备
|
|
107
|
+
* @param {String} clientid 设备sn
|
|
108
|
+
*/
|
|
109
|
+
exports.reboot_device = function(clientid) {
|
|
110
|
+
return this.push("reboot_cam", clientid, {});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 设置设备时间
|
|
115
|
+
* @param {String} clientid 设备sn
|
|
116
|
+
* @param {String} datetime 日期时间
|
|
117
|
+
*/
|
|
118
|
+
exports.set_device_time = function(clientid, datetime) {
|
|
119
|
+
return this.push("ss_set_timing", clientid, {
|
|
120
|
+
"body": {
|
|
121
|
+
"datetime": datetime
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 恢复出厂设置
|
|
128
|
+
* @param {String} clientid 设备sn
|
|
129
|
+
* @param {Boolean} record 是否恢复控制记录,true为恢复
|
|
130
|
+
* @param {Boolean} member 是否恢复成员,true为恢复
|
|
131
|
+
* @param {Boolean} log 是否恢复请求日志,true为恢复
|
|
132
|
+
*/
|
|
133
|
+
exports.reset_device = function(clientid, record = true, member = false, log = true) {
|
|
134
|
+
if (record) {
|
|
135
|
+
// 清空记录
|
|
136
|
+
this.push("delete_record", clientid, {});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (member) {
|
|
140
|
+
// 删除所有成员
|
|
141
|
+
this.push("delete_face", clientid, {
|
|
142
|
+
type: 4
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 查询下发进度(未完成)
|
|
149
|
+
* @param {String} clientid 设备sn
|
|
150
|
+
*/
|
|
151
|
+
exports.get_progress = function(clientid) {
|
|
152
|
+
return this.push("QueryProgress", clientid, {});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 考勤补卡(无)
|
|
157
|
+
* @param {String} clientid 设备sn
|
|
158
|
+
* @param {Object} param 其他信息
|
|
159
|
+
* @param {Number} longtime 超时回馈
|
|
160
|
+
*/
|
|
161
|
+
exports.replacement = function(clientid, param, longtime = 0) {
|
|
162
|
+
// return this.push("PullRecordOnlyName", clientid, param, longtime);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 查询人员名单
|
|
167
|
+
* @param {String} clientid 客户端ID
|
|
168
|
+
* @param {Number} longtime 超时回馈
|
|
169
|
+
*/
|
|
170
|
+
exports.get_member = async function(clientid, uuid, name) {
|
|
171
|
+
var qy = {};
|
|
172
|
+
if (uuid) {
|
|
173
|
+
qy.uuid = uuid;
|
|
174
|
+
}
|
|
175
|
+
if (name) {
|
|
176
|
+
qy.name = name;
|
|
177
|
+
}
|
|
178
|
+
var res = await this.push("query_face", qy);
|
|
179
|
+
if (res.code) {
|
|
180
|
+
return res.pers_id;
|
|
181
|
+
}
|
|
182
|
+
return []
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 查询人员名单
|
|
187
|
+
* @param {String} clientid 客户端ID
|
|
188
|
+
* @param {String} uuid 用户唯一标识
|
|
189
|
+
*/
|
|
190
|
+
exports.get_member_one = async function(clientid, uuid) {
|
|
191
|
+
var list = await get_member(clientid, uuid);
|
|
192
|
+
if (list.length) {
|
|
193
|
+
return list[0]
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 成员模型
|
|
200
|
+
* @param {Object} m 原始的成员
|
|
201
|
+
*/
|
|
202
|
+
exports.member_model_out = function(m) {
|
|
203
|
+
var obj = {
|
|
204
|
+
"per_id": m.customId,
|
|
205
|
+
"per_name": m.name,
|
|
206
|
+
"idcardNum": m.nfc || '',
|
|
207
|
+
"img_url": m.avatar,
|
|
208
|
+
"idcardper": m.idcard,
|
|
209
|
+
// 1 待审核 | 2 已拒绝 | 3 已通过 | 4 黑名单
|
|
210
|
+
"per_type": m.type == 4 ? 2 : 0,
|
|
211
|
+
"usr_type": m.gm,
|
|
212
|
+
"gender": m.sex == 1 ? '男' : '女'
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (m.time_valid_end && m.time_valid_end > date && m.time_valid_end <= endDate) {
|
|
216
|
+
if (typeof(m.time_valid_start) == "object") {
|
|
217
|
+
obj.s_time = m.time_valid_start.toStr("yyyy-MM-dd hh:mm:ss");
|
|
218
|
+
} else {
|
|
219
|
+
obj.s_time = m.time_valid_start.toTime().toStr("yyyy-MM-dd hh:mm:ss");
|
|
220
|
+
}
|
|
221
|
+
if (typeof(m.time_valid_end) == "object") {
|
|
222
|
+
obj.e_time = m.time_valid_end.toStr("yyyy-MM-dd hh:mm:ss");
|
|
223
|
+
} else {
|
|
224
|
+
obj.e_time = m.time_valid_end.toTime().toStr("yyyy-MM-dd hh:mm:ss");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return obj
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 下发人员名单
|
|
232
|
+
* @param {String} clientid 设备ID
|
|
233
|
+
* @param {Object} user 人员信息
|
|
234
|
+
*/
|
|
235
|
+
exports.update_member = function(clientid, user) {
|
|
236
|
+
var member = this.member_model_out(user);
|
|
237
|
+
return this.push(clientid, member);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 批量下发人员名单
|
|
242
|
+
* @param {String} clientid 客户端ID
|
|
243
|
+
* @param {Array} list 人员名单
|
|
244
|
+
* @param {Number} longtime 超时回馈
|
|
245
|
+
*/
|
|
246
|
+
exports.update_member_batch = async function(clientid, list, longtime = 0) {
|
|
247
|
+
var list = [];
|
|
248
|
+
for (var i = 0; i < arr.length; i++) {
|
|
249
|
+
var user = list[i];
|
|
250
|
+
var res = await this.push(clientid, this.member_model_out(user));
|
|
251
|
+
var bl = false;
|
|
252
|
+
if (res.code == 0) {
|
|
253
|
+
bl = true;
|
|
254
|
+
}
|
|
255
|
+
list.push({
|
|
256
|
+
uuid: user.customId,
|
|
257
|
+
bl,
|
|
258
|
+
tip: res.reply || "删除成功"
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return list;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 播放语音
|
|
266
|
+
*/
|
|
267
|
+
exports.play_audio = function(clientid, type = 3) {
|
|
268
|
+
var body = {};
|
|
269
|
+
switch (type) {
|
|
270
|
+
case 1:
|
|
271
|
+
// 权限过期
|
|
272
|
+
body.file_name = "deadline.wav"
|
|
273
|
+
break;
|
|
274
|
+
case 2:
|
|
275
|
+
// 鉴权失败
|
|
276
|
+
body.file_name = "failure.wav"
|
|
277
|
+
break;
|
|
278
|
+
case 3:
|
|
279
|
+
// 鉴权成功
|
|
280
|
+
body.file_name = "success.wav"
|
|
281
|
+
break;
|
|
282
|
+
default:
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
body.type = 0;
|
|
286
|
+
var res = await this.push("trylisten_wav", clientid, body);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 初始化函数, 用于定义开放给前端的函数
|
|
292
|
+
*/
|
|
293
|
+
exports.init = function() {
|
|
294
|
+
var m = this.methods;
|
|
295
|
+
var _this = this;
|
|
296
|
+
|
|
297
|
+
m["mqtt_heartbeat"] = function(clientid, params) {
|
|
298
|
+
if (!_this.drives[clientid]) {
|
|
299
|
+
_this.drives[clientid] = {};
|
|
300
|
+
}
|
|
301
|
+
_this.drives[clientid].online = 1;
|
|
302
|
+
console.log("心跳", clientid, _this.drives[clientid]);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 在线通知
|
|
307
|
+
* @param {String} clientid 设备sn
|
|
308
|
+
* @param {Object} param 其他信息
|
|
309
|
+
*/
|
|
310
|
+
m["mqtt_online"] = async function(clientid, params) {
|
|
311
|
+
if (!_this.drives[clientid]) {
|
|
312
|
+
_this.drives[clientid] = {};
|
|
313
|
+
}
|
|
314
|
+
_this.drives[clientid].online = 1;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
m["RecPush"] = async function(clientid, params, msg, id) {
|
|
318
|
+
var info = msg.body;
|
|
319
|
+
"body": {
|
|
320
|
+
"e_imgsize": 13485,
|
|
321
|
+
"ext_sec": 1709089205,
|
|
322
|
+
"hat": -1,
|
|
323
|
+
"hcode_status": 0,
|
|
324
|
+
"idcard": "",
|
|
325
|
+
"img_data": "/9j/4AAQSkZJRgABAQIAdgB2AAD/7wAPAAAAAAAAAAAAAAAAAP",
|
|
326
|
+
"isRealtimeData": 601,
|
|
327
|
+
"isurl": false,
|
|
328
|
+
"mask": -1,
|
|
329
|
+
"matched": 93,
|
|
330
|
+
"name": "schmidt",
|
|
331
|
+
"name_base64": "c2NobWlkdA==",
|
|
332
|
+
"per_id": "1706099386778",
|
|
333
|
+
"per_id_base64": "MTcwNjA5OTM4Njc3OA==",
|
|
334
|
+
"role": 0,
|
|
335
|
+
"sequence": 27307,
|
|
336
|
+
"sn": "7560d2db-fd20feb7",
|
|
337
|
+
"tep": 0,
|
|
338
|
+
"usec": 1709118005
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
var type = 1;
|
|
342
|
+
switch (params.otype) {
|
|
343
|
+
// (1人脸验证|2远程开门|3智码开门|4刷卡验证)
|
|
344
|
+
case "7":
|
|
345
|
+
case "27":
|
|
346
|
+
type = 2;
|
|
347
|
+
break;
|
|
348
|
+
case "47":
|
|
349
|
+
case "48":
|
|
350
|
+
case "55":
|
|
351
|
+
case "56":
|
|
352
|
+
case "57":
|
|
353
|
+
type = 3;
|
|
354
|
+
break;
|
|
355
|
+
case "21":
|
|
356
|
+
case "22":
|
|
357
|
+
case "24":
|
|
358
|
+
case "25":
|
|
359
|
+
type = 4;
|
|
360
|
+
break;
|
|
361
|
+
default:
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
if (type == 2) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
// 1白名单|2黑名单
|
|
368
|
+
var person_type = params.PersonType == "1" ? 2 : 1;
|
|
369
|
+
var record_type = params.RecordType ? Number(params.RecordType) + 1 : 1;
|
|
370
|
+
|
|
371
|
+
// 拿到打卡人的姓名
|
|
372
|
+
var name = params.persionName || params.name;
|
|
373
|
+
if (!name) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
var customId = params.customId.trim();
|
|
377
|
+
var phone = (params.telnum || "").trim();
|
|
378
|
+
var idcard = (params.idCard || "").trim();
|
|
379
|
+
var nfc = (params.cardNum2 || params.RFIDCard || "").trim();
|
|
380
|
+
var time = params.time;
|
|
381
|
+
var avatar = "";
|
|
382
|
+
if (params.pic) {
|
|
383
|
+
avatar = params.pic;
|
|
384
|
+
}
|
|
385
|
+
var log = {
|
|
386
|
+
customId,
|
|
387
|
+
name,
|
|
388
|
+
phone,
|
|
389
|
+
idcard,
|
|
390
|
+
nfc,
|
|
391
|
+
clientid,
|
|
392
|
+
type,
|
|
393
|
+
person_type,
|
|
394
|
+
record_type,
|
|
395
|
+
time,
|
|
396
|
+
avatar
|
|
397
|
+
}
|
|
398
|
+
$.server.exec_log(clientid, log);
|
|
399
|
+
|
|
400
|
+
_this.send(`mqtt/face/${clientid}`, {
|
|
401
|
+
"messageId": _this.get_msgid('PushAck'),
|
|
402
|
+
"operator": "PushAck",
|
|
403
|
+
"info": {
|
|
404
|
+
"PushAckType": "2",
|
|
405
|
+
"SnapOrRecordID": params.RecordID
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
m["send_qr_msg"] = async function(clientid, params, msg, id) {
|
|
411
|
+
var qrcode = params.data;
|
|
412
|
+
var {
|
|
413
|
+
uuid,
|
|
414
|
+
pass,
|
|
415
|
+
tip,
|
|
416
|
+
device
|
|
417
|
+
} = $.server.exec_qrcode(clientid, qrcode);
|
|
418
|
+
if (device && device.online) {
|
|
419
|
+
await _this.unlock(clientid, uuid, pass, tip);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (tip) {
|
|
423
|
+
if (tip.indexOf("过期")) {
|
|
424
|
+
_this.play_audio(clientid, 1);
|
|
425
|
+
} else {
|
|
426
|
+
_this.play_audio(clientid, 2);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
3
|
+
"name": "ZS",
|
|
4
|
+
// mqtt 服务标题
|
|
5
|
+
"title": "新设备",
|
|
6
|
+
// mqtt 服务介绍
|
|
7
|
+
"description": "",
|
|
8
|
+
// 状态 0未启用,1启用
|
|
9
|
+
"state": 1,
|
|
10
|
+
// 订阅的主题
|
|
11
|
+
"topic": ["face/response", "qr/response", "online/response", "heartbeat/response"],
|
|
12
|
+
// 主题回复
|
|
13
|
+
"topic_receive": ["mqtt/face/${clientid}"],
|
|
14
|
+
// 给客户端推送的主题
|
|
15
|
+
"topic_push": "face/${clientid}/request",
|
|
16
|
+
// 接收方式
|
|
17
|
+
"qos": 1,
|
|
18
|
+
// 保持接收
|
|
19
|
+
"retain": true,
|
|
20
|
+
// 调用的脚本
|
|
21
|
+
"func_file": "./index.js",
|
|
22
|
+
// 客户端ID
|
|
23
|
+
"clientid": "sn",
|
|
24
|
+
// 消息ID
|
|
25
|
+
"msgid": "cmd_id",
|
|
26
|
+
// 请求方法
|
|
27
|
+
"method": "cmd",
|
|
28
|
+
// 参数
|
|
29
|
+
"params": "body",
|
|
30
|
+
// 结果
|
|
31
|
+
"result": "reply",
|
|
32
|
+
// 回复方法
|
|
33
|
+
"method_receive": "${method}"
|
|
34
|
+
}
|