【发布时间】:2020-12-23 07:49:20
【问题描述】:
我已集成 Twilio 可编程语音。现在我正在尝试让客户端从浏览器调用,并使用 Twilio JS Client 接收对浏览器的调用。当我尝试拨打电话时,它会显示。
消息:“功能令牌无效或丢失。”
我也搜索了互联网和 Twilio 文档,但没有任何帮助。这是我的代码。
查看
<button onclick="callCustomer('{{ '+xxxxxxxx' }}')" type="button" class="btn btn-primary btn-lg call-customer-button">
Call customer
</button>
控制器
public function newToken(Request $request) {
// Required for all Twilio access tokens
$twilioAccountSid = 'ACxxxxxxxxx';
$twilioApiKey = 'SKxxxxxxxxxxx';
$twilioApiSecret = 'xxxxxx';
$outgoingApplicationSid = 'APxxxxxxxxxxx';
$identity = "Jhon_Doe";
$token = new AccessToken(
$twilioAccountSid, $twilioApiKey, $twilioApiSecret, 3600, $identity
);
$voiceGrant = new VoiceGrant();
$voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);
$voiceGrant->setIncomingAllow(true);
$token->addGrant($voiceGrant);
return $token->toJWT();
}
JS
function callCustomer(phoneNumber) {
$.get("/token", {forPage: window.location.pathname}, function (data) {
console.log(data);
const device = new Twilio.Device();
device.setup(data);
var params = {"phoneNumber": phoneNumber};
device.connect(params);
});
}
我尝试从 jwt.io 调试工具调试我的令牌,它说:
签名无效。
我确定我遗漏了一些东西,但不知道是什么。任何帮助或提示将不胜感激。
【问题讨论】:
标签: jwt twilio twilio-php twilio-click-to-call twilio-programmable-voice