1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 02:14:26 +01:00

Added JSON Response handling to PHP software

Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
Ralf Ramsauer 2015-09-23 16:54:39 +02:00
parent 364a1f36fc
commit 270943e388

View File

@ -1,5 +1,5 @@
<?php
function tellLock( $pCommand, $pUser, $pPass, $pToken, $pIp ){
function tellLock($pCommand, $pUser, $pPass, $pToken, $pIp){
$json = '{
"user":' . json_encode( $pUser ) . ',
@ -98,13 +98,15 @@
$isApi = true;
}
$lSuccess = tellLock($pCommand, $pUser, $pPass, $pToken, $pIp);
if ($lSuccess == 0) {
$showSuccess = true;
} else {
$failureMsg = err2str($lSuccess);
$jsonResponse = json_decode(tellLock($pCommand, $pUser, $pPass, $pToken, $pIp), true);
if ($jsonResponse == null || !isset($jsonResponse['message']) || !isset($jsonResponse['code'])) {
$showFailure = true;
$failureMsg = 'Error parsing JSON response';
} else {
$failureMsg = $jsonResponse['message'];
$code = $jsonResponse['code'];
$showSuccess = ($code == 0);
$showFailure = !$showSuccess;
}
} else {
$failureMsg = 'Invalid Request';
@ -198,6 +200,6 @@ if ($isApi == false) {
</html>
<?php
} else {
echo $lSuccess;
echo $code;
}
?>