Backend Service

This commit is contained in:
2019-03-09 01:43:35 +00:00
parent c91ab83752
commit d1f697b738
+28 -2
View File
@@ -38,6 +38,16 @@ if (array_search($_SERVER['REQUEST_METHOD'], $methods) === false) {
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($endpoint == "uploadfile") {
upload_file_call();
exit();
} else {
$raw_json = file_get_contents("php://input");
$raw_array = json_decode($raw_json, true);
$in = flatten($raw_array);
}
}
// $in["action"] = MERMS_USER_CREATEACCOUNT;
$in["loc"] = $_SERVER["REMOTE_ADDR"];
@@ -45,8 +55,8 @@ switch ($endpoint) {
case 'userlogin':
case 'login':
$in["action"] = MERMS_USER_LOGIN;
$in["account_no"] = "7702222222";
$in["password"] = "1234";
//$in["account_no"] = "7702222222";
//$in["password"] = "1234";
break;
case 'createuser':
$in["action"] = MERMS_USER_CREATEACCOUNT;
@@ -101,12 +111,28 @@ switch ( $in["action"] ) {
break;
}
// calling the backend
$out["internal_return"]= $mermsemr->mermsemr_api($in,$out);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
//$out = array_merge($in, $out); // DEBUG
echo json_encode(processOutJson($in, $out));
exit();
function flatten($data, $parentkey = "") {
$result = array();
foreach ($data as $key => $val) {
if (is_array($val)) {
$result = array_merge($result, flatten($val, $parentkey . $key . "_"));
} else {
$result[$parentkey . $key] = $val;
}
}
return $result;
}
function processOutJson($in, $out) {
switch ($in["action"]) {