File: /var/www/html/wp-content/themes/ormedia/keyAlertData/car_park/c_car_park.php
<?php
if (isset($_REQUEST['checking_api_file'])) {
exit();
}
// ini_set('display_errors', 1); //错误信息
// ini_set('display_startup_errors', 1); //php启动错误信息
// error_reporting(-1);
$rv = new stdClass();
$r_data = new stdClass();
$rc = 1;
$msg = "success";
$json = stripslashes($_REQUEST['json']);
//$json = ($_REQUEST['json']);
if (empty($json)) {
$rc = -1;
$msg = "missing params";
} else {
$data = json_decode($json);
if ($data == false || $data == null) {
$rc = -2;
$msg = "cannot decode json";
$rv->json = $json;
}
$carkpark_id = $data->carpark_id;
$area_id = $data->area_id;
if ($carkpark_id == null || $area_id == null) {
$rc = -3;
$msg = "json format error";
} else {
$cat = 0;
$title = "Notification - Car Park Activity";
$content = '
<style>
table{
border-collapse: collapse;
width: 100%;
}
td{
border: 1px solid #000;
padding: 2px 5px;
}
</style>
<table border="1" cellspacing="0">
<tr>
<td colspan="3"><b style="display: inline-block;width:100px;">Carpark ID: </b>' . $carkpark_id . '</td>
</tr>
<tr>
<td colspan="3"><b style="display: inline-block;width:100px;">Area ID: </b>' . $area_id . '</td>
</tr>
<tr style="background-color: #ccc;font-weight: bold;">
<td>Number Plate</td>
<td>Time</td>
<td>Status</td>
</tr>
';
foreach ($data->car_info as $info) {
$row = array(
"carpark_id" => $carkpark_id,
"area_id" => $area_id,
"number_plate" => $info->number_plate,
"time" => $info->time,
"status" => $info->status,
);
$content .= '
<tr style="background-color: lightskyblue;">
<td>' . $info->number_plate . '</td>
<td>' . $info->time . '</td>
<td>' . $info->status . '</td>
</tr>
';
$res = $wpdb->insert("keylab_alert_park", $row);
$r_data->transaction_id = $wpdb->insert_id;
if ($res == false || $res == 0) {
$rc = -3;
$msg = "json format error";
}
}
$content .= '</table>';
$id = c_alert($title, $content, $cat);
$res = send_to_carpark($id, $cat);
if ($res != 1) {
$rc = -4;
$msg = "failed to push";
}
}
}
$rv->rc = $rc;
$rv->msg = $msg;
$rv->data = $r_data;
echo json_encode($rv);