前段时间做了个小试验,用Python 调用中控门禁并包装成webservice供移动设备调用。 移动端用的是泛微的OA企业微信端。

实现手机远程开门效果,拿着手机,走到哪,哪的门就自动开了,很屌的样子。  

 

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ZK_Door_Helper.py
#
# Copyright (C) 2019 - xulong <fangkailove@yeah.net>
#
from soaplib.service import rpc
from soaplib.service import DefinitionBase
from soaplib.serializers.primitive import String, Integer

from soaplib.wsgi import Application
from soaplib.serializers.clazz import Array

import win32com.client




'''
中控门禁控制web服务

'''

class ZK_Door_Helper_Srv(DefinitionBase):
    @rpc(String,  _returns=String)
    def open(self, macip):
        '''
            call example for E8 mobile
            Mobile_NS.callWebService({
                endpoint : "http://192.168.126.xxx:7789/",
                operationName : "open",
                parameters : [
                                {
                                    name : "macip",
                                    type : "String",
                                    value : "192.168.122.xxx"
                                }
                ],
                callbackFn : function(result){
                    alert("webservice result:" + result);
                }
            });
        
        '''
        zk = win32com.client.Dispatch('zkemkeeper.ZKEM') #通过调用中控com组件控制门禁设备开门
        rlt = ""
        if zk.Connect_Net(macip,4370):
            rlt= "connected"
            if zk.ACUnlock(1,100):
                rlt= "success!! open the door"
            else:
                rlt= "faild!! open the door"
        else:
            rlt= "faild!! connected"

        del zk

        return rlt

if __name__=='__main__':
    try:
        from wsgiref.simple_server import make_server
        server = make_server('192.168.126.xxx', 7789, Application([ZK_Door_Helper_Srv], 'tns'))
        server.serve_forever()
    except ImportError:
        print "Error: example server code requires Python >= 2.5"

请注明转自:https://blog.csdn.net/fangkailove/article/details/90017664

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐