Created
November 27, 2015 15:08
-
-
Save wiesson/0da717936a54c5443038 to your computer and use it in GitHub Desktop.
Click 2 Call - XML RPC Example with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!extension_loaded('xmlrpc')) { | |
echo "PHP xmlrpc extension is not available."; | |
die; | |
} | |
function call($remoteUri, $localUri, $username, $password) | |
{ | |
$requestParameter = array( | |
'RemoteUri' => sprintf('sip:%[email protected]', $remoteUri), | |
'LocalUri' => sprintf('sip:%[email protected]', $localUri), | |
'TOS' => 'voice' | |
); | |
$auth = base64_encode(sprintf('%s:%s', $username, $password)); | |
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter); | |
$context = stream_context_create( | |
array('http' => array( | |
'method' => "POST", | |
'header' => sprintf("Content-Type: text/xml\r\nAuthorization: Basic %s)", $auth), | |
'content' => $request | |
)) | |
); | |
file_get_contents("https://api.sipgate.net/RPC2", false, $context); | |
} | |
$remoteUri = isset($_POST['remoteUri']) ? $_POST['remoteUri'] : false; | |
$error = false; | |
if ($remoteUri !== null) { | |
if(is_numeric($remoteUri)) { | |
call($remoteUri, "<YOUR SIPGATE PHONENUMBER>", "<YOUR SIPGATE ACCOUNT LOGIN>", "<YOUR SIPGATE ACCOUNT PASSWORD>"); | |
} else { | |
$error = true; | |
} | |
} | |
?> | |
<!doctype HTML> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Click to Call</title> | |
<style> | |
body { | |
font-family: sans-serif; | |
margin: 0 auto; | |
padding: 20px; | |
max-width: 400px; | |
} | |
h4 { | |
text-align: center; | |
} | |
form > label, form > input, form > button { | |
display: block; | |
width: 100%; | |
} | |
form > label { | |
padding-left: 12px; | |
margin-bottom: 6px; | |
} | |
form > input, form > button[type=submit] { | |
padding: 12px; | |
line-height: 22px; | |
font-size: 18px; | |
border: none; | |
} | |
form > input { | |
color: #333; | |
border-radius: 0; | |
background-color: #EEE; | |
box-sizing: border-box; | |
margin-bottom: 26px; | |
} | |
form > button[type=submit] { | |
cursor: pointer; | |
background-color: #562961; | |
color: white; | |
transition: all 0.3s; | |
font-weight: 700; | |
} | |
form > button[type=submit]:hover { | |
background-color: rgba(0, 0, 0, 0.1); | |
color: #562961; | |
} | |
.invalid input { | |
outline-color: red; | |
animation: shake .5s linear; | |
color: red; | |
} | |
@-webkit-keyframes shake { | |
8%, 41% { | |
-webkit-transform: translateX(-10px); | |
} | |
25%, 58% { | |
-webkit-transform: translateX(10px); | |
} | |
75% { | |
-webkit-transform: translateX(-5px); | |
} | |
92% { | |
-webkit-transform: translateX(5px); | |
} | |
0%, 100% { | |
-webkit-transform: translateX(0); | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<h4>Click to Call example</h4> | |
<form action="" method="POST" class="<?php if($error) { echo "invalid"; } ?>"> | |
<label for="remoteUri">Number</label> | |
<input id="remoteUri" type="text" name="remoteUri" value="<?php echo $remoteUri; ?>" placeholder="49123456789"> | |
<button type="submit">Click to Call</button> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment