【问题标题】:Twilio send an smsTwilio 发送短信
【发布时间】:2016-03-18 13:46:06
【问题描述】:

您好,我必须在我的应用中验证用户电话号码。我已经实现了 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}";

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

收件人:这里我使用了自己的号码,以便接收短信。我自己的号码在 twilio 中也用于验证目的

我基本上想使用 twilio 从“6323”之类的数字发送随机密码。请告诉我我错过了什么。他们还给了我在 From 字段中使用的美国号码。如何在 From 字段中获取“6323”之类的短数字或“whatsapp”之类的字母名称。

【问题讨论】:

    标签: php twilio twilio-php


    【解决方案1】:

    根据docs

    测试凭证

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

    因此您需要将+15005550006 硬编码为From

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

    【讨论】:

    • 这完全正确。补充一点,当您尚未使用信用卡升级您的帐户时,您可以使用 Live Credentials 向您自己的电话号码发送 SMS 消息,这也不会花费您任何费用。
    • @AlexTartan 感谢 alex 的回答。好的,它现在正在工作,它说已发送消息。但是我的手机没有收到任何短信。
    猜你喜欢
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2015-08-08
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多