2
我使用Twilio API發送根據經批准的數目的廣播短信MySQL查詢Twilio短信電話。我遇到的問題是無法成功運行從數據庫中拉取手機信息的查詢,並將其輸入到API中以符合發送SMS的查詢條件的每個結果。以下是我到目前爲止。如何使用基於結果
//Include the PHP TwilioRest library
require "Services/Twilio.php";
//Set our AccountSid and AuthToken
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
//Instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
//Trusted numbers that we want to be able to send a broadcast
$trusted = array("+33333333333" => "ApprovedAdmin1");
//An unauthorized user tried to send a broadcast.
if(!$name = $trusted[$_REQUEST['From']])
{header("content-type: text/xml");echo "\n";echo "Unauthorized broadcaster, contact an admin for access.";exit(0);}
//These are the recipients that are going to receive the broadcasts
//database user credentials
`$user = "user";`
`$password = "password";`
`$database = "database";`
`$host = "localhost";`
//connect to the database
`$DB = mysql_connect($host, $user, $password) or die("Can't connect to database.");`
`@mysql_select_db($database) or die("Unable to select database");`
//Used to query database for only user phone numbers who accept texts
$recipients = array (mysql_query("SELECT phone FROM sms WHERE (accept_text = 'Y')"));
//I have commented this out to try to get the query to work. The below recipients array does work and even lists the names of the user in the SMS.
//$recipients = array("+22222222222" => "testuser1");
//Grab the message from the incoming SMS
$msg = $_REQUEST['Body'];
// Iterate over all our recipients and send them the broadcast
//foreach ($recipients as $number => $name) {
//Send a new outgoinging SMS by POSTing to the SMS resource
$sms = $client->account->sms_messages->create("3333333333",$number,"$name, " . $msg);echo $name . " ";}
XML的有效性工作正常。結果變量不從表格中提取或響應任何數字。如果我運行直接連接到數據庫的查詢結果拉動罰款。 – 2012-03-03 17:23:32
如果您嘗試使用TwiML來響應用戶,那麼您的XML不正確。這是無效的TwiML。 – christophmccann 2012-03-03 17:25:52
我正在使用Twilio Rest。如果數組是硬編碼的,則響應不會從數據庫結果本身發送。 – 2012-03-03 17:27:29