index.php
3.23 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
date_default_timezone_set("Asia/Taipei");
$date = date_create();
$time = date_format($date, 'Y-m-d H:i:s');
$link = mysqli_connect("10.10.10.237", "root", "SANlien<03051501>", "practice");
if (mysqli_connect_errno()) {
//printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//printf("#connect successfully<br><br>\n");
if(isset($_GET["inst"]))
{
$serial = "\"".$_GET["inst"]."\"";
if( !(isset($_GET["code"])))
{
//echo "not API<br>";
$query = "SELECT OpCode FROM status WHERE SerialNo = $serial";
//echo "#query <br> => <br> $query<br><br>";
if ($result = mysqli_query($link, $query))
{
if ($row = mysqli_fetch_row($result))
{
$service_code = "\"$row[0]\"";
echo "service_code:$row[0]";
//echo "<br><br>insert service_code to log<br>";
$query = "INSERT INTO log(Time,SerialNo,OpCode) VALUES (\"$time\", $serial, $service_code)";
//echo "#query <br> => <br> $query<br><br>";
mysqli_query($link, $query);
//printf("Insert New Record sucessfully<br>");
}
else
{
//echo "<br><br>insert wrong service_code to log<br>";
$query = "INSERT INTO log(Time,SerialNo,OpCode,msg) VALUES (\"$time\", $serial, \"\",\"wrong serial\")";
mysqli_query($link, $query);
//printf("Insert New wrong record sucessfully<br><br>");
}
mysqli_free_result($result);
mysqli_free_result($row);
}
}
else
{
//echo "is API<br>";
$service_code = "\"".$_GET["code"]."\"";
if($service_code == "\"666\"")
{
//echo "<br>insert API's service code to log<br>";
$query = "INSERT INTO log(Time,SerialNo,OpCode) VALUES (\"$time\", $serial, $service_code)";
mysqli_query($link, $query);
//printf("Insert into log sucessfully<br><br>");
//printf("update status to 666<br>");
$query="UPDATE status SET OpCode = $service_code WHERE SerialNo = $serial";
mysqli_query($link, $query);
//printf("update successfully.<br>Affected rows (UPDATE): %d<br>", mysqli_affected_rows($link));
}
else if($service_code == "\"400\"")
{
if(isset($_GET["msg"]))
{
$msg="\"".$_GET["msg"]."\"";
$query = "INSERT INTO log(Time,SerialNo,OpCode,msg) VALUES (\"$time\", $serial, $service_code,$msg)";
mysqli_query($link, $query);
//printf("Insert 400 sucessfully<br><br>");
//printf("update status to 000<br>");
$query="UPDATE status SET OpCode = \"000\" WHERE SerialNo = $serial";
mysqli_query($link, $query);
//printf("update successfully.<br>Affected rows (UPDATE): %d<br>", mysqli_affected_rows($link));
}
}
else if($service_code == "\"777\"")
{
//echo "<br>insert API's service code to log<br>";
$query = "INSERT INTO log(Time,SerialNo,OpCode) VALUES (\"$time\", $serial, $service_code)";
mysqli_query($link, $query);
//printf("Insert into log sucessfully<br><br>");
//printf("update status to 000<br>");
$query="UPDATE status SET OpCode = \"000\" WHERE SerialNo = $serial";
mysqli_query($link, $query);
//printf("update successfully.<br>Affected rows (UPDATE): %d<br>", mysqli_affected_rows($link));
}
}
}
else
{
//printf("no serial");
}
mysqli_close($link);
?>