This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
mb_language("Japanese"); | |
mb_internal_encoding("UTF-8"); | |
$userArr = array( | |
'+8150xxxxyyyy' => array('+8150xxxxyyyy','sip:xxx@sip.yyy.com','+8180xxxxyyyy','xxx@yyyy.com','担当1'), | |
'+8150xxxxyyyy' => array('+8150xxxxyyyy','sip:xxx@sip.yyy.com','+8180xxxxyyyy','xxx@yyyy.com','担当2'), | |
'+8150xxxxyyyy' => array('+8150xxxxyyyy','sip:xxx@sip.yyy.com','+8180xxxxyyyy','xxx@yyyy.com','担当3') | |
); | |
$number_index = isset($_REQUEST['number_index']) ? $_REQUEST['number_index'] : "0"; | |
$DialCallStatus = isset($_POST['DialCallStatus']) ? $_POST['DialCallStatus'] : ""; | |
$RecordingUrl = isset($_POST['RecordingUrl']) ? $_POST['RecordingUrl'] : ""; | |
$callFrom = isset($_POST['From']) ? $_POST['From'] : ""; | |
$callTo = isset($_POST['To']) ? $_POST['To'] : ""; | |
$smsFrom = "+1xxxxyyyy"; | |
$user_twilioNo = $userArr[$callTo][0]; // Twilio番号(050) | |
$user_sipNo = $userArr[$callTo][1]; // Sip番号 | |
$user_cellNo = $userArr[$callTo][2]; // 携帯番号 | |
$user_email = $userArr[$callTo][3]; // メールアドレス | |
$user_name = $userArr[$callTo][4]; // ユーザー名 | |
$callNo = strstr($user_sipNo, "sip"); | |
$replaceCallNo = str_replace("+81", "0", $callFrom); | |
header("content-type: text/xml"); | |
if ($RecordingUrl != "") { | |
$number_index = 9; | |
// SendGrid Start | |
$url = 'http://sendgrid.com/'; | |
$user = 'azure_xxxxxxxxxxxxxxxxxxxxx@azure.com'; | |
$pass = 'xxxxxxxxxxxxxxxx'; | |
$message = "発信番号「".$callFrom."」"."からメッセージが届いています。"."¥n"."録音メッセージは下のURLから確認できます。"."¥n"."確認URL:".$RecordingUrl; | |
$messageHTML = "発信番号「".$callFrom."」"."からメッセージが届いています。"."<br />"."録音メッセージは下のURLから確認できます。"."<br />"."確認URL:"."<a href='$RecordingUrl'>".$RecordingUrl."</a>"; | |
$emailTitle = "録音メッセージが届いています。"; | |
$emailFrom = "xxxx@yyyyyyy.com"; | |
$params = array( | |
'api_user' => $user, | |
'api_key' => $pass, | |
'to' => $user_email, | |
'subject' => $emailTitle, | |
'html' => $messageHTML, | |
'text' => $message, | |
'from' => $emailFrom, | |
); | |
$request = $url.'api/mail.send.json'; | |
// Generate curl request | |
$session = curl_init($request); | |
// Tell curl to use HTTP POST | |
curl_setopt ($session, CURLOPT_POST, true); | |
// Tell curl that this is the body of the POST | |
curl_setopt ($session, CURLOPT_POSTFIELDS, $params); | |
// Tell curl not to return headers, but do return the response | |
curl_setopt($session, CURLOPT_HEADER, false); | |
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); | |
// obtain response | |
$response = curl_exec($session); | |
curl_close($session); | |
// SendGrid End | |
//$message = "発信番号「".$callFrom."」"."からメッセージが届いています。"."¥r"."録音メッセージは下のURLから確認できます。"."¥r"."確認URL:".$RecordingUrl; | |
// メールの配信 | |
//mb_send_mail("${user_email}", "録音メッセージが届いています。", "${message}", "From: ${emailFrom}"); | |
?> | |
<Response> | |
<Say language="ja-jp">メッセージを保存いたしました。<?php echo $user_name; ?>からの連絡までいましばらくおまちください。このシステムはTwilioで開発されました。</Say> | |
<Hangup/> | |
</Response> | |
<?php | |
} | |
if ($DialCallStatus != "completed" && $number_index < 2) { | |
?> | |
<Response> | |
<!-- 携帯電話に転送されたらSMSにて発信者番号を通知する --> | |
<?php if ($number_index == 1) { ?> | |
<Sms from="<?php echo $smsFrom; ?>" to="<?php echo $user_cellNo; ?>"><?php echo $callFrom."から電話がありました。確認をお願いします。"; ?></Sms> | |
<?php } ?> | |
<?php if ($number_index == 0) { ?> | |
<Say language="ja-jp"><?php echo $user_name; ?>のオフィスの電話に接続します。しばらくお待ち下さい</Say> | |
<Dial timeout="2" callerId="<?php echo $replaceCallNo; ?>" action="BYOD-Dial.php?number_index=<?php echo $number_index+1; ?>"> | |
<Sip> | |
<?php echo $user_sipNo; ?> | |
</Sip> | |
</Dial> | |
<?php } else { ?> | |
<Say language="ja-jp">携帯電話に転送します。しばらくお待ち下さい</Say> | |
<Dial timeout="10" callerId="<?php echo $user_twilioNo; ?>" action="BYOD-Dial.php?number_index=<?php echo $number_index+1; ?>"> | |
<Number> | |
<?php echo $user_cellNo; ?> | |
</Number> | |
</Dial> | |
<?php } ?> | |
</Response> | |
<?php | |
} elseif ($number_index != 9) { | |
?> | |
<Response> | |
<!-- 携帯にも出なかった場合、録音処理に入る。--> | |
<?php if ($DialCallStatus == "no-answer") { ?> | |
<Say language="ja-jp">ピーという発信音の後に、メッセージを録音してください。録音終了後、シャープを押してください。</Say> | |
<Record /> | |
<?php } ?> | |
</Response> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment