当前位置:首页 > 电子 > 正文内容

微信小程序 连接ZKT中控指纹打卡机

admin4年前 (2021-07-07)电子4515


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


扫描二维码推送至手机访问。

版权声明:本文由视觉博客发布,如需转载请注明出处。

本文链接:https://feelsight.cn/post/119.html

“微信小程序 连接ZKT中控指纹打卡机” 的相关文章

STM32 keil mdk启动代码发分析

在启动文件我们看到了__main和用户写的main,这2个是有区别的,大概流程如下: 1、复位第一条指令:Reset_Handler   PROC,这里指定为 LDR     R0, =__main。表示调用...

STM32 中断向量表的位置 、重定向

STM32 中断向量表的位置 、重定向

这篇文章已经说了STM32的启动过程: https://feelsight.cn/post/39.html 我们也知道怎么跳到main函数了,那么,中断发生后,又是怎么跑到中断入口地址的呢? 从stm32f10x.s可以看到,已经定义好了一大堆...

ESP8266在Eclipse下设置编译模式(有boot和无boot)

ESP8266在Eclipse下设置编译模式(有boot和无boot)

更改编译模式可以更改Makefile文件中的 BOOT?=new APP?=1 SPI_SPEED?=40 SPI_MODE?=QIO SPI_SIZE_MAP?=2 可以根据2A-ESP8266__IOT_SDK_User_Manual__CN_...

FAT32文件格式详解

FAT32文件格式详解

说明: MBR :Master Boot Record ( 主引导记录)  DBR :DOS Boot Record ( 引导扇区) ...

ESP8266发送HTTP请求GET请求POST请求

ESP8266发送HTTP请求GET请求POST请求

一、ESP8266简介   ESP8266 是深圳安信可科技有限公司开发的基于乐鑫ESP8266的超低功耗的UART-WIFI模块的模组,可以方便进行二次元开发,接入云端服务,实现手机3/4G全球随时随地的控制,加速产品原型设计。  &em...

stc-isp烧录 下载 协议 过程分析

一、数据封装格式 包头 标示 数据包长度 命令字...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。