微信小程序 连接ZKT中控指纹打卡机
1.在Centos环境下安装必要的库
项目地址:https://github.com/fananimi/pyzk
里面有安装教程
www.feelsight.cn 版权所有
需要安装flask
yum install python-flask
2.安装python3环境
可以参考https://feelsight.cn/post/118.html
3.新建一个python脚本
import sys import os import logging from flask import Flask, request
# www.feelsight.cn 版权所有
app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='zkt_log.log',
filemode='a')
sys.path.insert(1,os.path.abspath("/usr/local/lib/python3.6/site-packages"))
from zk import ZK, const
# 设备列表
dooriplist = ('192.168.1.50','192.168.1.51','192.168.1.52','192.168.1.53','192.168.1.54')
# 微信小程序用户ID列表,代表控制门的权限
weixinid = ('otLcT5ITB6ubK4-RkAe8T0','')
def zktopen(ipadd,times):
conn = None
# 需要修改相应的端口号和通讯密码
zk = ZK(ipadd, port=4370, timeout=5, password=, force_udp=False, ommit_ping=False)
try:
# connect to device
conn = zk.connect()
if conn.unlock(time=times):
return True
except Exception as e:
print ("Process terminate : {}".format(e))
return False
finally:
if conn:
conn.disconnect()
def DataCheck(id,num,times):
for idstr in weixinid:
if idstr == id:
if int(num) < len(dooriplist) :
if int(times) < 100 :
return True
return False
@app.route('/')
def hello_world():
# zktopen('192.168.1.53',5)
return 'hello world'
@app.route('/register', methods=['POST'])
def register():
# print (request.headers)
# print (request.form)
doornum = request.form['num']
userid = request.form['id']
times = request.form['time']
logging.info('From:'+str(request.form)+' id:'+userid+' doornum:'+doornum+' time:'+times)
print('doornum:'+doornum+' id:'+userid)
print(dooriplist[int(doornum)])
if DataCheck(userid,doornum,times) :
print('check ok')
if True == zktopen(dooriplist[int(doornum)],int(times)) :
print('open ok')
return 'welcome'
else:
print('check err')
return 'check err'
# print (request.form.get('name')) www.feelsight.cn 版权所有
# print (request.form.getlist('name'))
# print (request.form.get('nickname', default='little apple'))
#do something else
#
#
if __name__ == '__main__':
app.run(host='0.0.0.0',port=80,debug=True)
4.运行脚本测试服务是否正常
www.feelsight.cn 版权所有
直接在浏览器输入服务器地址看看浏览器是否有hello word字符串
如果出现则表示成功一半了
5.测试锁是否能正常打开
本连接使用的是post请求方式, www.feelsight.cn 版权所有
num: "0",//门锁的索引,前面门锁的IP地址列表里面的第几个 id: this.data.openid,//微信用户的ID time: this.data.opentime,//开门时间 www.feelsight.cn 版权所有
6.微信小程序代码
https://feelsight.cn/zb_users/upload/2021/07/20210726161840_44528.zip
- 随机文章
- 热门文章
- 热评文章






