首页 文章

Twilio发送短信

提问于
浏览
0

您好我必须在我的应用中验证用户电话号码 . 我已经实现了twilio库但我无法发送短信 . 我收到了这个错误

Uncaught exception 'Services_Twilio_RestException' with message 'The From phone number +120xxxxxxx is not a valid, SMS-capable inbound phone number or short code for your account

我还没有买他们的订阅 . 我想首先测试他们的服务,所以我使用试用帐户 . 我用过test AccountSID 和Test authToken .

<?php

require "twilio/Services/Twilio.php";

// set your AccountSid and AuthToken from www.twilio.com/user/account
 $AccountSid = "testaccountsid";
    $AuthToken = "testauthtoken";

    $client = new Services_Twilio($AccountSid, $AuthToken);

    $message = $client->account->messages->create(array(
        "From" => "+1xxxxxxxx",
        "To" => "+92xxxxxxx",
        "Body" => "Test message!",
    ));

// Display a confirmation message on the screen
echo "Sent message {$message->sid}";

From: 当我点击 Get your first twilio phone number 时,他们给了我一个我在“发件人”字段中使用过的美国手机号码

enter image description here

To: 这里我使用了自己的号码,以便我可以收到文本 . 我的号码在twilio中也用于验证目的

我基本上想用twilio从像“6323”这样的数字发送随机密码 . 请告诉我我错过了什么 . 而且他们也给了我在From字段中使用的美国号码 . 如何在“发件人”字段中获取“6323”等短号或“whatsapp”等字母名称 .

1 回答

  • 2

    根据docs

    测试凭据如果您在尝试使用测试凭据进行身份验证时收到此错误,则可能尝试从您的真实帐户发送带有“来自”号码的消息 . 可用于使用您的测试凭据发送成功消息的唯一号码是15005550006.有关更多信息,请阅读我们关于使用您的测试凭据发送SMS的发件人号码的文档 .

    所以你需要将 +15005550006 硬编码为 From .

    有关其API的更多信息,请参阅this

相关问题