mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 10:24:26 +01:00
Added JSON Response handling to PHP software
Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
364a1f36fc
commit
270943e388
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
function tellLock( $pCommand, $pUser, $pPass, $pToken, $pIp ){
|
function tellLock($pCommand, $pUser, $pPass, $pToken, $pIp){
|
||||||
|
|
||||||
$json = '{
|
$json = '{
|
||||||
"user":' . json_encode( $pUser ) . ',
|
"user":' . json_encode( $pUser ) . ',
|
||||||
@ -98,13 +98,15 @@
|
|||||||
$isApi = true;
|
$isApi = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lSuccess = tellLock($pCommand, $pUser, $pPass, $pToken, $pIp);
|
$jsonResponse = json_decode(tellLock($pCommand, $pUser, $pPass, $pToken, $pIp), true);
|
||||||
|
if ($jsonResponse == null || !isset($jsonResponse['message']) || !isset($jsonResponse['code'])) {
|
||||||
if ($lSuccess == 0) {
|
|
||||||
$showSuccess = true;
|
|
||||||
} else {
|
|
||||||
$failureMsg = err2str($lSuccess);
|
|
||||||
$showFailure = true;
|
$showFailure = true;
|
||||||
|
$failureMsg = 'Error parsing JSON response';
|
||||||
|
} else {
|
||||||
|
$failureMsg = $jsonResponse['message'];
|
||||||
|
$code = $jsonResponse['code'];
|
||||||
|
$showSuccess = ($code == 0);
|
||||||
|
$showFailure = !$showSuccess;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$failureMsg = 'Invalid Request';
|
$failureMsg = 'Invalid Request';
|
||||||
@ -198,6 +200,6 @@ if ($isApi == false) {
|
|||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
} else {
|
} else {
|
||||||
echo $lSuccess;
|
echo $code;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user