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

    בקשה מימות המשיח בקשר למעבר לשרתי Private

    פורום מפתחים API
    8
    32
    792
    טוען פוסטים נוספים
    • מהישן לחדש
    • מהחדש לישן
    • הכי הרבה הצבעות
    תגובה
    • הגיבו כנושא
    התחברו בכדי לפרסם תגובה
    נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
    • ק
      קביעתא @חוקר נערך לאחרונה על ידי

      @חוקר ואפשר גם שימות יגדירו שאם המספר קיים בשרת הפרייוט שישלח קוד שגיאה מסודר

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

        @קביעתא אמר בבקשה מימות המשיח בקשר למעבר לשרתי Private:

        @חוקר ואפשר גם שימות יגדירו שאם המספר קיים בשרת הפרייוט שישלח קוד שגיאה מסודר

        תבין ששרת הפריווט הוא נפרד לגמרי ולע"ע המערכת באמת לא יודעת שזה קיים שם.

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

          @חוקר אמר בבקשה מימות המשיח בקשר למעבר לשרתי Private:

          אם משתמשים במחלקה מסודרת ניתן בקצת יותר קלות להסתדר.
          משנים את הurl במחלקה עבור כל המחלקה.
          ואם יש מערכות של כאן ושם ניתן להוסיף למחלקה משתנה בשם פריווט והמחלקה מזהה אם הוא אמת או בשקר לשנות את ה url לפי זה.
          ובעת יצירת מחלקה מעבירים יחד עם הנספר את הערך הנכון פריווט

          אני משתמש עם המחלקה של מאזין נלהב
          לא הסתדרתי עם זה
          מה אני אמור לשנות שם?

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

            @חוקר @איש-ימיני
            אני גם אשמח לדעת על מה עושים את התנאי במחלקה של @מאזין-נלהב בשביל ישלח לכתובת של הפרייבט, אני כבר מסתבך בזה הרבה זמן.
            תודה למסייעים @bc98400

            תגובה 1 תגובה אחרונה תגובה ציטוט 0
            • B
              bc98400 נערך לאחרונה על ידי

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

              תגובה 1 תגובה אחרונה תגובה ציטוט 0
              • B
                bc98400 נערך לאחרונה על ידי

                הכתובת נמצאת בשורה 93
                או להוסיף תנאי לשורה 127

                D תגובה 1 תגובה אחרונה תגובה ציטוט 0
                • D
                  dudu @bc98400 נערך לאחרונה על ידי

                  @bc98400 איך אפשר להוסיף תנאי?
                  הרי המשתנה של הכתובת הוא משתנה קבוע שערכו נקבע בהגדרה הראשונית וא"א לשנות אותו אח"כ?

                  B תגובה 1 תגובה אחרונה תגובה ציטוט 0
                  • B
                    bc98400 @dudu נערך לאחרונה על ידי

                    @dudu @איש-ימיני
                    זה צריך להיות משהו כזה (זה לא מדוייק כי לא בדקתי לעומק עשיתי את זה ככה מלמעלה)

                    
                    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
                                {
                                    const URL = 'https://private.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;
                        }
                    }
                    
                    

                    השורות שהוספתי זה מ 128 עד 164

                    מ D 2 תגובות תגובה אחרונה תגובה ציטוט 0
                    • מ
                      ממפ @bc98400 נערך לאחרונה על ידי

                      @bc98400 לא עובד.
                      יש בעיה בתנאי כנראה, מופיע שגיאה על השורה של הכתובת:
                      d11ca10c-a56b-4c58-8862-b73718c15bdf-image.png

                      תגובה 1 תגובה אחרונה תגובה ציטוט 0
                      • D
                        dudu @bc98400 נערך לאחרונה על ידי

                        @bc98400
                        זה לא יכול לעבוד,
                        אין אפשרות להגדיר את המשתנה const פעם נוספת.
                        ניסיתי את זה ליר ביטחון על מחלקה סתם, וראיתי אכן שזה לא נותן.

                        אולי אפשר להפוך את המשנה מ const ל private השאלה אם זה לא יפגע בתפקוד שלו בשאר הדברים...

                        אין פה מישהו שכבר עשה כזה תנאי או משהו כזה?

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

                          מה אתם רוצים ? שתוכלו לשלוח בGET לדף שבו אתם נמצאים ערך וזה ישים בכתובת מה שצריך?

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

                            @שמואל בדיוק! יש סיכוי לכזה דבר??

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

                              @ממפ אמר בבקשה מימות המשיח בקשר למעבר לשרתי Private:

                              @שמואל בדיוק! יש סיכוי לכזה דבר??

                              צ"ע

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

                                אני שיחקתי עם המחלקה של @חוקר ככה:

                                הורדתי את :

                                const URL = 'https://www.call2all.co.il/ym/api/';
                                

                                והוספתי בפונקציית הבנייה __construct

                                את השורות הבאות:

                                global $private;
                                $this -> url = 'https://'.$private.'.call2all.co.il/ym/api/';
                                

                                אחר כך החלפתי כל מקום שהיה

                                self::URL
                                

                                ב:

                                $this -> url
                                

                                ⁉

                                תגובה 1 תגובה אחרונה תגובה ציטוט 1
                                • D
                                  dudu נערך לאחרונה על ידי

                                  אני עכשיו מצאתי פתרון אחר.
                                  במקום השורה:

                                  const URL = 'https://www.call2all.co.il/ym/api/';
                                  

                                  כתבתי

                                  private $URLFirst = 'https://www.call2all.co.il/ym/api/';
                                  

                                  ואת פונקציית הבנייה שיניתי שתקבל עוד משתנה, ככה:

                                  public function __construct($user_name, $password, $private = false)
                                  

                                  והוספתי תנאי בתחילת הפונקציה:

                                  if($private)
                                              $this -> URLFirst = 'https://private.call2all.co.il/ym/api/';
                                  

                                  וכמובן אח"כ בשני המקומות שהופיע:

                                  self::URL
                                  

                                  החלפתי ל:

                                  $this -> URLFirst
                                  

                                  ובסה"כ המחלקה נראית כך:

                                  class connecting_to_yemot_api
                                  {
                                      public $token;
                                   
                                      private $URLFirst = 'https://www.call2all.co.il/ym/api/';
                                   
                                      public function __construct($user_name, $password, $private = false)
                                      {
                                          if($private)
                                              $this -> URLFirst = 'https://private.call2all.co.il/ym/api/';
                                              
                                          $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 = $this -> URLFirst.'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 = $this -> URLFirst.$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;
                                      }
                                  }
                                  

                                  לא בדקתי את זה על שרת פרייבט כי אין לי, אבל על השרת הרגיל זה עובד, אין סיבה לכאורה שלא יעבוד גם על פרייבט.

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

                                    אני מצאתי פתרון אחר.

                                    פשוט define בתחילת הקובץ של הURL.
                                    אם שולחים (GET) ערך SetSite=private זה פונה לפריווט

                                    כמובן עשיתי בערך URL:

                                    const URL = URL;
                                    

                                    בדקתי בשתי השרתים וזה עובד.

                                    וככה זה נראה:

                                    <?php
                                    $SetSite = $_GET["SetSite"];
                                    	if ($SetSite == NULL) {
                                    	define("URL", "https://www.call2all.co.il/ym/api/");
                                    }
                                    	if ($SetSite == "private") {
                                    	define("URL", "https://private.call2all.co.il/ym/api/");
                                    }
                                    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;
                                        }
                                    }
                                    

                                    את המחלקה לקחתי מ https://freeivr.co.il/oldforum/viewtopic.php?t=2780

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

                                      @שמואל לכאורה אתה צודק, אני ניסיתי בהתחלה להכיל את הערך של const URL עם משתנה וזה לא עבד, כי const הוא קבוע ולא יכול לקבל ערך של משתנה, אבל אין סיבה לכאורה שהוא לא יקבל ערך של קבוע כמו שעשית

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

                                        @שואל-ברצינות נכון. גם אני נתקלתי בזה. לא נכנס שם משתנה בשום צורה. אז עשיתי ככה...

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

                                          @שמואל עשיתי בדיקה על אחת המחלקות ולא עובד:

                                          <?php
                                          /*================יצירת אובייקט(מופע) חדש====================*/
                                           
                                          $con = new connecting_to_yemot_api('0*********', '1212');
                                          /*================קבלת מספר היחידות====================*/
                                          $a = $con -> connecting('GetSession');
                                          print_r($a);
                                           
                                          /*===============================================================*/
                                          
                                          $SetSite = $_GET["SetSite"];
                                          	if ($SetSite == NULL) {
                                          	define("URL", "https://www.call2all.co.il/ym/api/");
                                          }
                                          	if ($SetSite == "private") {
                                          	define("URL", "https://private.call2all.co.il/ym/api/");
                                          }
                                          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;
                                              }
                                          }
                                          ?>
                                          

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

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

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