• דף הבית
    • אינדקס קישורים
    • פוסטים אחרונים
    • משתמשים
    • חיפוש בהגדרות המתקדמות
    • חיפוש גוגל בפורום
    • ניהול המערכת
    • ניהול המערכת - שרת private
    • הרשמה
    • התחברות

    מדריך התחלת עבודה עם API של ימות משיח (חלק ב').

    מתוזמן נעוץ נעול הועבר פורום מפתחים API
    24 פוסטים 8 כותבים 3.2k צפיות 2 עוקבים
    טוען פוסטים נוספים
    • מהישן לחדש
    • מהחדש לישן
    • הכי הרבה הצבעות
    תגובה
    • תגובה כנושא
    התחברו כדי לפרסם תגובה
    נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
    • מ מנותק
      מנסה @yonatan
      נערך לאחרונה על ידי

      @yonatan

      אני לא יודע בדיוק מה הבעיה ואין לי כח לבדוק שורה אחרי שורה,אבל גם אני אתמול ניסיתי להעלות קובץ עם המחלקה וזה החזיר שגיאות כל הזמן.

      אז העתקתי את המחלקה המקורית [מהפורום הישן] וזה עבד מצויין.

      הנה המחלקה

      class BodyPost
      {
      // part "multipart/form-data"
      public static function PartPost($name, $val)
      {
      $body = 'Content-Disposition: form-data; name="' . $name . '"';
      // check instance of oFile
      if($val instanceof oFile)
      {
      $file = $val->Name();
      $mime = $val->Mime();
      $cont = $val->Content();
      
      $body .= '; filename="' . $file . '"' . "\r\n";
      $body .= 'Content-Type: ' . $mime ."\r\n\r\n";
      $body .= $cont."\r\n";
      } else $body .= "\r\n\r\n".$val."\r\n";
      return $body;
      }
      
      public static function Get(array $post, $delimiter = '-------------0123456789')
      {
      if(is_array($post) && !empty($post))
      {
      $bool = true;
      //foreach($post as $val) if($val instanceof oFile) {$bool = true; break; };
      if($bool)
      {
      $ret = '';
      foreach($post as $name=>$val)
      $ret .= '--' . $delimiter. "\r\n". self::PartPost($name, $val);
      $ret .= "--" . $delimiter . "--\r\n";
      } else $ret = http_build_query($post);
      } else throw new \Exception('Error input param!');
      return $ret;
      }
      }
      
      class oFile
      {
      private $name;
      private $mime;
      private $content;
      
      public function __construct($name, $mime=null, $content=null)
      {
      if(is_null($content))
      {
      $info = pathinfo($name);
      // check is exist and readable file
      if(!empty($info['basename']) && is_readable($name))
      {
      $this->name = $info['basename'];
      // get MIME
      $this->mime = mime_content_type($name);
      // load file
      $content = file_get_contents($name);
      if($content!==false)
      {
      $this->content = $content;
      }
      else
      {
      throw new Exception('Don`t get content - "'.$name.'"');
      }
      }
      else
      {
      throw new Exception('Error param');
      }
      }
      else
      {
      $this->name = $name;
      if(is_null($mime)) $mime = mime_content_type($name);
      $this->mime = $mime;
      $this->content = $content;
      };
      }
      
      public function Name() { return $this->name; }
      
      public function Mime() { return $this->mime; }
      
      public function Content() { return $this->content; }
      
      }
      
      class connecting_to_yemot_api
      {
      public $token;
      
      const URL = 'https://www.call2all.co.il/ym/api/';
      
      public function __construct($user_name, $password)
      {
      $body = array('username' => $user_name, 'password' => $password);
      
      $body = http_build_query($body);
      
      $opts = array('http' => array(
      
      'method' => 'POST',
      
      'header' => "Content-Type: application/x-www-form-urlencoded",
      
      'content' => $body,
      
      'follow_location' => false) );
      
      $context = stream_context_create($opts);
      
      $url = self::URL.'Login';
      
      $result = file_get_contents($url, FALSE, $context);
      
      $result = json_decode($result);
      
      if($result -> responseStatus == 'OK')
      {
      $this -> token = $result -> token;
      
      return TRUE;
      }
      else
      {
      throw new Exception('שם המשתמש או הסיסמא של המערכת שגויים');
      }
      }
      
      public function __destruct()
      {
      $this -> connecting('Logout');
      }
      
      public function connecting($action, $body = array())
      {
      $delimiter = '----'.uniqid();
      
      $body['token'] = $this -> token;
      
      $body = BodyPost::Get($body, $delimiter);
      
      $opts = array('http' =>
      array(
      'method' => 'POST',
      'header' => 'Content-Type: multipart/form-data; boundary='.$delimiter,
      'content' => $body,
      'follow_location' => false
      )
      );
      $context = stream_context_create($opts);
      
      $url = self::URL.$action;
      
      $result = file_get_contents($url, FALSE, $context);
      
      $headers = $this -> parseHeaders($http_response_header);
      
      if($headers['Content-Type'][0] == 'application/json')
      {
      return json_decode($result);
      }
      else
      {
      return $result;
      }
      }
      
      private function parseHeaders($headers)
      {
      // פונקציה שמקבלת מערך של שורות הכותרות
      // הפונקציה מפרקת את קבצי הקוקי לתת-מערך נפרד
      
      
      // מערך הכותרות
      $head = array();
      
      foreach( $headers as $k=>$v )
      {
      $t = explode( ':', $v, 2 );
      
      if( isset( $t[1] ) )
      {
      if($t[0] == 'Set-Cookie')
      {
      $CookiesArr = array();
      
      $cookies = explode( ';', $t[1]);
      
      foreach($cookies as $cookie)
      {
      $c = explode( '=', $cookie);
      
      if( isset( $c[1] ) )
      {
      $CookiesArr[ trim($c[0]) ] = trim( $c[1] );
      }
      else
      {
      $CookiesArr[] = trim( $c[0] );
      }
      }
      
      $head[ trim($t[0]) ] = $CookiesArr;
      }
      elseif($t[0] == 'Content-Type')
      {
      $arr = array();
      
      $children = explode( ';', $t[1]);
      
      foreach($children as $child)
      {
      $c = explode( '=', $child);
      
      if( isset( $c[1] ) )
      {
      $arr[ trim($c[0]) ] = trim( $c[1] );
      }
      else
      {
      $arr[] = trim( $c[0] );
      }
      }
      
      $head[ trim($t[0]) ] = $arr;
      }
      else
      {
      $head[ trim($t[0]) ] = trim( $t[1] );
      }
      }
      else
      {
      $head[] = $v;
      if( preg_match( "#HTTP/[0-9\.]+\s+([0-9]+)#",$v, $out ) )
      {
      $head['reponse_code'] = intval($out[1]);
      }
      }
      }
      return $head;
      }
      }
      

      והנה החלקים שמצרפים המקוריים

      הזדהות [חובה]

      /*================יצירת אובייקט(מופע) חדש====================*/
      
      $con = new connecting_to_yemot_api('0773137770', '0000');
      
      

      שאר סוגי הפעולות לצירוף

      /*================קבלת מספר היחידות====================*/
      
      $a = $con -> connecting('GetSession');
      
      print_r($a);
      
      /*===============================================================*/
      
      
      
      /*================הפעלת קמפיין====================*/
      
      $body = array
      (
      // מספר הקמפיין
      'templateId' => '203584',
      );
      
      $a = $con -> connecting('RunCampaign', $body);
      
      print_r($a);
      
      /*===============================================================*/
      
      
      /*================הורדת קובץ====================*/
      
      $body = array
      (
      // נתיב הקובץ
      'path' => 'ivr/ext.ini',
      );
      
      $a = $con -> connecting('DownloadFile', $body);
      
      print_r($a);
      
      /*===============================================================*/
      
      
      
      /*================העלאת קובץ====================*/
      
      // יצירת הקובץ
      $File = new oFile('ext.ini', 'text/plain', 'type=menu');
      
      $body = array
      (
      'path' => 'ivr/ext.ini',
      'convertAudio' => 0,
      'fileUpload' => $File
      );
      
      $a = $con -> connecting('UploadFile', $body);
      
      print_r($a);
      
      /*===============================================================*/
      להלן המחלקה:
      קוד: בחירת הכל
      

      מקור

      וקרדיט ענק ל @מאזין-נלהב

      תגובה 1 תגובה אחרונה תגובה ציטוט 1
      • Y מנותק
        yonatan @ASS
        נערך לאחרונה על ידי

        @ass עכשיו אין שגיאה אבל לא מחזיר נתונים

        מ תגובה 1 תגובה אחרונה תגובה ציטוט 0
        • מ מנותק
          מנסה @yonatan
          נערך לאחרונה על ידי מנסה

          @yonatan

          כי לא כתבת לו להחזיר נתונים

          תוסיף את זה

          print_r $File_list;
          
          Y תגובה 1 תגובה אחרונה תגובה ציטוט 0
          • Y מנותק
            yonatan @מנסה
            נערך לאחרונה על ידי

            @מנסה הוא מחזיר שיש לו בעיה עם השורה הזאת

            מ תגובה 1 תגובה אחרונה תגובה ציטוט 0
            • מ מנותק
              מנסה @yonatan
              נערך לאחרונה על ידי

              @yonatan

              ערכתי אותה מקודם

              תנסה

              print_r ($File_list);
              

              אם לא אז תנסה

              print $File_list;
              
              
              Y תגובה 1 תגובה אחרונה תגובה ציטוט 0
              • Y מנותק
                yonatan @מנסה
                נערך לאחרונה על ידי

                @מנסה לא עובד

                A תגובה 1 תגובה אחרונה תגובה ציטוט 0
                • A מנותק
                  ASS @yonatan
                  נערך לאחרונה על ידי

                  @yonatan
                  אולי תעלה פה את הקוד המלא (אני מניח שעדכנת אותו מאז הפוסט הקודם ) ואני יבדוק אצלי.

                  תגובה 1 תגובה אחרונה תגובה ציטוט 0
                  • מ מנותק
                    מנחם עזריה
                    נערך לאחרונה על ידי

                    כתבתי ככה ועושה לי שגיאה מה הבעיה?

                    <?php

                    echo "זה קוד PHP";
                    //בשרת רגיל
                    define("URL", "https://www.call2all.co.il/ym/api/");
                    //בשרת פרייבט
                    //define("URL", "https://private.call2all.co.il/ym/api/");
                    //בשרת רגיל
                    //משתנה כדי למנוע בעיות בהעלאת קבצים בהמשך
                    $server = "www";
                    //בשרת פרייבט
                    //$server = "private";
                    class BodyPost
                    {
                    // part "multipart/form-data"
                    public static function PartPost($name, $val)
                    {
                    $body = 'Content-Disposition: form-data; name="' . $name . '"';
                    // check instance of oFile
                    if($val instanceof oFile)
                    {
                    $file = $val->Name();
                    $mime = $val->Mime();
                    $cont = $val->Content();

                              $body .= '; filename="' . $file . '"' . "\r\n";
                              $body .= 'Content-Type: ' . $mime ."\r\n\r\n";
                              $body .= $cont."\r\n";
                          } else $body .= "\r\n\r\n".$val."\r\n";
                         return $body;
                     }
                    
                    public static function Get(array $post, $delimiter = '-------------0123456789')
                     {
                         if(is_array($post) && !empty($post))
                          {
                              $bool = true;
                              //foreach($post as $val) if($val instanceof oFile) {$bool = true; break; };
                              if($bool)
                               {
                                   $ret = '';
                                   foreach($post as $name=>$val)
                                       $ret .= '--' . $delimiter. "\r\n". self::PartPost($name, $val);
                                   $ret .= "--" . $delimiter . "--\r\n";
                               } else $ret = http_build_query($post);
                          } else throw new \Exception('Error input param!');
                         return $ret;
                     }
                    

                    }

                    class oFile
                    {
                    private $name;
                    private $mime;
                    private $content;

                     public function __construct($name, $mime=null, $content=null)
                      {
                          if(is_null($content))
                           {
                               $info = pathinfo($name);
                    

                    // check is exist and readable file
                    if(!empty($info['basename']) && is_readable($name))
                    {
                    $this->name = $info['basename'];
                    // get MIME
                    $this->mime = mime_content_type($name);
                    // load file
                    $content = file_get_contents($name);
                    if($content!==false)
                    {
                    $this->content = $content;
                    }
                    else
                    {
                    throw new Exception('Don`t get content - "'.$name.'"');
                    }
                    }
                    else
                    {
                    throw new Exception('Error param');
                    }
                    }
                    else
                    {
                    $this->name = $name;
                    if(is_null($mime)) $mime = mime_content_type($name);
                    $this->mime = $mime;
                    $this->content = $content;
                    };
                    }

                    public function Name() { return $this->name; }
                    
                    public function Mime() { return $this->mime; }
                    
                    public function Content() { return $this->content; }
                    

                    }

                    class connecting_to_yemot_api
                    {
                    public $token;

                    const URL = URL;
                    
                    public function __construct($user_name, $password)
                    {
                        $body = array('username' => $user_name, 'password' => $password);
                    
                        $body = http_build_query($body);
                    
                        $opts = array('http' => array(
                    
                            'method'  => 'POST',
                    
                            'header'  => "Content-Type: application/x-www-form-urlencoded",
                    
                            'content' => $body,
                    
                            'follow_location' => false) );
                    
                         $context  = stream_context_create($opts);
                    
                         $url = self::URL.'Login';
                    
                            $result = file_get_contents($url, FALSE, $context);
                    
                            $result = json_decode($result);
                    
                            if($result -> responseStatus == 'OK')
                            {
                                $this -> token = $result -> token;
                    
                                return TRUE;
                            }
                            else
                            {
                                throw new Exception('שם המשתמש או הסיסמא של המערכת שגויים');
                            }
                    }
                    
                    public function __destruct()
                    {
                        $this -> connecting('Logout');
                    }
                    
                    public function connecting($action, $body = array())
                    {
                        $delimiter = '----'.uniqid();
                    
                        $body['token'] = $this -> token;
                    
                        $body = BodyPost::Get($body, $delimiter);
                    
                        $opts = array('http' =>
                                array(
                                    'method'  => 'POST',
                                    'header'  => 'Content-Type: multipart/form-data; boundary='.$delimiter,
                                    'content' => $body,
                                    'follow_location' => false
                                    )
                                  );
                        $context  = stream_context_create($opts);
                    
                        $url = self::URL.$action;
                    
                        $result = file_get_contents($url, FALSE, $context);
                    
                        $headers = $this -> parseHeaders($http_response_header);
                    
                        if($headers['Content-Type'][0] == 'application/json')
                        {
                            return json_decode($result);
                        }
                        else
                        {
                            return $result;
                        }
                    }
                    
                    private function parseHeaders($headers)
                    {
                        // פונקציה שמקבלת מערך של שורות הכותרות
                        // הפונקציה מפרקת את קבצי הקוקי לתת-מערך נפרד
                    
                    
                        // מערך הכותרות
                        $head = array();
                    
                        foreach( $headers as $k=>$v )
                        {
                            $t = explode( ':', $v, 2 );
                    
                            if( isset( $t[1] ) )
                            {
                                if($t[0] == 'Set-Cookie')
                                {
                                    $CookiesArr = array();
                    
                                    $cookies = explode( ';', $t[1]);
                    
                                    foreach($cookies as $cookie)
                                    {
                                        $c = explode( '=', $cookie);
                    
                                        if( isset( $c[1] ) )
                                        {
                                            $CookiesArr[ trim($c[0]) ] = trim( $c[1] );
                                        }
                                        else
                                        {
                                            $CookiesArr[] = trim( $c[0] );
                                        }
                                    }
                    
                                    $head[ trim($t[0]) ] = $CookiesArr;
                                }
                                elseif($t[0] == 'Content-Type')
                                {
                                    $arr = array();
                    
                                    $children = explode( ';', $t[1]);
                    
                                    foreach($children as $child)
                                    {
                                        $c = explode( '=', $child);
                    
                                        if( isset( $c[1] ) )
                                        {
                                            $arr[ trim($c[0]) ] = trim( $c[1] );
                                        }
                                        else
                                        {
                                            $arr[] = trim( $c[0] );
                                        }
                                    }
                    
                                    $head[ trim($t[0]) ] = $arr;
                                }
                                else
                                {
                                    $head[ trim($t[0]) ] = trim( $t[1] );
                                }
                            }
                            else
                            {
                                $head[] = $v;
                                if( preg_match( "#HTTP/[0-9\.]+\s+([0-9]+)#",$v, $out ) )
                                {
                                    $head['reponse_code'] = intval($out[1]);
                                }
                            }
                        }
                        return $head;
                    }
                    

                    }
                    //שם משתמש וסיסמא של המערכת
                    $con = new connecting_to_yemot_api('077*****','');
                    $token = "077
                    :****";

                    //נתיב
                    $path = "ivr2:/2";

                    // פונקציה למספרי קבצים עוקבים
                    function FileNameToUpload($server, $token, $path){
                    $array = json_decode(file_get_contents("https://$server.call2all.co.il/ym/api//GetIVR2Dir?token=$token&path=$path"),true);
                    if($array["responseStatus"] == "OK"){
                    foreach($array["files"] as $key => $value){
                    if($value["fileType"] == "AUDIO" || $value["fileType"] == "TTS"){
                    $split = explode(".",$value["name"]);
                    if (is_numeric($split[0])){
                    break;
                    }
                    }
                    }
                    if($split[0] == null){
                    $NewFileName = 0;
                    }else{
                    $NewFileName = $split[0]+1;
                    }
                    //הפוך למינימום 3 ספרות/
                    return str_pad($NewFileName,3,"0",STR_PAD_LEFT);
                    }else{
                    //במקרה של שגיאה
                    echo "שגיאה";

                    }
                    

                    }
                    // קריאה לפונקציה.
                    $NewFileName = FileNameToUpload($server,$token,$path);
                    if($NewFileName != null){
                    //מכריז על שם של נתיב הקובץ להעלאה
                    $path_name = "$path/$NewFileName.wav";
                    }

                    //מאיפה לקחת את הקובץ
                    $File = new oFile('ext.ini', 'text/plain', file_get_contents("...."));

                    //להעלאת קבצים פקודה
                    $Upload_order = $con -> connecting('UploadFile',
                    [
                    //טוקן
                    'path' =>$path_name,
                    //המרה ל-wav אם מוגדר על 1 הקובץ יומר אם מוגדר על 0 לא
                    'convertAudio' => 1,
                    //קובץ להעלאה
                    'fileUpload' => $File
                    ]
                    );

                    ?>

                    ל תגובה 1 תגובה אחרונה תגובה ציטוט 0
                    • ל מנותק
                      לעזור לכולם @מנחם עזריה
                      נערך לאחרונה על ידי

                      @מנחם-עזריה
                      איפה הוא נותן לך שגיאה בטלפון או בדפדפן?

                      תגובה 1 תגובה אחרונה תגובה ציטוט 0
                      • ש מנותק
                        שמואל מאיר @ASS
                        נערך לאחרונה על ידי

                        @ASS את כל מה שאתה אומר להעתיק זה לאותו קובץ ראשון שפתחתי?

                        A תגובה 1 תגובה אחרונה תגובה ציטוט 0
                        • A מנותק
                          ASS @שמואל מאיר
                          נערך לאחרונה על ידי

                          @שמואל-מאיר כתב במדריך התחלת עבודה עם API של ימות משיח (חלק ב').:

                          אותו קובץ ראשון שפתחתי?

                          בדיוק

                          תגובה 1 תגובה אחרונה תגובה ציטוט 0
                          • ש מנותק
                            שמואל מאיר @ASS
                            נערך לאחרונה על ידי

                            @ASS עשיתי את כל מה שרשום וזה לא אומר שגיאה וגם לא מעלה את הקובץ לשלוחה.

                            ש תגובה 1 תגובה אחרונה תגובה ציטוט 0
                            • ש מנותק
                              שמואל מאיר @שמואל מאיר
                              נערך לאחרונה על ידי

                              פוסט זה נמחק!
                              ל תגובה 1 תגובה אחרונה תגובה ציטוט 0
                              • ל מנותק
                                לעזור לכולם @שמואל מאיר
                                נערך לאחרונה על ידי

                                @שמואל-מאיר
                                זה אומר שאין לך מספיק מקום בשרת ואתה צריך להגדיל את הנפח שלו

                                ש תגובה 1 תגובה אחרונה תגובה ציטוט 0
                                • ש מנותק
                                  שמואל מאיר @לעזור לכולם
                                  נערך לאחרונה על ידי

                                  @לעזור-לכולם מה זאת אומרת יש לי במחשב המון מקום, ועשיתי שהמחשב יהיה שרת כמו שכתב שם בהדרכה.

                                  ש תגובה 1 תגובה אחרונה תגובה ציטוט 0
                                  • ש מנותק
                                    שמואל מאיר @שמואל מאיר
                                    נערך לאחרונה על ידי

                                    @ASS @לעזור-לכולם מה קורה אף אחד לא יכול לעזור לי קצת?

                                    תגובה 1 תגובה אחרונה תגובה ציטוט 0
                                    • ש מנותק
                                      שמואל מאיר
                                      נערך לאחרונה על ידי

                                      זה עכשיו כותב לי כך:
                                      Screenshot_3.png

                                      תגובה 1 תגובה אחרונה תגובה ציטוט 0
                                      • פוסט ראשון
                                        פוסט אחרון