我使用twilio将短信发送到手机,当我运行脚本时,它会向我的手机发送短信,但问题是我不知道发送短信的状态,我该怎么做? / p>
我使用这个简单的入门演示代码
<?php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
// In production, these should be environment variables. E.g.:
// $auth_token = $_ENV["TWILIO_ACCOUNT_SID"]
// A Twilio number you own with SMS capabilities
$twilio_number = "+0987654321";
$client = new Client($account_sid, $auth_token);
$client->messages->create(
// Where to send a text message (your cell phone?)
'+1234567890',
array(
'from' => $twilio_number,
'body' => 'I sent this message in under 10 minutes!'
)
);
答案 0 :(得分:1)
经过适当的研究,并与webhook有各种各样的问题,这就是我的定位
$phoneString = $phoneNumber->asNorthAmericanDialingString();
$mi = $client->messages->create(
// the number you'd like to send the message to
$phoneString ,
array (
// A Twilio phone number you purchased at twilio.com/console
'from' => Config::getCurrentConfig()->smsConfig->fromNumber ,
// the body of the text message you'd like to send
'body' => $message ,
'ProvideFeedback' => "true"
)
);
$msg = $mi->fetch();
$sid = $msg->sid;
$status = $msg->status;
if ($status == 'sent' || $status == 'delivered') { // f'ing twilio, random status
self::getClassLogger()->debug("Sent text message[$sid], status is [$status]");
return new TextMessageStatus($sid , $status);
} else {
// do whatever is appropriate for your case
}