从Twilio子帐户发送短信(是的,它们是全局启用的消息号码)功能不适合我。
这是发送消息的代码
public function notification($loggedUserId,$send_to){
global $objSession;
$modelUser = new Application_Model_User();
$data = $modelUser->getTwilio('twilio',$loggedUserId);
// here in $data I got all data about subaccount
//by which a user is logged in and array i got is
/*
Array
(
[twilio_id] => 1
[twilio_trainer_id] => 147 (its logged user id)
[twilio_phone] => +177*****09
[twilio_sid] => ACfd42**********709***b***********
[twilio_token] => 88a*************************da**
[twilio_added] => 2014-04-29 19:42:14
)*/
// Step 1: Set Library.
require_once(ROOT_PATH.'/library/twilio/Services/Twilio.php');
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = $data['twilio_sid'];
$AuthToken = $data['twilio_token'];
$twilioPhone = $data['twilio_phone'];
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$peopleInfo = $this->objUser->getUserData($send_to);
//prd($peopleInfo['user_phone']);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
if(!empty($peopleInfo['user_phone'])){
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased, or the (deprecated) Sandbox number
$twilioPhone,
// the number we are sending to - Any phone number
$peopleInfo['user_phone'],
// the sms body
"Hey , Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent Successufully ";
}
exit;
}
一切正常,但是我的号码没有收到消息。打印"Sent Successfully",但未收到任何消息。
有谁知道我做错了什么吗?
按Rock Rathore的要求,
类是否处理区号?我的意思是它需要一个格式吗?例如,如果你给它0091或+91或91,这对它有影响吗?如果您发送不同格式的区号,该课程是否会格式化最终号码?还是需要一个格式的区号?