Guest User

Untitled

a guest
Mar 1st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2.  
  3. //Define an Adhearsion PHP class for a REST HTTP connection
  4. class Adhearsion {
  5.  
  6. public $url;
  7. public $username;
  8. public $password;
  9.  
  10. function __construct($url, $username, $password) {
  11. $this->url = $url;
  12. $this->username = $username;
  13. $this->password = $password;
  14. }
  15.  
  16. function invoke($method_name) {
  17. $json = json_encode(array_slice(func_get_args(), 1));
  18.  
  19. $url = "$this->url/$method_name";
  20. return json_decode(http_post_data($url,
  21. $json,
  22. array("httpauth" => "$this->username:$this->password")));
  23. }
  24.  
  25. }
  26.  
  27. //Connect to the REST API of Adhearsion
  28. $ahn = new Adhearsion("localhost:5000", "jicksta", "roflcopterz");
  29.  
  30. //Build an array of the options for calling
  31. $call_options = array ('channel' => 'SIP/303',
  32. 'context' => 'inbound',
  33. 'exten' => '1000',
  34. 'priority' => '1',
  35. 'async' => 'true',
  36. 'variable' => 'destination=304');
  37.  
  38. //Invoke the Adhearsion originate method via an HTTP POST of a JSON object
  39. $ahn->invoke("originate", $call_options);
  40. ?>
Add Comment
Please, Sign In to add comment