<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; curl</title>
	<atom:link href="https://www.yunda51.com/?feed=rss2&#038;tag=curl" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>CURL模拟进行微信接口的GET与POST</title>
		<link>https://www.yunda51.com/?p=1475</link>
		<comments>https://www.yunda51.com/?p=1475#comments</comments>
		<pubDate>Wed, 31 Dec 2014 06:38:16 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[php技术]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[Post]]></category>
		<category><![CDATA[微信]]></category>
		<category><![CDATA[接口]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1475</guid>
		<description><![CDATA[Get提交获取数据 /** * @desc 获取access_token * @return String a<a href="https://www.yunda51.com/?p=1475" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>Get提交获取数据</strong></p>
<pre class="wp-code-highlight prettyprint">
           /** 
            * @desc 获取access_token 
            * @return String access_token 
            */  
           function getAccessToken(){  
               $AppId = &#039;1232assad13213123&#039;;  
               $AppSecret = &#039;2312312321adss3123213&#039;;  
               $getUrl = &#039;https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid=&#039;.$AppId.&#039;&amp;secret=&#039;.$AppSecret;  
               $ch = curl_init();  
               curl_setopt($ch, CURLOPT_URL, $getUrl);  
               curl_setopt($ch, CURLOPT_HEADER, 0);  
               curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
               curl_setopt($ch, CURL_SSLVERSION_SSL, 2);  
               curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
               curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
               $data = curl_exec($ch);  
               $response = json_decode($data);  
               return $response-&gt;access_token;  
           }  
</pre>
<p><strong>Post提交获取数据</strong></p>
<pre class="wp-code-highlight prettyprint">
            /** 
             * @desc 实现天气内容回复 
             */  
            public function testWeixin(){  
                $access_token = $this-&gt;getAccessToken();  
                $customMessageSendUrl = &#039;https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=&#039;.$access_token;  
                $description = &#039;今天天气的详细信息（从第三方获取）。&#039;;  
                $url = &#039;http://weather.com/&#039;;  
                $picurl = &#039;http://weather.com/&#039;;  
                $postDataArr = array(  
                    &#039;touser&#039;=&gt;&#039;OPENID&#039;,  
                    &#039;msgtype&#039;=&gt;&#039;news&#039;,  
                    &#039;news&#039;=&gt;array(  
                        &#039;articles&#039;=&gt;array(  
                            &#039;title&#039;=&gt;&#039;当天天气&#039;,  
                            &#039;description&#039;=&gt;$description,  
                            &#039;url&#039;=&gt;$url,  
                            &#039;picurl&#039;=&gt;$picurl,  
                        ),  
                    ),  
                );  
                $postJosnData = json_encode($postDataArr);  
                $ch = curl_init($customMessageSendUrl);      
                curl_setopt($ch, CURLOPT_HEADER, 0);      
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      
                curl_setopt($ch, CURLOPT_POST, 1);      
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postJosnData);    
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
                $data = curl_exec($ch);      
                var_dump($data);  
            }  
</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a>  原文地址：<a href="http://www.yunda51.com/1475.html">http://www.yunda51.com/1475.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1475</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>curl抓取(thinkphp自动审核)</title>
		<link>https://www.yunda51.com/?p=1190</link>
		<comments>https://www.yunda51.com/?p=1190#comments</comments>
		<pubDate>Tue, 21 Jan 2014 07:23:30 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[php技术]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[gzip编码]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Thinkphp]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1190</guid>
		<description><![CDATA[最近在做Thinkphp项目的时候需要写一个自动审核数据的功能,根据Curl来抓取对比,并且每隔十秒会自动刷新<a href="https://www.yunda51.com/?p=1190" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>最近在做Thinkphp项目的时候需要写一个自动审核数据的功能,根据Curl来抓取对比,并且每隔十秒会自动刷新页面审核!<br />
代码如下:<br />
首先创建:textpageAction.class.php</p>
<pre class="wp-code-highlight prettyprint">
//检测字符串编码的方法,将编码$code转换为utf-8编码!
function safeEncoding($str){
	$code=mb_detect_encoding($str,array(&#039;GB2312&#039;,&#039;GBK&#039;,&#039;UTF-8&#039;,&#039;ASCII&#039;));//检测字符串编码
	if($code==&quot;CP936&quot;){
		$result=$str;
	}else{
		//$result=mb_convert_encoding($str,&#039;UTF-8&#039;,$code);//将编码$code转换为utf-8编码
		$result=iconv($code,&quot;UTF-8&quot;,$str);
	}
		return $result;
}
///这个方法可以用来测试用
function ceshi(){
	include(&#039;simple_html_dom.php&#039;);
	$ch = curl_init();
		$timeout = 10; 
		curl_setopt ($ch, CURLOPT_URL, &quot;http://bj.ohqly.com/1511/2014011548894568v0.html&quot;);
                ////模式器,如果别人网站拦截了,加上这句话就ok了////
                curl_setopt ( $ch, CURLOPT_USERAGENT, &#039;Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1)&#039;);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt($curl, CURLOPT_BINARYTRANSFER, true) ;
		curl_setopt($curl, CURLOPT_ENCODING, &#039;gzip,deflate&#039;);
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$html = curl_exec($ch);
		curl_close($ch);
		$html=$this-&gt;safeEncoding($html);
		var_dump($html);
		//dump($html);
		$html=str_get_html($html);
		foreach($html-&gt;find(&#039;h1&#039;) as $e) {
			echo $e-&gt;innertext . &#039;&lt;br&gt;&#039;;
			$val= $e-&gt;innertext;
			//$val=rtrim($val);
			//$val=ltrim($val);
			dump(stripos(&quot;本田思域 2009款 1.8 VTI 自动豪华版&quot;,$val)!==false);
		}
	exit();
}

///自动审核
function tongguo(){
	include(&#039;simple_html_dom.php&#039;);//这个引文可以在下面下载!
   	$time = $_REQUEST[&#039;where&#039;];
 	$time = explode(&quot;,&quot;,$time);
 	$result = M(&#039;textpage&#039;);
 	$where[&#039;_string&#039;] = &quot; time &gt;=&#039;{$time[0]}&#039; and time &lt;=&#039;{$time[1]}&#039;&quot;;
	$where[&#039;status&#039;] = 2;
	
	 $renwu = M(&#039;textpage&#039;);
	$list = $result-&gt;where($where)-&gt;limit(10)-&gt;select();
 	if(!$list){
		$this-&gt;assign(&#039;jump&#039;,&#039;0&#039;);
 	}else{
 		$this-&gt;assign(&#039;jump&#039;,&#039;1&#039;);
	} ///$wangzhan=array(&#039;liebiao.com&#039;,&#039;58.com&#039;,&#039;ohqly.com&#039;,&#039;ganji.com&#039;,&#039;lieju.com&#039;,
&#039;favolist.com&#039;,&#039;go007.com&#039;,&#039;gd8.com&#039;,&#039;fenlei168.com&#039;,&#039;kvov.com&#039;,&#039;ffjzw.com&#039;);
	foreach($list as $v){
		//$html=file_get_contents();
		$ch = curl_init();
		$timeout = 10; 
		curl_setopt ($ch, CURLOPT_URL, $v[&#039;url&#039;]);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt($curl, CURLOPT_BINARYTRANSFER, true) ;
		curl_setopt($curl, CURLOPT_ENCODING, &#039;gzip,deflate&#039;);
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$html = curl_exec($ch);
		curl_close($ch);
		if($this-&gt;safeEncoding($html)==false){
			$html=$this-&gt;gzdecode($html);
			$html=$this-&gt;safeEncoding($html);
		}else{
			$html=$this-&gt;safeEncoding($html);
		}
		//dump($html);die;
		if(!$html){
			if($html==&#039;&#039;){
				$data[&#039;reason&#039;]= &quot;超时&quot;;
			}else{
				$data[&#039;reason&#039;]= &quot;文章不存在!&quot;;
			}
			$data[&#039;status&#039;] = 3;
			
			$con[&#039;id&#039;] = $v[&#039;id&#039;];
			$result = $renwu-&gt;where($con)-&gt;save($data);
			if($result){
			     echo $v[&#039;id&#039;] .$v[&#039;textname&#039;] .$v[&#039;url&#039;] .&quot;【文章不存在--未通过】&lt;br /&gt;&quot;;
			}
		}else{
			 if(stripos($v[&#039;url&#039;],&#039;liebiao.com&#039;)!==false){
			//$html=$this-&gt;gzdecode($html);
			}
			$html = str_get_html($html);
 			if(is_object($html)===false){
				$data[&#039;status&#039;] = 3;
				$data[&#039;reason&#039;]= &quot;链接不存在!&quot;;
				 $con[&#039;id&#039;] = $v[&#039;id&#039;];
				$result = $renwu-&gt;where($con)-&gt;save($data);
				if($result){
				   echo $v[&#039;id&#039;] .$v[&#039;textname&#039;] .$v[&#039;url&#039;] .&quot;【链接不存在--未通过】&lt;br /&gt;&quot;;
				}
			}else{
				$tf=false;
				if(stripos($v[&#039;url&#039;],&#039;lieju.com&#039;)!==false){
					$tit=$html-&gt;find(&#039;span&#039;);
					foreach($tit as $e) {
						$val= $e-&gt;innertext;
						if(stripos($val,$v[&#039;textname&#039;])!==false){
							$tf=true;
							break;
						}
					}

				}else if(stripos($v[&#039;url&#039;],&#039;baixing.com&#039;)!==false){
					foreach($html-&gt;find(&#039;h2&#039;) as $e) {
						$val=str_replace(&#039;&amp;nbsp&#039;,&#039;&#039;,strip_tags($e-&gt;innertext));
						//$val=trim(strip_tags($e-&gt;innertext));
						//$dump($val);die;
						if(stripos($val,$v[&#039;textname&#039;])!==false){
							$tf=true;
							break;
						}
					}
				}else{
					foreach($html-&gt;find(&#039;h1&#039;) as $e) {
						//$val=str_replace(&#039; &#039;,&#039;&#039;,strip_tags($e-&gt;innertext));
					        //$val= $e-&gt;innertext;
						$val=trim(strip_tags($e-&gt;innertext));/////去空格以及去掉html标签
						//$dump($val);die;
						if(stripos($val,$v[&#039;textname&#039;])!==false){
							$tf=true;
							break;
						}
					}
				}
				if($tf){
					$data[&#039;status&#039;] = 4;
					$data[&#039;reason&#039;]= &quot;&quot;;
					$con[&#039;id&#039;] = $v[&#039;id&#039;];
					$result = $renwu-&gt;where($con)-&gt;save($data);
					if($result){
						echo $v[&#039;id&#039;] .$v[&#039;textname&#039;] .$v[&#039;url&#039;] .&quot;【通过】&lt;br /&gt;&quot;;
					}
				}else{
					
					$data[&#039;status&#039;] = 3;
					$data[&#039;reason&#039;]= &quot;标题错误!&quot;;
					$con[&#039;id&#039;] = $v[&#039;id&#039;];
					$result = $renwu-&gt;where($con)-&gt;save($data);
					if($result){
						echo $v[&#039;id&#039;] .$v[&#039;textname&#039;] .$v[&#039;url&#039;] .&quot;【标题错误--未通过】&lt;br /&gt;&quot;;
					}
				}
			}
		}
}
	$this-&gt;display(&#039;tongguo&#039;);

}
//gzip压缩编码的解决方法
 function gzdecode($data) {
             $len = strlen($data);
             if ($len &lt; 18 || strcmp(substr($data,0,2),&quot;\x1f\x8b&quot;)) {
             return null;  // Not GZIP format (See RFC 1952)
           }
            $method = ord(substr($data,2,1));  // Compression method
            $flags  = ord(substr($data,3,1));  // Flags
            if ($flags &amp; 31 != $flags) {
            // Reserved bits are set -- NOT ALLOWED by RFC 1952
             return null;
          }
            // NOTE: $mtime may be negative (PHP integer limitations)
            $mtime = unpack(&quot;V&quot;, substr($data,4,4));
            $mtime = $mtime[1];
            $xfl   = substr($data,8,1);
            $os    = substr($data,8,1);
            $headerlen = 10;
            $extralen  = 0;
            $extra     = &quot;&quot;;
            if ($flags &amp; 4) {
           // 2-byte length prefixed EXTRA data in header
           if ($len - $headerlen - 2 &lt; 8) {
           return false;    // Invalid format
          }
           $extralen = unpack(&quot;v&quot;,substr($data,8,2));
           $extralen = $extralen[1];
           if ($len - $headerlen - 2 - $extralen &lt; 8) {
           return false;    // Invalid format
          }
           $extra = substr($data,10,$extralen);
           $headerlen += 2 + $extralen;
  }

          $filenamelen = 0;
          $filename = &quot;&quot;;
          if ($flags &amp; 8) {
          // C-style string file NAME data in header
          if ($len - $headerlen - 1 &lt; 8) {
          return false;    // Invalid format
        }
           $filenamelen = strpos(substr($data,8+$extralen),chr(0));
           if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 &lt; 8) {
           return false;    // Invalid format
    }
           $filename = substr($data,$headerlen,$filenamelen);
           $headerlen += $filenamelen + 1;
  }

           $commentlen = 0;
           $comment = &quot;&quot;;
          if ($flags &amp; 16) {
          // C-style string COMMENT data in header
          if ($len - $headerlen - 1 &lt; 8) {
           return false;    // Invalid format
     }
           $commentlen = strpos(substr($data,8+$extralen+$filenamelen),chr(0));
           if ($commentlen === false || $len - $headerlen - $commentlen - 1 &lt; 8) {
           return false;    // Invalid header format
    }
          $comment = substr($data,$headerlen,$commentlen);
          $headerlen += $commentlen + 1;
  }

          $headercrc = &quot;&quot;;
          if ($flags &amp; 1) {
          // 2-bytes (lowest order) of CRC32 on header present
          if ($len - $headerlen - 2 &lt; 8) {
          return false;    // Invalid format
    }
          $calccrc = crc32(substr($data,0,$headerlen)) &amp; 0xffff;
          $headercrc = unpack(&quot;v&quot;, substr($data,$headerlen,2));
          $headercrc = $headercrc[1];
          if ($headercrc != $calccrc) {
          return false;    // Bad header CRC
    }
         $headerlen += 2;
  }

        // GZIP FOOTER - These be negative due to PHP&#039;s limitations
        $datacrc = unpack(&quot;V&quot;,substr($data,-8,4));
        $datacrc = $datacrc[1];
        $isize = unpack(&quot;V&quot;,substr($data,-4));
        $isize = $isize[1];

       // Perform the decompression:
       $bodylen = $len-$headerlen-8;
       if ($bodylen &lt; 1) {
      // This should never happen - IMPLEMENTATION BUG!
      return null;
   }
      $body = substr($data,$headerlen,$bodylen);
      $data = &quot;&quot;;
      if ($bodylen &gt; 0) {
      switch ($method) {
      case 8:
        // Currently the only supported compression method:
        $data = gzinflate($body);
        break;
      default:
        // Unknown compression method
        return false;
    }
  } else {
        // I&#039;m not sure if zero-byte body content is allowed.
        // Allow it for now...  Do nothing...
  }

       // Verifiy decompressed size and CRC32:
      // NOTE: This may fail with large data sizes depending on how
     //  PHP&#039;s integer limitations affect strlen() since $isize
    //  may be negative for large sizes.
        if ($isize != strlen($data) || crc32($data) != $datacrc) {
       // Bad format!  Length or CRC doesn&#039;t match!
        return false;
  }
        return $data;
	}
}//end
?&gt;
</pre>
<p>然后创建模板shenhe.html</p>
<pre class="wp-code-highlight prettyprint">
&lt;html&gt;
          &lt;if condition=&quot; $on neq NULL &quot; &gt;&lt;a href=&quot;{:U(&#039;/Textpage/tongguo&#039;,
           array(&#039;where&#039;=&gt;$time))}&quot;&gt;&lt;h4&gt;自动审核&lt;/h4&gt;&lt;/a&gt;&lt;/if&gt;
&lt;/html&gt;
</pre>
<p>最后创建模板tongguo.html</p>
<pre class="wp-code-highlight prettyprint">
&lt;html&gt;
         &lt;script type=&quot;text/javascript&quot;&gt;
         var jump=&quot;{$jump}&quot;;
         window.onload = function(){
	 if(jump==&#039;1&#039;){
		setTimeout(function(){
		location.reload();
                },60000);//60秒自动刷新页面
	}else{
		
		alert(&#039;审核完毕&#039;);
		//location.href=&quot;{U:(Textpage/submit)}&quot;;
	}
	
};
        &lt;/script&gt;
&lt;/html&gt;
</pre>
<p><a href="http://pan.baidu.com/s/1c0EHipU" target="&quot;_blank"><img class="alignnone size-full wp-image-1075" title="btn_load" src="http://www.yunda51.com/wp-content/uploads/2013/11/btn_load3.png" alt="" width="86" height="28" /></a><br />
转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1190.html">http://www.yunda51.com/1190.html</a>   </p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1190</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
