Skip to content
Snippets Groups Projects
Commit 7e4337f9 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

add php for api call

parent e71aa8b6
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ import org.apache.http.impl.client.HttpClients;
public class RfidTimerReaderService implements JavaDelegate {
public static final String GET_HTTP_RFID_API = "http://localhost/postserver/rfidtest.json";
public static final String GET_HTTP_RFID_API = "http://zeit-bis.de/api/rfid.php?action=get";
private final Logger LOGGER = LoggerFactory.getLogger(RfidTimerReaderService.class);
......@@ -36,7 +36,7 @@ public class RfidTimerReaderService implements JavaDelegate {
String rfidTag = jo.getString("tagId");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(jo.getString("timeStamp"));
LOGGER.info("Starting product review with rfid tag {" + rfidTag + "}");
LOGGER.info("Starting product review with rfid tag {" + rfidTag + "} Date:" + date.toString());
// Create new Process
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("rfidTag", rfidTag);
......@@ -49,7 +49,7 @@ public class RfidTimerReaderService implements JavaDelegate {
}
private Optional<HttpResponse> sendHTTPRequest() {
LOGGER.info("Message send:");
LOGGER.info("Message sending..");
HttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet(GET_HTTP_RFID_API);
get.setHeader("content-type", "application/json");
......
......@@ -9,7 +9,8 @@ public class RfidProductService {
static {
rifdProductMap.put("12345678", "Pizza");
rifdProductMap.put("87654321", "Doener");
rifdProductMap.put("87654321", "Döner");
rifdProductMap.put("12121212", "Spaghetti");
}
private RfidProductService() {
......
<?php
$filename = 'data.json';
// test request type
$action = 'default';
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
}
if ($action === 'append') {
// append new rfid tag entry to json file
// rfid tag id
if (isset($_REQUEST['tagId'])) {
$tagId = $_REQUEST['tagId'];
// current timestamp
date_default_timezone_set("Europe/Berlin");
$timeStampJson = '"timeStamp": "' . date("Y-m-d H:i:s") . '"';
$rfidTagJson = '"tagId" : "' . $tagId . '"';
// new json tag
$newJson = '{' . $rfidTagJson . ',' . $timeStampJson . '}';
// save new json
$currentJson = str_replace(']', '', file_get_contents($filename));
// only append, if tag is not in the current file
if (strpos($currentJson, $tagId) === false) {
if ($currentJson !== '[') {
$currentJson .= ',';
}
$currentJson .= $newJson . ']';
// write file
file_put_contents($filename, $currentJson);
}
}
} else if ($action === 'get') {
// get the current rfid tag
$content = file_get_contents($filename);
echo $content;
// clear file /(empty json array)
file_put_contents($filename, "[]");
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment