微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在PHP中通过twilio发送短信

我正在尝试通过PHP发送短信,但我听不到我的问题.
我的帐户已经过验证并且是高级帐户(不是免费的),URL正确后即需要,并且我更改了accountSid和AuthToken,

require_once('twilio-PHP-master/Services/Twilio.PHP'); // Loads the library

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

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

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

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

有什么帮助吗?

解决方法:

可能会有两个问题:

1)不允许使用您为该地区购买的Twilio号码发送短信.
2)可能存在一些代码错误.从您的代码中得知您未定义API版本.

我有用的代码是(对于已付款或未付款帐户)

require_once('twilio-PHP-master/Services/Twilio.PHP'); // Loads the library

$version = "2010-04-01"; // Twilio REST API version

// Set our Account SID and AuthToken
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$client = new Services_Twilio($AccountSid, $AuthToken, $version); //initialise the Twilio client

try{
$message = $client->account->messages->create(array(
    "From" => "+972527213871",
    "To" => "+972527213871",
    "Body" => "Test message!",
));

// display a confirmation message on the screen
echo "Sent message";
}catch (Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }

您还可以在twilio帐户中检查消息中的日志部分.
如果未显示任何日志,则可以签入开发者工具->应用监控器.

您可以参考此以获得更多帮助:
http://phpobserver.wordpress.com/2014/03/18/build-sms-text-message-into-your-web-apps-twilio-api/

我希望这能帮到您!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐