问题描述
我正在尝试将 app.py 从 here 转换为 PHP,但是,我遇到了困难(我是 PHP 新手)。
到目前为止,这是我所拥有的:
<?PHP
// Get the PHP helper library from https://twilio.com/docs/libraries/PHP
// this line loads the library
require_once "/path/to/Twilio/autoload.PHP";
require('vendor/autoload.PHP');
use Twilio\TwiML\VoiceResponse;
use Twilio\Rest\Client;
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Http\Requests;
$TWILIO_ACCOUNT_SID = "ACXXXX";
$TWILIO_AUTH_TOKEN = "XXXXXX";
# create here: twilio.com/console/verify/services
$VERIFY_SERVICE_SID = "VAXXXXX";
# replace with your number for testing
$MODERATOR = "+11111111111";
# add your number and the numbers of other people joining your call
# Could replace with your customer DB in production
$KNowN_PARTICIPANTS = array(
"+12222222222" => "Test",$MODERATOR => "Me"
);
$twilio = new Client($TWILIO_ACCOUNT_SID,$TWILIO_AUTH_TOKEN);
function join_conference($caller,$resp){
$resp = new VoiceResponse();
$dial = $resp->dial();
# If the caller is our MODERATOR,then start the conference when they
# join and end the conference when they leave
if ($_REQUEST['From'] == $MODERATOR) {
$dial->conference("My Conference",array(
"startConferenceOnEnter" => True,"endConferenceOnExit" => True
));
} else {
$dial->conference("My Conference",array(
"startConferenceOnEnter" => True
));
}
echo $dial;
}
function start_verification($caller){
try{
$verification = $twilio->verify->v2->services($VERIFY_SERVICE_SID)->verifications($caller)->fetch();
}
catch (TwilioRestException $e){
echo "No pending verifications for " . $caller;
$verification = $twilio->verify->v2->services($VERIFY_SERVICE_SID)->verifications($caller)->create($caller,"sms");
}
}
function check_verification($caller,$otp){
$check = $twilio->verify->v2->services($VERIFY_SERVICE_SID)->verificationChecks->create($otp,["to" => $caller]);
return $check->status == "approved";
}
Route::match(array("GET","POST"),"/voice",function()
{
$resp = new VoiceResponse();
$caller = $_REQUEST["From"];
$name = $KNowN_PARTICIPANTS[$caller];
if (is_null($name)){
$resp->say("Sorry,I do not recognize the number you are calling from.");
return $resp;
}
start_verification($caller);
$gather = $resp->gather(["numDigits" => 6,"action" => "/gather"]);
$gather->say("Welcome ." . $name . "Please enter the 6 digit code sent to your device");
$resp->redirect("/voice");
return $resp;
});
Route::match(array("GET","/gather",function(Request $request)
{
$resp = new VoiceResponse();
if ($request->input("Digits")){
$caller = $_REQUEST["From"];
if (check_verification($caller,$request->input('Digits'))){
$resp->say("That was correct. Joining conference.");
}
else {
$resp->say("Please try again.");
$resp->redirect("/voice");
}
return join_conference($caller,$resp);
}
return $resp;
});
当我在本地主机中运行该应用程序时,出现以下错误:“致命错误:未捕获错误:在 /path/otpconference.PHP:66 中找不到类 'Illuminate\Support\Facades\Route' 堆栈跟踪:# 0 {main} 在第 66 行的 /path/otpconference.PHP 中抛出“
您能否建议在没有 Laravel 的情况下是否有另一种方法来实现这一点?这个框架有点混乱。
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)