[英]Validate user when they try to call phone number with nexmo in laravel
[英]App-to-Phone call Nexmo
我是Nexmo的新手,我正尝试建立一个应用程序通话。 移动Ionic / Cordova应用程序的用户通过互联网发起语音呼叫,电话在PSTN上响铃。 被叫方回答,双方都可以讲话和收听。
现在,我已经设置了服务器,并且可以在PSTN上拨打电话,可以接听电话了,还可以使用NCCO向被叫方说短信。
但是,我无法弄清楚如何在调用方客户端上处理Nexmo。 如何在应用程序和PSTN之间建立连接? 如何通过Nexmo发送和接收语音交换? 我只能在docs和npm nexmo包中找到使用Text-to-Speech的示例 。
我的服务器具有Nexmo 文档中的以下代码:
<?php
include 'application_generate_jwt.php';
//Connection information
$base_url = 'https://api.nexmo.com' ;
$version = '/v1';
$action = '/calls';
//User and application information
$application_id = "id-for-your-voice-application";
//Mint your JWT
$keyfile="application_secret_key.txt";
$jwt = generate_jwt($application_id, $keyfile);
//Add the JWT to the request headers
$headers = array('Content-Type: application/json', "Authorization: Bearer " . $jwt ) ;
//Change the to parameter to the number you want to call
$payload = '{
"to":[{
"type": "phone",
"number": "441632960961"
}],
"from": {
"type": "phone",
"number": "441632960960"
},
"answer_url": ["https://nexmo-community.github.io/ncco-examples/first_call_talk.json"]
}';
//Create the request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url . $version . $action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
echo $response;
如果需要更多信息,请告诉我!
使用Nexmo可以使用2种方法来完成此操作,这实际上取决于您是否知道带有应用程序的设备的电话号码。
如果是这样,那么您可以从nexmo拨出每个电话号码的电话,并将它们都放入一个简单的会议(在NCCO通话中称为对话) https://docs.nexmo.com/voice/voice-api/ncco- reference#conversation您只需要确保对话的名称对于该呼叫是唯一的。
另一种方法是通过代理调用,因此该应用程序启动一个“ tel:” URL,其中包含一个供客户呼叫的nexmo电话号码,然后执行将呼叫连接到目标号码的NCCO。
这取决于您的用例,哪种模式最适用,在选项1中,您将承担2个通话费用(每部电话一个),在选项2中,您将承担一个通话费用,而应用程序用户有另一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.