קוד להודעה אישית במהלך האזנה - מישהו מוכן להעלות לשרת שלו?
-
@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 כמו שכתבת כאן,
אשמח אם תוכל לסייע לי בטיפול בקוד -
@amp-Software-0 וואי איך אני מקווה שזה העדכון האחרון...
<?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}.wav"); $encodedTarget = urlencode("ivr2:{$folderMove}/Phone/{$GetPhone}"); CheckIfFolderExists($token, $encodedTarget, $ymApi, $GoToFolderAndPlay); $url = "{$ymApi}FileAction?token={$token}&action=move&what={$encodedWhat}&target={$encodedTarget}"; file_get_contents($url); unset($_SESSION["IfRecorded"]); return "id_list_message=" . MsgRecordSaved . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function record_ok_and_run_tzintuk(string $token, string $RecordPath, string $GetPhone, string $GoToFolderAndPlay, string $ymApi): string { $folderMove = isset($_GET["folder_move"]) ? $_GET["folder_move"] : "/personalMessages"; $encodedWhat = urlencode("ivr2:{$RecordPath}.wav"); $encodedTarget = urlencode("ivr2:{$folderMove}/Phone/{$GetPhone}"); CheckIfFolderExists($token, $encodedTarget, $ymApi, $GoToFolderAndPlay); $url = "{$ymApi}FileAction?token={$token}&action=move&what={$encodedWhat}&target={$encodedTarget}"; file_get_contents($url); RunTzintuk($token, $GetPhone, $ymApi); unset($_SESSION["IfRecorded"]); return "id_list_message=" . MsgRecordSaved . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function record_again(string $hangupInsertFile, $RecordName): string { $_SESSION["IfRecorded"] = "yes"; $recordValues = [ "Record", "", "record", "/ApiTempFiles", $RecordName, "no", $hangupInsertFile ]; return CreateReadCommand(MsgRecordInstructions, $recordValues); } function record_cancel(string $token, string $RecordPath, string $GoToFolderAndPlay, string $ymApi): string { $encodedWhat = urlencode("ivr2:{$RecordPath}.wav"); $url = "{$ymApi}FileAction?token={$token}&action=delete&what={$encodedWhat}"; file_get_contents($url); unset($_SESSION["IfRecorded"]); return "id_list_message=" . MsgRecordCanceled . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function continue_recording(string $hangupInsertFile, $RecordName): string { $_SESSION["IfRecorded"] = "yes"; $recordValuesContinue = [ "Record", "", "record", "/ApiTempFiles", $RecordName, "no", $hangupInsertFile, "yes" ]; return CreateReadCommand(MsgContinueRecording, $recordValuesContinue); } // מערך פונקציות $recordFunctions = [ "1" => "record_play", "2" => "record_ok_and_run_tzintuk", "3" => "record_again", "4" => "record_cancel", "5" => "continue_recording", ]; function RecordFunc(string $hangupInsertFile): string { $_SESSION["IfRecorded"] = "yes"; $recordValues = [ "Record", "", "record", "/ApiTempFiles", "", "no", $hangupInsertFile ]; return CreateReadCommand(MsgRecordInstructions, $recordValues); } function MenuRecord (): string { if (isset($_SESSION["IfRecorded"]) && $_SESSION["IfRecorded"] == "yes") { $_SESSION["IfRecorded"] = "no"; } $menuRecordValues = [ "MenuRecord", "", "1", "", "", "NO", "", "", "", "", "", "", "", "", "no" ]; return CreateReadCommand(MsgMenuRecordInstructions, $menuRecordValues); } function RunTzintuk(string $token, string $GetPhone, string $ymApi) { $callerId = isset($_GET["tzintuk_your_id"]) ? $_GET["tzintuk_your_id"] : null; $TzintukTimeOut = isset($_GET["tzintuk_timeout"]) ? $_GET["tzintuk_timeout"] : null; $url = "{$ymApi}RunTzintuk?token={$token}&phones=tzl:{$GetPhone}&callerId={$callerId}&TzintukTimeOut={$TzintukTimeOut}"; file_get_contents($url); } function CheckIfFolderExists(string $token, string $encodedTarget, string $ymApi, string $GoToFolderAndPlay) { $url = "{$ymApi}CheckIfFileExists?token={$token}&path={$encodedTarget}/ext.ini"; $ch = curl_init($url); 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); // בדיקה האם הפענוח הצליח והשדה fileExists קיים if ($result !== null && isset($result['fileExists'])) { // בדיקה אם השדה fileExists מכיל false if ($result['fileExists'] == false) { $OpenFolder = "{$ymApi}UpdateExtension?token={$token}&path={$encodedTarget}"; file_get_contents($OpenFolder); $DeleteExtFile = "{$ymApi}FileAction?token={$token}&action=delete&what={$encodedTarget}/ext.ini"; file_get_contents($DeleteExtFile); } } 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); } // יצירת משתנים גלובליים - מוקדם יותר ועם בדיקות קיום $ymApi = "https://www.call2all.co.il/ym/api/"; $ApiDID = isset($_GET["ApiDID"]) ? $_GET["ApiDID"] : null; $pass = isset($_GET["pass"]) ? $_GET["pass"] : null; $ApiCallID = isset($_GET["ApiCallId"]) ? $_GET["ApiCallId"] : null; $ApiExtension = isset($_GET["ApiExtension"]) ? $_GET["ApiExtension"] : null; $ApiWhat = isset($_GET["what"]) ? $_GET["what"] : null; $PlayStop = isset($_GET["PlayStop"]) ? $_GET["PlayStop"] : null; if (!$ApiDID || !$pass || !$ApiDID || !$ApiExtension || !$ApiWhat) { echo "id_list_message=" . MsgBranchConfigError; exit; } // יצירת טוקן עם קידוד URL $token = urldecode("{$ApiDID}:{$pass}"); $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}"; 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={$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"]) && isset($_GET["Record"])) { if ($hangupInsertFile == "yes") { if ($hangupSendTzintuk == "yes") { record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); }else{ record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } }else{ record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } exit; }else{ exit; } session_id($ApiCallID); session_start(); // טיפול בהקלטה אישית if (!isset($_GET["Record"])) { echo RecordFunc($hangupInsertFile); exit; }else{ $RecordPath = str_replace(".wav", "", $_GET["Record"]); $RecordName = str_replace("/ApiTempFiles" . "/", "", $RecordPath); } // טיפול בתפריט if (isset($_SESSION["IfRecorded"]) && $_SESSION["IfRecorded"] == "yes") { echo MenuRecord(); 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 == "record_play") { echo record_play($RecordPath); } elseif ($optionValue == "record_ok") { echo record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } elseif ($optionValue == "record_ok_and_run_tzintuk") { echo record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } elseif ($optionValue == "record_again") { echo record_again($hangupInsertFile, $RecordName); } elseif ($optionValue == "record_cancel") { echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } elseif ($optionValue == "continue_recording") { echo continue_recording($hangupInsertFile, $RecordName); } elseif ($optionValue == "noop") { echo MenuRecord(); } } } 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); } elseif ($functionToCall == "record_ok_and_run_tzintuk") { echo record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } elseif ($functionToCall == "record_again") { echo record_again($hangupInsertFile, $RecordName); } elseif ($functionToCall == "record_cancel") { echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } elseif ($functionToCall == "continue_recording") { echo continue_recording($hangupInsertFile, $RecordName); } }else{ echo MenuRecord(); } } } ?>
-
@amp-Software-0 מה עם זה?...
-
פוסט זה נמחק! -
@CUBASE
עודכן -
@amp-Software-0 שוב לא עובד,
שמע, אתה תותח עם כזה סבלנות אבל לא נעים לי לשגע אותך (וגם זה שאתה מתחבר לפורום פעם בכמה ימים), רוצה להקצות לי תיקייה בשרת שלך ואעדכן בעצמי כל פעם?
בכל זאת, הנה מעודכן:
<?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}.wav"); $encodedTarget = urlencode("ivr2:{$folderMove}/Phone/{$GetPhone}"); CheckIfFolderExists($token, $encodedTarget, $ymApi, $GoToFolderAndPlay); $url = "{$ymApi}FileAction?token={$token}&action=move&what={$encodedWhat}&target={$encodedTarget}"; file_get_contents($url); unset($_SESSION["IfRecorded"]); return "id_list_message=" . MsgRecordSaved . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function record_ok_and_run_tzintuk(string $token, string $RecordPath, string $GetPhone, string $GoToFolderAndPlay, string $ymApi): string { $folderMove = isset($_GET["folder_move"]) ? $_GET["folder_move"] : "/personalMessages"; $encodedWhat = urlencode("ivr2:{$RecordPath}.wav"); $encodedTarget = urlencode("ivr2:{$folderMove}/Phone/{$GetPhone}"); CheckIfFolderExists($token, $encodedTarget, $ymApi, $GoToFolderAndPlay); $url = "{$ymApi}FileAction?token={$token}&action=move&what={$encodedWhat}&target={$encodedTarget}"; file_get_contents($url); RunTzintuk($token, $GetPhone, $ymApi); unset($_SESSION["IfRecorded"]); return "id_list_message=" . MsgRecordSaved . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function record_again(string $hangupInsertFile, $RecordName): string { $_SESSION["IfRecorded"] = "yes"; $recordValues = [ "Record", "", "record", "/ApiTempFiles", $RecordName, "no", $hangupInsertFile ]; return CreateReadCommand(MsgRecordInstructions, $recordValues); } function record_cancel(string $token, string $RecordPath, string $GoToFolderAndPlay, string $ymApi): string { $encodedWhat = urlencode("ivr2:{$RecordPath}.wav"); $url = "{$ymApi}FileAction?token={$token}&action=delete&what={$encodedWhat}"; file_get_contents($url); unset($_SESSION["IfRecorded"]); return "id_list_message=" . MsgRecordCanceled . "&go_to_folder_and_play={$GoToFolderAndPlay}"; } function continue_recording(string $hangupInsertFile, $RecordName): string { $_SESSION["IfRecorded"] = "yes"; $recordValuesContinue = [ "Record", "", "record", "/ApiTempFiles", $RecordName, "no", $hangupInsertFile, "yes" ]; return CreateReadCommand(MsgContinueRecording, $recordValuesContinue); } // מערך פונקציות $recordFunctions = [ "1" => "record_play", "2" => "record_ok_and_run_tzintuk", "3" => "record_again", "4" => "record_cancel", "5" => "continue_recording", ]; function RecordFunc(string $hangupInsertFile): string { $_SESSION["IfRecorded"] = "yes"; $recordValues = [ "Record", "", "record", "/ApiTempFiles", "", "no", $hangupInsertFile ]; return CreateReadCommand(MsgRecordInstructions, $recordValues); } function MenuRecord (): string { if (isset($_SESSION["IfRecorded"]) && $_SESSION["IfRecorded"] == "yes") { $_SESSION["IfRecorded"] = "no"; } $menuRecordValues = [ "MenuRecord", "", "1", "", "", "NO", "", "", "", "", "", "", "", "", "no" ]; return CreateReadCommand(MsgMenuRecordInstructions, $menuRecordValues); } function RunTzintuk(string $token, string $GetPhone, string $ymApi) { $callerId = isset($_GET["tzintuk_your_id"]) ? $_GET["tzintuk_your_id"] : null; $TzintukTimeOut = isset($_GET["tzintuk_timeout"]) ? $_GET["tzintuk_timeout"] : null; $url = "{$ymApi}RunTzintuk?token={$token}&phones=tzl:{$GetPhone}&callerId={$callerId}&TzintukTimeOut={$TzintukTimeOut}"; file_get_contents($url); } function CheckIfFolderExists(string $token, string $encodedTarget, string $ymApi, string $GoToFolderAndPlay) { $url = "{$ymApi}CheckIfFileExists?token={$token}&path={$encodedTarget}/ext.ini"; $ch = curl_init($url); 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); // בדיקה האם הפענוח הצליח והשדה fileExists קיים if ($result !== null && isset($result['fileExists'])) { // בדיקה אם השדה fileExists מכיל false if ($result['fileExists'] == false) { $OpenFolder = "{$ymApi}UpdateExtension?token={$token}&path={$encodedTarget}"; file_get_contents($OpenFolder); $DeleteExtFile = "{$ymApi}FileAction?token={$token}&action=delete&what={$encodedTarget}/ext.ini"; file_get_contents($DeleteExtFile); } } 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); } // יצירת משתנים גלובליים - מוקדם יותר ועם בדיקות קיום $ymApi = "https://www.call2all.co.il/ym/api/"; $ApiDID = isset($_GET["ApiDID"]) ? $_GET["ApiDID"] : null; $pass = isset($_GET["pass"]) ? $_GET["pass"] : null; $ApiCallID = isset($_GET["ApiCallId"]) ? $_GET["ApiCallId"] : null; $ApiExtension = isset($_GET["ApiExtension"]) ? $_GET["ApiExtension"] : null; $ApiWhat = isset($_GET["what"]) ? $_GET["what"] : null; $PlayStop = isset($_GET["PlayStop"]) ? $_GET["PlayStop"] : null; if (!$ApiDID || !$pass || !$ApiCallID || !$ApiExtension || !$ApiWhat) { echo "id_list_message=" . MsgBranchConfigError; exit; } // יצירת טוקן עם קידוד URL $token = urldecode("{$ApiDID}:{$pass}"); $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}"; if (isset($_GET["hangup_insert_file"]) && $_GET["hangup_insert_file"] == "yes") { $hangupInsertFile = "yes"; }else{ $hangupInsertFile = ""; } if (isset($_GET["hangup_send_tzintuk"]) && $_GET["hangup_send_tzintuk"] == "yes") { $hangupSendTzintuk = "yes"; }else{ $hangupSendTzintuk = ""; } // בניית כתובת ה-API המלאה עם הטוקן והפרמטרים $GetFileInfo = "{$ymApi}GetFile?token={$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); session_id($ApiCallID); session_start(); // טיפול בהקלטה אישית if (!isset($_GET["Record"])) { echo RecordFunc($hangupInsertFile); exit; }else{ $RecordPath = str_replace(".wav", "", $_GET["Record"]); $RecordName = str_replace("/ApiTempFiles" . "/", "", $RecordPath); } if (isset($_GET["hangup"]) && $hangupInsertFile == "yes") { if ($hangupSendTzintuk == "yes") { record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); }else{ record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } exit; }elseif (isset($_GET["hangup"])){ record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); exit; } // טיפול בתפריט if (isset($_SESSION["IfRecorded"]) && $_SESSION["IfRecorded"] == "yes") { echo MenuRecord(); 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 == "record_play") { echo record_play($RecordPath); } elseif ($optionValue == "record_ok") { echo record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } elseif ($optionValue == "record_ok_and_run_tzintuk") { echo record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } elseif ($optionValue == "record_again") { echo record_again($hangupInsertFile, $RecordName); } elseif ($optionValue == "record_cancel") { echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } elseif ($optionValue == "continue_recording") { echo continue_recording($hangupInsertFile, $RecordName); } elseif ($optionValue == "noop") { echo MenuRecord(); } } } 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); } elseif ($functionToCall == "record_ok_and_run_tzintuk") { echo record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); } elseif ($functionToCall == "record_again") { echo record_again($hangupInsertFile, $RecordName); } elseif ($functionToCall == "record_cancel") { echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); } elseif ($functionToCall == "continue_recording") { echo continue_recording($hangupInsertFile, $RecordName); } }else{ echo MenuRecord(); } } } ?>
-
@CUBASE
זה קצת לא הגיוני ההתנהלות, אם אין לך שרת לבצע בדיקות, לא יהיה לדבר סוף,
אתה חייב לבדוק את הקוד שלך היטב ואח"כ להעלות אותו. אני יכול להיות שרת פרודקשן אבל לא שרת טסט..@CUBASE כתב בקוד להודעה אישית במהלך האזנה - מישהו מוכן להעלות לשרת שלו?:
רוצה להקצות לי תיקייה בשרת שלך ואעדכן בעצמי כל פעם?
אני מניח שלא התכוונת ברצינות..
בכל אופן כרגע העלתי את הקוד המעודכן
-
@amp-Software-0 תותח אתה !!
-
@amp-Software-0 כתב בקוד להודעה אישית במהלך האזנה - מישהו מוכן להעלות לשרת שלו?:
@CUBASE
זה קצת לא הגיוני ההתנהלות, אם אין לך שרת לבצע בדיקות, לא יהיה לדבר סוף,
אתה חייב לבדוק את הקוד שלך היטב ואח"כ להעלות אותויש לי שרת לבדיקות, הבעיה שא"א לגשת אליו ב-API ואני מנסה כמה שאני יכול לדמות שיחה, לפעמים אני יכול לתפוס את הבאג רק אחרי שאני מקשיב בטלפון, לדוג' היה באג שבהשמעת קובץ כתבתי id_list_message=/ApiTempFiles/000 .wav, כשראיתי את זה במחשב לא יכולתי לדעת שזה באג, אחרי ששמעתי בטלפון הבנתי שהייתה לי טעות...
-
פוסט זה נמחק! -
@CUBASE אדם שפוי לא יפתח דרך להעלות לשרת שלו קוד שרירותי
לגבי חיבור לימות - תריץ מקומית למחשב ותנגיש את זה לימות על ידי ngrok -
@CUBASE יש היום שרתים בכלום כסף, אני שוכר שרת בבערך 15 לחודש, אתה יכול לשכור לכמה ימים ולבטל, דברו גם על firebase של גוגל שזה עוד יותר זול
-
@עידו @צדיק-תמים כל עוד אני עושה את זה בתור תחביב ולא בתור מקצוע - אני לא הולך לשלם...