chatbot_api_dev.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. //
  3. // !list
  4. //
  5. $dictResponse = array();
  6. $dictResponse["success"] = false;
  7. $dictResponse["status_code"] = 400;
  8. $dictResponse["status_description"] = "parameter missing";
  9. //
  10. // main - no interface
  11. //
  12. if ( !isset($_REQUEST["interface"]) || $_REQUEST["interface"] == "" ) {
  13. //
  14. $dictResponse = array();
  15. $dictResponse["success"] = true;
  16. $dictResponse["status_code"] = 200;
  17. $dictResponse["status_description"] = "ok";
  18. $data = "<b>Hello world!</b><br>
  19. weather information ;-)<br>
  20. <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"currentColor\" class=\"bi bi-cloud-drizzle\" viewBox=\"0 0 16 16\">
  21. <path d=\"M4.158 12.025a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317m6 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317m-3.5 1.5a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317m6 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317m.747-8.498a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 11H13a3 3 0 0 0 .405-5.973M8.5 2a4 4 0 0 1 3.976 3.555.5.5 0 0 0 .5.445H13a2 2 0 0 1 0 4H3.5a2.5 2.5 0 1 1 .605-4.926.5.5 0 0 0 .596-.329A4 4 0 0 1 8.5 2\"/>
  22. </svg>
  23. ";
  24. $dictResponse["response"] = "".$data;
  25. }
  26. //
  27. // interface: dev
  28. //
  29. if ( isset($_REQUEST["interface"]) && $_REQUEST["interface"] == "dev" ) {
  30. //echo "<pre>"; print_r($_REQUEST); echo "</pre>";
  31. //
  32. $dictResponse = array();
  33. $dictResponse["success"] = true;
  34. $dictResponse["status_code"] = 200;
  35. $dictResponse["status_description"] = "ok";
  36. //
  37. $arrEntries = array();
  38. $dictEntry = array();
  39. $dictEntry["id"] = "1";
  40. $dictEntry["name"] = "name 1";
  41. $arrEntries[] = $dictEntry;
  42. $dictEntry = array();
  43. $dictEntry["id"] = "2";
  44. $dictEntry["name"] = "name 2";
  45. $arrEntries[] = $dictEntry;
  46. //
  47. $dictResponse["entries"] = $arrEntries;
  48. }
  49. // JSON_HEX_APOS ???
  50. $output = json_encode($dictResponse, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
  51. //
  52. header('Content-Type: application/json');
  53. http_response_code($dictResponse["status_code"]);
  54. echo $output;
  55. //
  56. exit;
  57. ?>