  | 
              
	              
	                
  
    
	 
        ขอความช่วยเหลือ : ใครเคยเขียน code ตรวจสอบ EMS บางที่ดึงข้อมูลจากเว็บไปรษณีย์     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองไปนั่งอ่านดูครับ  >>> คลิก <<< 
 
Edit 1 - ไม่ทัน admin 555+                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2014-03-06 08:49:05              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-06 08:45:35 | 
                        By :
                            apisitp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 จะบอกว่า ทั้งลองแล้ว ใช้งานไม่ได้เลยครับ ขอโค้ดที่สามารถใช้งานได้จริงหน่อยครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-06 10:16:58 | 
                        By :
                            Art-B | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 มันขึ้นแต่แบบนี้ 
 
The requested URL was rejected. Please consult with your administrator. 
 
Your support ID is: 6111612062080013292                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-06 10:18:46 | 
                        By :
                            Art-B | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ไม่มีคนมาตอบเลยครับ ว่าทำไมถึงใช้ไม่ได้                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-07 09:01:51 | 
                        By :
                            Art-B | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 อยากพัฒนาใช้เอง ไม่อยากไปลิงค์กับ Host ของที่อื่น จะใช้ host ตัวเองวิ่งตรงไปที่ server ปณ. เลยครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-10 11:17:15 | 
                        By :
                            Art-B | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองทำอะไรไปบ้างแล้วครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-10 11:38:45 | 
                        By :
                            kerb | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 จริงๆเราสามารถเขียนโปรแกรมเพื่อ Post ไปยังหน้า track ems แล้ว get data มาโชว์ได้นะครับ  แต่ขอเสียของการทำแบบนี้คือถ้าทางเว็บไปรษณีย์มีการปรับเปลี่ยน process หรือ code บางอย่าง อันจะทำให้การทำงานผิดพลาดได้ ซึ่งผมมองว่าเค้าคงไม่ได้เปลี่ยนบ่อยหรอกครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-10 13:11:29 | 
                        By :
                            kerb | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ไม่มีโค้ดตัวอย่างครับ ลองเขียนเองเลยครับไม่ยาก ใช้ curl เข้ามาช่วยครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-10 16:28:20 | 
                        By :
                            kerb | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ใครเก่งช่วยแก้ไข พัฒนาต่อยอดให้ด้วยครับ 
 
Code (PHP) 
 <?php
        header('content-type: text/html; charset=tis-620;');
        define('urltrack', 'http://track.thailandpost.co.th/trackinternet');
        $track = "EK449227981TH";
        $c = cURL(urltrack . '/Default.aspx', null, null, null);
        preg_match('~"__VIEWSTATE" value="([^"]+)"~', $c, $m);
        $VIEWSTATE = urlencode($m[1]);
        preg_match('~"__EVENTVALIDATION" value="([^"]+)"~', $c, $m);
        $EVENTVALIDATION = urlencode($m[1]);
        if (trim($VIEWSTATE) || trim($VIEWSTATE)) {
            $c = cURL(urltrack . '/Default.aspx', true, null, '__EVENTTARGET=Login&__VIEWSTATE=' . $VIEWSTATE . '&__EVENTVALIDATION=' . $EVENTVALIDATION . '&TextBarcode=' . $track);
            if (preg_match('~ASP.NET_SessionId=(.+?);~', $c, $b)) {
                $c = cURL(urltrack . '/Result.aspx', null, $b[0], null);
                if (preg_match_all('~(<td style="width:[^"]+">.+)<\/td>~', $c, $m)) {
                    echo '<table>';
                    foreach ($m[1] as $k => $v) {
                        echo '<tr>' . str_replace('signature.aspx', urltrack . '/signature.aspx', $v) . '</tr>';
                    }
                    echo '</table>';
                } else {
                    echo 'Not found!!!';
                }
            }
        } else {
            echo 'System Error!!!';
        }
        function cURL($url, $header = NULL, $cookie = NULL, $p = NULL) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_HEADER, $header);
            curl_setopt($ch, CURLOPT_NOBODY, $header);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_COOKIE, $cookie);
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
            if ($p) {
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
            }
            $result = curl_exec($ch);
            if ($result) {
                return $result;
            } else {
                return curl_error($ch);
            }
            curl_close($ch);
        }
        ?>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-11 13:30:25 | 
                        By :
                            Art-B | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 มาอัพเดท พัฒนาได้เท่านี้ ติดปัญหาเรื่องส่งค่าไปหน้าผลลัพธ์ สุดท้ายใครก็ได้ช่วยหน่อย 
 
ว่าหน้าเพจ Result.aspx มันต้องการค่าอะไรบ้างที่ส่งไปหา เพราะแสดงผลลัพธ์ที่ถูกต้องได้ 
 
Code (PHP) 
<?php
ob_start();
session_start();
?>     
<?php
header('content-type: text/html; charset=tis-620;');
define('urltrack', 'http://track.thailandpost.co.th/trackinternet');
$track = "EK449227981TH";
function getHTML($url, $timeout) {
    $ch = curl_init($url); // initialize curl with given url
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set  useragent
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
    curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
    return @curl_exec($ch);
}
function getHTML2($url, $timeout, $para, $header) {
    $ch = curl_init($url); // initialize curl with given url
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set  useragent
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
    curl_setopt($ch, CURLOPT_HEADER, $header);
    curl_setopt($ch, CURLOPT_NOBODY, $header);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $para);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
    curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
    return @curl_exec($ch);
}
function getHTML3($url, $cookie) {
    $ch = curl_init($url); // initialize curl with given url
    $timeout = 10;
    curl_setopt($ch, CURLOPT_HEADER,null);
    curl_setopt($ch, CURLOPT_NOBODY, null);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set  useragent
    curl_setopt($ch, CURLOPT_URL, $url);
  
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
    return @curl_exec($ch);
}
$html = getHTML(urltrack . '/Default.aspx', 10);
preg_match("/<title>(.*)<\/title>/i", $html, $match);
$title = $match[1];
var_dump($match);
echo "<br>" . $title . "<br>";
preg_match('/<input(.*?)id=\"__VIEWSTATE\"(.*)value=\"(.*?)\"/i', $html, $match2);
$title2 = $match2[3];
//var_dump($match2);
echo "<br>" . $title2 . "<br>";
$VIEWSTATE = urlencode($title2);
//$VIEWSTATE = $title2;
preg_match('/<input(.*?)id=\"__EVENTVALIDATION\"(.*)value=\"(.*?)\"/i', $html, $match3);
$title3 = $match3[3];
//var_dump($match2);
echo "<br>" . $title3 . "<br>";
$EVENTVALIDATION = urlencode($title3);
$login = urlencode("Login");
$track = urlencode($track);
//$EVENTVALIDATION = $title3;
if (trim($VIEWSTATE) || trim($VIEWSTATE)) {
    $html = getHTML2(urltrack . '/Default.aspx', 10, '__EVENTTARGET=' . $login . '&__VIEWSTATE=' . $VIEWSTATE . '&__EVENTVALIDATION=' . $EVENTVALIDATION . '&TextBarcode=' . $track, true);
    // $html = cURL(urltrack . '/Default.aspx', true, null, '__EVENTTARGET=Login&__VIEWSTATE=' . $VIEWSTATE . '&__EVENTVALIDATION=' . $EVENTVALIDATION . '&TextBarcode=' . $track);
    if (preg_match('~ASP.NET_SessionId=(.+?);~', $html, $b)) {
        var_dump($b);
        preg_match('~TS0179c3ff=(.+?);~', $html, $b2);
        var_dump($b2);
        preg_match('~persist=(.+?);~', $html, $b3);
        var_dump($b3);
       // echo $c = cURL(urltrack . '/Result.aspx', null, $b[0], null);
       echo $c = getHTML3(urltrack . '/Result.aspx', $b[0] . ";" . $b2[0] . ";" . $b3[0]);
        //var_dump($b);
    }
} else {
    echo 'System Error!!!';
}
   
       
?>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-03-12 11:35:38 | 
                        By :
                            Art-B | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ถ้าทำได้แล้วขอคำปรึกษาด้วยครับ กำลังหาวิธีอยู่เลยครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-11-24 10:01:48 | 
                        By :
                            ิN@s | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เรื่องแบบนี้มันไม่ใช่ใครเก่งแล้วจะทำได้นะครับ 
 
เป็นเรื่องของไม่รู้ format ui ที่จะใช้ติดต่อกับไปรณีย์เท่านั้น 
อยากให้ใช้งานได้จริง ก็แค่เข้าไปติดต่อกับไปรณ๊ย์ ขอ ui เขามา 
ถ้าเขาอนุญาต ก็ไปต่อได้ง่ายๆ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-11-24 12:24:20 | 
                        By :
                            NewbiePHP | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 มันเคยใช้ได้ แต่ตอนนี้ไปรษณีย์เปลี่ยนรุปแบบใหม่แล้วครับ 
 
  
 
ส่วนหนึ่งที่เอาออก เข้าใจว่ามีการ Request มากจนเกินไป ทั้งใช้งานจริงและ Spam สุดท้ายน่าจะเป็นการต้องการความถูกต้องคือ ป้องกันพวก Scamp เลยให้ตรวจสอบเว็บของไปรษณีย์โดยตรง                        
               
               | 
             
            
              
			  			  
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-11-24 12:51:44 | 
                        By :
                            mr.win | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 <? 
 
$tracking=$_GET['tracking']; 
$ch = curl_init(); 
										$url2="http://www.thailandpost.com/php/webservice.php"; 
										curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  
										curl_setopt($ch, CURLOPT_URL, $url2); 
										curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
										curl_setopt($ch, CURLOPT_POSTFIELDS, "action=getTrack&barcode=$tracking&language_id="); 
										$result=curl_exec ($ch); 
										curl_close ($ch); 
$obj = json_decode($result,true); 
 
 
    
   foreach($obj as $a) 
{ 
	echo "$a[DateTime] $a[Location] $a[StatusName] $a[Description]<br />" 
 } 
?>                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-01-22 20:37:51 | 
                        By :
                            pong | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
      		  
	
     | 
   
 
                 |