0
JSON-RPC HTTP 서비스를 만들려고합니다. POST 메서드를 사용하고 있습니다.PHP 간단한 JSON-RPC
rest.php
<?php
header('Content-Type: application/json');
$input = file_get_contents("php://input");
$json = json_decode($input);
$output = $json->num + 10;
echo json_encode($output);
?>
입력 :
{"num": 10 }
출력 :
20
가 지금은 더 만족 구현하기 위해 노력하고 hods, 그래서 나는이 같은 입력을 사용할 수 있습니다
public function add($n1, $n2) {
return $n1 + $n2;
}
Q : 어떻게라는 방법을 결정하고 나머지를 실행하는
{ "method":"add", "params": { "num1": 15, "num2": 10 } }
그래서 내가 rest.php에 기능을 추가 할 수 있습니다. 새로운 입력으로 PHP?
편집 :
<?php
header('Content-Type: application/json');
$input = file_get_contents("php://input");
$json = json_decode($input);
foreach ($json->params as $param) {
$params[] = $param;
}
$output = call_user_func_array($json->method, $params);
echo json_encode($output);
function add($n1, $n2) {
return $n1 + $n2;
}
내 테스트를 원래 게시물에 추가했습니다. –