[7808] | 1 | <?php |
---|
| 2 | |
---|
| 3 | $serverUrl = $_REQUEST['serverUrl']; |
---|
| 4 | $methodType = $_REQUEST['methodType']; |
---|
| 5 | $params = $_REQUEST['params']; |
---|
| 6 | $id = ( $_REQUEST['id'] ) ? $_REQUEST['id'] : time(); |
---|
| 7 | |
---|
| 8 | $data = "id=".$id."¶ms=" . stripslashes($params); |
---|
| 9 | |
---|
| 10 | function callJSONRPC($url, $data, $method) |
---|
| 11 | { |
---|
| 12 | $ch = curl_init(); |
---|
| 13 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
---|
| 14 | |
---|
| 15 | if($method == "POST"){ |
---|
| 16 | curl_setopt($ch, CURLOPT_POST, 1); |
---|
| 17 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
---|
| 21 | curl_setopt($ch, CURLOPT_URL, $url); |
---|
| 22 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded")); |
---|
| 23 | |
---|
| 24 | $result = curl_exec($ch); |
---|
| 25 | $errorCode = curl_getinfo($ch,CURLINFO_HTTP_CODE); |
---|
| 26 | $lastURL = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL); |
---|
| 27 | |
---|
| 28 | curl_close($ch); |
---|
| 29 | |
---|
| 30 | switch($errorCode) |
---|
| 31 | { |
---|
| 32 | case 200: |
---|
| 33 | break; |
---|
| 34 | case 404: |
---|
| 35 | $result = json_encode(array("error" => array("code" => 404, "message" => "RECURSO NAO ENCONTRADO => $lastURL"))); |
---|
| 36 | break; |
---|
| 37 | case 500: |
---|
| 38 | $result = json_encode(array("error" => array("code" => 500, "message" => "ERRO INTERNO. CONSULTE O LOG DO SERVIDOR"))); |
---|
| 39 | break; |
---|
| 40 | default: |
---|
| 41 | $result = json_encode(array("error" => array("code" => -1, "message" => "ERRO DESCONHECIDO. CONSULTE O LOG DO SERVIDOR"))); |
---|
| 42 | break; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | return $result; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | $result = callJSONRPC($serverUrl, $data, $methodType); |
---|
| 49 | |
---|
| 50 | echo $result; |
---|
| 51 | ?> |
---|