-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
36 lines (31 loc) · 1.1 KB
/
server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
if(isset($_POST['FunCode']) && $_POST['FunCode']== '4000'){ //轮询请求
echo outPro(); //调用出货请求
}elseif (isset($_GET['new_pro'])) { //添加新的出货请求
$rand_filename = './products/'.rand(1000000,9999999);
file_put_contents($rand_filename, $_GET['new_pro']);
}
function outPro(){ //从products 目录 取出一个文件 读文件中的货道号并出货,出完货删除对应文件
$files = scandir("./products/");
foreach ($files as $file) {
if(count($files) == 2){
$info = '{ "Status": "0","MsgType":"3",Err":"暂无任务"}';
break;
}
if($file !== "." && $file !== ".."){
$pro = "./products/".$file;
$pro_id = file_get_contents($pro);
unlink($pro);
$TradeNo = date('YmdHis', time()).get_millisecond();
$info = '{ "Status": "0","MsgType":"0","TradeNo":"'.$TradeNo.'","SlotNo":"'.$pro_id.'","ProductID":"0","Err":"成功"}';
break;
}
}
return $info;
}
function get_millisecond(){ //生成一个时间用作订单号
list($usec, $sec) = explode(" ", microtime());
$msec=round($usec*1000);
return $msec;
}
?>