前段时间做了个小试验,用Python 调用中控门禁并包装成webservice供移动设备调用。 移动端用的是泛微的OA企业微信端。
实现手机远程开门效果,拿着手机,走到哪,哪的门就自动开了,很屌的样子。
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ZK_Door_Helper.py
#
# Copyright (C) 2019 - xulong <[email protected]>
#
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"