Skip to content

Instantly share code, notes, and snippets.

@samwize
Created October 22, 2012 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwize/3930494 to your computer and use it in GitHub Desktop.
Save samwize/3930494 to your computer and use it in GitHub Desktop.
Hoiio API Example: Conference Outgoing
<html>
<head>
<title>Hoiio Conference API</title>
</head>
<body style="font-family:arial,helvetica,sans-serif;font-size:13px;margin-top:20px;">
<?php
// Developer information: appId, accessToken
$appId = "YOUR_APP_ID_HERE";
$accessToken = "YOUR_ACCESS_TOKEN_HERE";
$server = "https://secure.hoiio.com/open";
if ($_SERVER['REQUEST_METHOD'] == "GET") {
// Exit PHP and print those UI
?>
<h1>Hoiio Conference API</h1>
<form id="conference" name="conference" action="conf-example.php" method="post">
<p>Enter at least 1 destination phone number in E.164 format. Example: +6511111111</p>
<input name="n1" type="text" /><br>
<input name="n2" type="text" /><br>
<input name="n3" type="text" /><br>
<input name="n4" type="text" /><br>
<input name="n5" type="text" /><br>
<input name="n6" type="text" /><br>
<input name="n7" type="text" /><br>
<input name="n8" type="text" /><br><br>
<input id="makeCall" type="submit" value="Make Conference Call">
</form>
<?php
// Back to PHP
return;
}
// String the destinations together, separated by comma
$dest = "";
for ($i=1; $i<=8; $i++) {
$val = $_POST['n'.$i];
if (strlen($val) > 0)
$dest .= $val . ',';
}
if (substr($dest, -1) == ',')
$dest = substr($dest, 0, -1);
// Call Hoiio Conference API
$params = array("app_id" => $GLOBALS['appId'],
"access_token" => $GLOBALS['accessToken'],
"dest" => $dest,
"room" => "myroom",
"tag" => "conference trial");
$data = http_build_query($params);
$response = do_post_request($GLOBALS['server']."/voice/conference", $data);
$result = json_decode($response);
if ($result->status != "success_ok")
echo "Error: " . $result->status . "<br>";
else
echo "Conference call is send out successfully<br>";
echo '<br><a href="conf-example.php">back</a><br>';
return;
// Source adapted from http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl
// This function will do the http post to the server, feel free to use different function of your desire
function do_post_request($url, $data) {
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment