我选的框架是tp5.1
几个要点,做这个功能的肯定都有push文档。第一个路由对应到。 iclock/cdata。构造一个这样的路由。apache下,可以选择重写,也可以选择route改变路由。nginx下重写一下路由。基本就可以了。下面贴代码:
Cdata.php
<?php
namespace app\iclock\controller;
use think\Controller;
use think\Request;
class Cdata extends Controller
{
public function index()
{
//1.接收考勤机发来的消息
//2.存入数据到数据表
//3.返回考勤机需要的数据,并将这些数据存入考勤机,如果存在就更新
$text = json_encode($this->request->request());
file_put_contents('log.txt',$text.PHP_EOL,FILE_APPEND);
if($this->request->request('options') == 'all')
{
$return = "GET OPTION FROM : {$this->request->request('SN')}";
$array = [
'Stamp' => time(),
'OpStamp' => time(),
'PhotoStamp' => time(),
'ErrorDelay' => 30,
'Delay' => 30,
'TransTimes' => '12:00',
'TransInterval' => 1,
'TransFlag' => 0123456789,
'Realtime' => 1,
'Encrypt' => 0,
'ServerVer' => '2.32 '.date('Y-m-d'),
'TableNameStamp' => time(),
];
$unix_time = date_default_timezone_set('GMT');
header("HTTP/1.0 200 OK");
header("Content-Type: text/plain");
header("Date:".$unix_time);
$string = "";
foreach ($array as $key => $val)
$return .= $key .'='.$val.PHP_EOL;
return $return;
}
}
public function hello($name = 'ThinkPHP5')
{
return 'hello,' . $name;
}
}
getrequest.php
<?php
namespace app\iclock\controller;
use think\Controller;
use think\Request;
class Getrequest extends Controller
{
public function index()
{
$text = json_encode($this->request->request());
file_put_contents('log.txt',$text.PHP_EOL,FILE_APPEND);
$unix_time = date_default_timezone_set('GMT');
header("HTTP/1.1 200 OK");
header("Content-Type: text/plain");
header("Date:".$unix_time);
$cmd = "C:333:INFO ".PHP_EOL;
// $cmd .= "C:124:CHECK";
return $cmd;
}
public function hello($name = 'ThinkPHP5')
{
return 'hello,' . $name;
}
}
devidecmd.php
<?php
namespace app\iclock\controller;
use think\Controller;
use think\Request;
class Devicecmd extends Controller
{
public function index()
{
$text = json_encode(file_get_contents("php://input"));
file_put_contents('logcmd.txt',$text.PHP_EOL,FILE_APPEND);
$unix_time = date_default_timezone_set('GMT');
header("HTTP/1.1 200 OK");
header("Content-Type: text/plain");
header("Date:".$unix_time);
// $cmd = "C:1:SHELL CMD_STRING".PHP_EOL;
// return $cmd;
return 'OK';
}
public function hello($name = 'ThinkPHP5')
{
return 'hello,' . $name;
}
}
之后的逻辑可以自己按需求来写