קוד להודעה אישית במהלך האזנה - מישהו מוכן להעלות לשרת שלו?
-
@CUBASE
https://utilitiesphone.com/PlayfilePersonalMessage/PlayfilePersonalMessage.php
בלי התחייבות לאחסון כלל! -
@amp-Software-0 אלוףףף!!
-
@amp-Software-0 היתה טעות בקוד, יש מצב אתה מעלה שוב?
-
@amp-Software-0 יש מצב?
-
@CUBASE
העלתייש לך שם שגיאה, ככה"נ מחמת שימוש בתוסף בעורך הקוד
תיקנתי את זה -
באמת זה היה איזה תוסף
באיזה תוספים אתה משתמש ל-PHP?
התקנתי כמה תוספים ואין לי מושג מה באמת מסייע... -
@CUBASE
PHP Intelephense
ו PHP debug
באמת לא מומלץ להתקין הרבה תוספים, זה רק מסבך -
-
@CUBASE
כן,
PHP Debug זה בעיקר בשביל דיבוג עם Xdebug, זה לא נצרך לפיתוח עצמו -
@amp-Software-0 אויש, סליחה שאני משגע אותך...
עוד באג מעצבן, ב-read כתבתי Record במקום record
הקוד בספויילר (אני מניח שיותר קל לשנות מאשר למחוק ולהעלות שוב)
<?php // קבועים להודעות const MsgRecordInstructions = "m-1012"; const MsgMenuRecordInstructions = "m-1009"; const MsgBranchConfigError = "m-1120"; const MsgRecordSaved = "m-1452"; const MsgRecordCanceled = "m-1306"; const MsgContinueRecording = "m-2196"; const MsgNoPhone = "m-1494"; const MsgERROR = "m-1080"; // פונקציה ליצירת פקודת read function CreateReadCommand(string $Message, array $Values): string { $FormattedValues = implode(",", $Values); return "read={$Message}={$FormattedValues}"; } // פונקציות נוספות function record_play(string $RecordPath): string { return "id_list_message=f-{$RecordPath}&" . MenuRecord(); } function record_ok(string $token, string $RecordPath, string $GetPhone, string $GoToFolderAndPlay, string $ymApi): string { $folderMove = isset($_GET["folder_move"]) ? $_GET["folder_move"] : "/personalMessages"; $encodedWhat = urlencode("ivr2:{$RecordPath}"); $encodedTarget = urlencode("ivr2:{$folderMove}/Phone/{$GetPhone}"); $url = "{$ymApi}FileAction?token=" . urlencode($token) . "&action=move&what={$encodedWhat}&target={$encodedTarget}"; file_get_contents($url); return "id_list_message=" . MsgRecordSaved . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function record_again(string $hangupInsertFile): string { return RecordFunc($hangupInsertFile); } function record_cancel(string $token, string $RecordPath, string $GoToFolderAndPlay, string $ymApi): string { $encodedWhat = urlencode("ivr2:{$RecordPath}"); $url = "{$ymApi}FileAction?token=" . urlencode($token) . "&action=delete&what={$encodedWhat}"; file_get_contents($url); return "id_list_message=" . MsgRecordCanceled . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function continue_recording(string $hangupInsertFile): string { $recordValuesContinue = [ "Record", "", "record", "/ApiTempFiles", "", "no", $hangupInsertFile, "yes" // החלפת null במחרוזת ריקה ]; return CreateReadCommand(MsgContinueRecording, $recordValuesContinue); } // מערך פונקציות $recordFunctions = [ "1" => "record_play", "2" => "record_ok", "3" => "record_again", "4" => "record_cancel", "5" => "continue_recording", ]; function RecordFunc(string $hangupInsertFile): string { $recordValues = [ "Record", "", "record", "/ApiTempFiles", "", "no", $hangupInsertFile, // החלפת null במחרוזת ריקה ]; return CreateReadCommand(MsgRecordInstructions, $recordValues); } function MenuRecord (): string { $menuRecordValues = [ "MenuRecord", "", "1", "", "", "NO", "", "", "", "", "", "", "", "", "no", // החלפת null במחרוזת ריקה ]; return CreateReadCommand(MsgMenuRecordInstructions, $menuRecordValues); } function RunTzintuk(string $token, string $GetPhone, string $ymApi): string { $callerId = isset($_GET["tzintuk_your_id"]) ? $_GET["tzintuk_your_id"] : null; $TzintukTimeOut = isset($_GET["tzintuk_timeout"]) ? $_GET["tzintuk_timeout"] : null; $url = "{$ymApi}RunTzintuk?token=" . urlencode($token) . "&phones=tzl:{$GetPhone}&callerId={$callerId}&TzintukTimeOut={$TzintukTimeOut}"; file_get_contents($url); return ""; } // יצירת משתנים גלובליים - מוקדם יותר ועם בדיקות קיום $ymApi = "https://www.call2all.co.il/ym/api/"; $ApiDID = isset($_GET["ApiDID"]) ? $_GET["ApiDID"] : null; $pass = isset($_GET["pass"]) ? $_GET["pass"] : null; if (!$ApiDID || !$pass) { echo "id_list_message=" . MsgBranchConfigError; exit; } // יצירת token - תוקן! $token = "{$ApiDID}:{$pass}"; $ApiExtension = isset($_GET["ApiExtension"]) ? $_GET["ApiExtension"] : null; $ApiWhat = isset($_GET["what"]) ? $_GET["what"] : null; $PlayStop = isset($_GET["PlayStop"]) ? $_GET["PlayStop"] : null; $ApiWhatFile = $ApiWhat && $ApiExtension ? str_replace("ivr2:/{$ApiExtension}/", "", $ApiWhat) : null; $ApiWhatFile = $ApiWhatFile ? substr($ApiWhatFile, 0, strrpos($ApiWhatFile, ".")) : null; $GoToPlayStop = $PlayStop ? $PlayStop - 5000 : null; $GoToFolderAndPlay = $ApiExtension && $ApiWhatFile && $GoToPlayStop ? "/{$ApiExtension},{$ApiWhatFile},{$GoToPlayStop}" : ""; if (isset($_GET["hangup_insert_file"]) && $_GET["hangup_insert_file"] == "yes") { $hangupInsertFile = "yes"; }else{ $hangupInsertFile = ""; } if (isset($_GET["hangup_send_tzuntuk"]) && $_GET["hangup_send_tzuntuk"] == "yes") { $hangupSendTzintuk = "yes"; }else{ $hangupSendTzintuk = ""; } // בניית כתובת ה-API המלאה (כמו קודם) $GetFileInfo = "{$ymApi}GetFile?token=" . urlencode($token) . "&what=" . urlencode($ApiWhat); // ביצוע בקשת GET עם cURL (כמו קודם) $ch = curl_init($GetFileInfo); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, ]); $response = curl_exec($ch); if (curl_errno($ch)) { $error_message = 'cURL Error'; echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; exit; } else { $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 200) { // פענוח JSON (כמו קודם) $result = json_decode($response, true); // בדיקה אם הפענוח הצליח והשדה file קיים (כמו קודם) if ($result !== null && isset($result['file']) && is_array($result['file'])) { // בדיקה אם השדה phone מכיל null או משהו אחר if ($result['file']['phone'] !== null) { $GetPhone = $result['file']['phone']; } else { echo "id_list_message=" . MsgNoPhone . "&go_to_folder_and_play={$GoToFolderAndPlay}"; exit; } } else { $error_message = "Invalid JSON response or 'file' field not found/incorrect format Response"; echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; exit; } } else { $error_message = "HTTP Error: {$http_code} Response: {$response}"; echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; exit; } } curl_close($ch); if (isset($_GET["hangup"])) { if ($hangupInsertFile == "yes") { record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); if ($hangupSendTzintuk == "yes") { RunTzintuk($token, $GetPhone, $ymApi); } }else{ record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } exit; } // טיפול בהקלטה אישית if (!isset($_GET["Record"])) { echo RecordFunc($hangupInsertFile); exit; }else{ $RecordPath = $_GET["Record"]; } // טיפול בהקלטה לתפריט if (!empty($_GET) && key(array_slice($_GET, -1, 1, true)) === "Record") { $menuRecordData = MenuRecord(); // שימוש ב $GoToFolderAndPlay echo $menuRecordData; exit; } // טיפול בהקשות if (isset($_GET["MenuRecord"])) { $menuRecordOption = $_GET["MenuRecord"]; $optionsParam = "menu_record_options_" . $menuRecordOption; if (isset($_GET[$optionsParam])) { $optionValue = $_GET[$optionsParam]; if (function_exists($optionValue) || $optionValue == "noop") { if ($optionValue == "noop") { echo MenuRecord(); } else { if ($optionValue == "record_play") { echo record_play($RecordPath); } elseif ($optionValue == "record_ok") { echo record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); RunTzintuk($token, $GetPhone, $ymApi); } elseif ($optionValue == "record_again") { echo record_again($hangupInsertFile); } elseif ($optionValue == "record_cancel") { echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } elseif ($optionValue == "continue_recording") { echo continue_recording($hangupInsertFile); } } } } else { if (array_key_exists($menuRecordOption, $recordFunctions)) { $functionToCall = $recordFunctions[$menuRecordOption]; if ($functionToCall == "record_play") { echo record_play($RecordPath); } elseif ($functionToCall == "record_ok") { echo record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); RunTzintuk($token, $GetPhone, $ymApi); } elseif ($functionToCall == "record_again") { echo record_again($hangupInsertFile); } elseif ($functionToCall == "record_cancel") { echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } elseif ($functionToCall == "continue_recording") { echo continue_recording($hangupInsertFile); } }else{ echo MenuRecord(); } } } ?>
-
@CUBASE
טופל -
@amp-Software-0
שינית גם את שם הפרמטר ל-record?כבר תיקנתי את זה בקוד שהבאתי בספויילר...
עכשיו זה מבקש ממני שוב ושוב הקלטה...
-
@CUBASE
טוב.. -
-
@amp-Software-0 אופססס..
יצאתי מנקודת הנחה שהמערכת כל פעם שולחת את הבקשה האחרונה כפרמטר אחרון (כך ראיתי איפשהו בפורום)
בגלל שבהקלטה ב-API יש תפריט שונה מהקלטה רגילה אז עשיתי שההקלטה תישמר ב-# בתיקייה זמנית ואז יבקש תפריט,
בקוד כתבתי שאם הפרמטר האחרון הוא Record אז ידפיס תפריט,
בפועל מה שקורה זה שהמשתמש מקליט, המערכת שולחת פרמטרRecord=/ApiTempFiles/000.wav
, המערכת מקבלת בקשה לתפריט ומחזירה פרמטרMenuRecord=3
(הקלטה חוזרת), ואז המערכת מקבלת בקשה להקלטה ומחזירהRecord=/ApiTempFiles/000.wav&MenuRecord=3
ולא מחזירה את הפרמטר Record אחרון!!בקיצור, אצטרך להשתמש באובייקט SESSION כמו שכתבת כאן,
אשמח אם תוכל לסייע לי בטיפול בקוד