首页 > 免费电话教程 > 傻瓜式搭建自己的sip通用回拨

201405月24

傻瓜式搭建自己的sip通用回拨

作者:admin 7 Comments 发表评论

本文转载自凌霄论坛,为一技术文章,基本能看懂,但是不知道为什么CURL要设置那些项目,SSY也不知道是什么玩意,懂的可以加我讨论!原作者的代码不知道是不是他自己写的!请自行测试,过段时间我也测试个!

【准备】

ssy账号一个,支持curl的php空间一个

【开始】

第一步:用ssy账号登录SSY控制面板

第二步:点击【Setting】->【Click here to show your API key】查看并负责你的API Key

第三步:将下面的代码复制保存为【sip.php】

第四步:将ssy账号名称及API Key配置到【sip.php】并将【sip.php】上传到你的网站空间根目录(推荐)

第五步:访问http://你的域名/sip.php?firstrun=true初始化程序,如我的是http://sovi.cc/sip.php?firstrun=true

第六步:现在就可以配置你的sip账号到你的sip回拨平台(http://你的域名/sip.php)上打回拨电话了!

代码如下:

<?php
header(“Content-Type: text/html;charset=utf-8”);
//配置信息

$apiKey= “4029ad2f40e99bcc53e964b842fec99999999614bfb57c2770f6b83d7e8fde575482acaf6eadb374f999ebbf59897b8f”;//你的ssy帐号的apiKey
$account=”myaccount”;//你的ssy帐号

$user=$_REQUEST[“user”];
$pass=$_REQUEST[“pass”];
$server=$_REQUEST[“server”];

function GetProviderID(){
global $apiKey;
$url=”https://www.sipsorcery.com/rest/v0.1/provisioning.svc/sipprovider/get”;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIE, “apikey=”.$apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
$result=json_decode($result,true);

return $result[‘Result’][0][‘ID’];
}
function UpdateProvider($ID){
global $apiKey;
global $account;
global $user;
global $pass;
global $server;

$url=”https://www.sipsorcery.com/rest/v0.1/provisioning.svc/sipprovider/update”;

$body=json_encode(array(“ID”=>$ID,
“ProviderName”=>”myProvider”,
“ProviderUsername”=>$user,
“ProviderPassword”=>$pass,
“ProviderServer”=>$server,
“ProviderAuthUsername”=>null,
“ProviderOutboundProxy”=>null,
“ProviderType”=>”SIP”,
“ProviderFrom”=>null,
“CustomHeaders”=>null,
“RegisterContact”=>”sip:{$account}@sipsorcery.com”,
“RegisterExpiry”=>3600,
“RegisterServer”=>null,
“RegisterRealm”=>null,
“RegisterEnabled”=>true,
“GVCallbackNumber”=>null,
“GVCallbackPattern”=>null,
“GVCallbackType”=>null)
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/json; charset=utf-8”));
curl_setopt($ch, CURLOPT_COOKIE, “apikey=”.$apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($ch);
curl_close($ch);
$result=json_decode($result,true);

return $result[‘Success’];
}
function GetDialPlanID(){
global $apiKey;
$url=”https://www.sipsorcery.com/rest/v0.1/provisioning.svc/dialplan/get”;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIE, “apikey=”.$apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
$result=json_decode($result,true);

return $result[‘Result’][0][‘ID’];
}
function UpdateDialPlan($ID){
global $apiKey;
$url=”https://www.sipsorcery.com/rest/v0.1/provisioning.svc/dialplan/update”;

$body=json_encode(array(“ID”=>$ID,
“DialPlanName”=>”webcallback”,
“TraceEmailAddress”=>null,
“DialPlanScript”=>”str=req.URI.User.to_s\r\ncaller = str.split(‘,’)\r\nsys.Callback(\”#{caller[0]}@myProvider\”,\”#{caller[1]}@myProvider\”)”,
“ScriptTypeDescription”=>”Ruby”,
“AcceptNonInvite”=>False)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/json; charset=utf-8”));
curl_setopt($ch, CURLOPT_COOKIE, “apikey=”.$apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($ch);
curl_close($ch);
$result=json_decode($result,true);

return $result[‘Success’];
}
if($_GET[“firstrun”]==”true”){
if(UpdateDialPlan(GetDialPlanID())){
die(“程序初始化完成,欢迎<a href='”.$_SERVER[‘SCRIPT_NAME’].”‘>使用</a>!”);
}else{
die(“程序初始化失败,请检查apiKey!”);
}
}
?>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/>
<title>Sovi通用SIP回拨平台</title>
</head>
<body>
<center><h2>SIP通用回拨平台</h2>
<form action=”sip.php” method=”post”>
<p>SIP:<input name=”server” type=”text” value=”<?php echo $_REQUEST[“server”];?>”></p>
<p>用户:<input name=”user” type=”text” value=”<?php echo $_REQUEST[“user”];?>”></p>
<p>密码:<input name=”pass” type=”text” value=”<?php echo $_REQUEST[“pass”];?>”></p>
<p>主叫:<input name=”caller” type=”text” value=”<?php echo $_REQUEST[“caller”];?>”></p>
<p>被叫:<input name=”called” type=”text” value=”<?php echo $_REQUEST[“called”];?>”></p>
<input name=”sovi” type=”submit” value=”Call”>
</form>
<?php
if($_POST[‘sovi’]==”Call”){
if(UpdateProvider(GetProviderID($ID))){
echo “SIP信息已提交<br/>”;
}else{
die(“SIP信息提交失败<br/>”);
}
$url=’https://www.sipsorcery.com/callmanager.svc/webcallback?user=’.$account.’&number=’.$_REQUEST[“caller”].’,’.$_REQUEST[“called”];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result=curl_exec($ch);
curl_close($ch);
if(strstr($result,”Web call was successfully initiated”)!=False){
echo “呼叫请求已提交,请等待来电”;
}else{
echo “发起呼叫失败!”;
}
}
?>
<hr/>
Code By:创建者名字<br/>
QQ:创建者QQ号码<br/>
<?php echo date(‘Y-m-d H:i:s’,time());?>
</center>
</body>
</html>

代码也可以直接下载:http://pan.baidu.com/share/link?shareid=1803133734&uk=907001332

推荐阅读相关文章:免费电话教程

本文地址:http://www.mianfeidianhua.net/dajian-sip.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

7 Responses to “傻瓜式搭建自己的sip通用回拨”

  1. #1 寒冰 回复 | 引用 Post:2014-05-24 15:27

    学习了,不过貌似ssy不开放免费注册了啊

  2. #2 轩辕银河 回复 | 引用 Post:2014-05-25 08:35

    还是直接用软件来的直接

  3. #3 蒙洛 回复 | 引用 Post:2014-05-26 09:48

    不知道在哪注册ssy?没有搜索到啊。求指教

    • #4 admin 回复 | 引用 Post:2014-05-26 13:07

      我也没有玩过SSY,听说现在不能注册了,你可以去淘宝搜索看看有没有卖这个账号的!

  4. #5 GG 回复 | 引用 Post:2014-05-28 07:31

    我几年前注册了SSY账号,一直没用过,昨天登陆网站,账号竟然还有效。

  5. #6 GG 回复 | 引用 Post:2014-05-28 07:45

    sipsorcery.com,就是这个网站,当时搞了一下,觉得这个东西好复杂,就没有搞了,现在觉得国外的网站比国内好,你的账号四五年不使用都不会注销。本贴的原作者搞了个无限5分钟和无限10分钟打电话,也想试试,但是找不到资源,有知道的朋友吗?

    • #7 admin 回复 | 引用 Post:2014-05-28 08:23

      国外的网站确实比较好,稳定性强很多。不过现在国内的免费回拨比较多,稳定性不怎么样。

发表评论