Twilio使用Ruby提供约会提醒,我需要用于约会提醒的PHP脚本。任何人都知道Twilio Appointment Reminder的PHP脚本
以下是来自twilio
的Ruby代码require "twilio-ruby"
class AppointmentreminderController < ApplicationController
# your Twilio authentication credentials
ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
# base URL of this application
BASE_URL = "http://www.yourserver.com:3000/appointmentreminder"
# Outgoing Caller ID you have previously validated with Twilio
CALLER_ID = 'NNNNNNNNNN'
def index
end
# Use the Twilio REST API to initiate an outgoing call
def makecall
if !params['number']
redirect_to :action => '.', 'msg' => 'Invalid phone number'
return
end
# parameters sent to Twilio REST API
data = {
:from => CALLER_ID,
:to => params['number'],
:url => BASE_URL + '/reminder',
}
begin
client = Twilio::REST::Client.new(ACCOUNT_SID, ACCOUNT_TOKEN)
client.account.calls.create data
rescue StandardError => bang
redirect_to :action => '.', 'msg' => "Error #{bang}"
return
end
redirect_to :action => '', 'msg' => "Calling #{params['number']}..."
end
更新:现在有一个PHP Tutorial
答案 0 :(得分:1)
我正在努力完成同样的事情。如果你不能在PHP中做到这一点(我提交了一张票)。我找到了一个资源,说你可以同时在一个应用程序中运行RoR和php,这是我最终可能会做的。
答案 1 :(得分:1)
你需要两个文件。一个php类,它调用twilio webservice和xml文件,其中twilio读取你不会的消息。
这课很简单。在构造函数中,您需要创建从twilio站点下载的twilio服务实例是一种名为&#34; call&#34;的方法。您需要调用以创建自动调用。 该方法接受两个参数(要调用的数字和要读取的消息)
请注意,消息需要urlencodend用于特殊的charcater,而number需要国际前缀。这是班级
class twilio_call {
private $oClient; // Twilio Object
private $szSid = ''; // your account sid from twilio profile
private $szToken = ''; // your token from twilio profile
private $szPhoneNumber = ''; // my twilio phone number from twilio profile(need a phone that can call)
private $szApiVersion = '2010-04-01'; // last twilio api
public function __construct() {
/** @var Services_Twilio*/
//This is twilio php api
$this->oClient = new Services_Twilio($this->szSid, $this->szToken, $this->szApiVersion);
}
/**
* @param $szToNumber number to call
* @param $message message to read
*/
public function call($szToNumber, $message) {
//$szToNumber = "+xx xxxxxxx"; // Your number with international prefix
$uri = 'http://yourserver.com/twilio-xml.php?message='.$message; //an xml contain text to scan
$this->oClient->account->calls->create($this->szPhoneNumber, $szToNumber,
$uri, array(
'Method' => 'GET',
'FallbackMethod' => 'GET',
'StatusCallbackMethod' => 'GET',
'Record' => 'false',
));
}
}
xml文件非常简单。只需要tre标签。
暂停:暂停指定的长度 play:执行一个mp3(或其他媒体参见twilio引用)来执行 说:用alice语音和特定语言来表示消息字符串。
这是xml
<?php
header("content-type: text/xml");
echo "<?xml szApiVersion=\"1.0\" encoding=\"UTF-8\"?>\n";
if (isset($_GET['message']))
$message = $_GET['message'];
?>
<Response>
<Play>http://yourserver/file.mp3</Play>
<Pause length="1"/>
<Say voice="alice" language="en-US" loop="10"><?php echo $message ?></Say>
</Response>