php c-url v-eto

**
 * Created by PhpStorm.
 * User: hxg
 * Date: 2016/5/4
 * Time: 10:47
 */
class TestAction extends CommonAction
{

	public function toupiao(){
		set_time_limit(10);
		//$agent=$_SERVER['HTTP_USER_AGENT'];
		$agent='Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3';
		$url='http://tp.zztc.com/index.php?g=Wap&m=Vote&a=vote';
		$url=htmlspecialchars_decode($url);
		$data = array (
			'token' => 'vjcbgt1414375209',
			 'id' => '28',
			 'wecha_id' => '',
			 'tid' => '18'
		);
		$options= array(
			CURLOPT_URL => $url,
			CURLOPT_HEADER => false,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_USERAGENT => $agent,
			CURLOPT_FOLLOWLOCATION => true,
			CURLOPT_TIMEOUT=>5,
			CURLOPT_POST=>1,
			CURLOPT_POSTFIELDS=>$data
		);
		$count=200;
		$start=0;
		$okCount=0;
		$yiCount=0;
		$errCount=0;

		$info='====================*****Start****=====================
'; while (true) { $res = $this->getUrlContent($url, $agent, $timeOut = 1, $options); $res=json_decode($res,true); $start++; if($res['status']==2) { $okCount++; }elseif($res['status']==4){ $yiCount++; }else{ $errCount++; } $info.=date("Y-m-d H:i:s",time()).': '.$res['info'].'
'; if($start==$count)break; $ran=rand(3,10); sleep($ran); } $info.='====================*****End****=====================
'; echo '成功:'.$okCount.'
'; echo '重复:'.$yiCount.'
'; echo '失败:'.$errCount.'
'; echo '*总投*:'.$start.'
'; echo '

'.$info; //$url2='http://tp.zztc.com/index.php?g=Wap&m=Vote&a=show&token=vjcbgt1414375209&id=28&wecha_id=&tid=18&from=timeline&isappinstalled=0'; //$surveyCount=$this->getSurveyCount($url2,$agent,$timeOut=5); } public function ajaxtoupiao(){ set_time_limit(10); //$agent=$_SERVER['HTTP_USER_AGENT']; $agent='Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'; $url='http://tp.zztc.com/index.php?g=Wap&m=Vote&a=vote'; $url=htmlspecialchars_decode($url); $data = array ( 'token' => '', 'id' => '', 'wecha_id' => '', 'tid' => '' ); $options= array( CURLOPT_URL => $url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $agent, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT=>5, CURLOPT_POST=>1, CURLOPT_POSTFIELDS=>$data ); $res = $this->getUrlContent($url, $agent, $timeOut = 1, $options); $res=json_decode($res,true); $res['info']=date('Y-m-d H:i:s',time()).'---'.$res['info']; $this->ajaxReturn($res,'jsonp'); } /** * 模拟获取网页内容 * @param $url 目标网址 * @param $agent 客户端信息 */ private function getUrlContent($url,$agent,$timeOut=5,$op){ $ch= curl_init(); $options= array( CURLOPT_URL => $url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $agent, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT=>$timeOut//cs ); $options=empty($op)?$options:$op; curl_setopt_array($ch, $options); $output= curl_exec($ch); curl_close($ch); return $output; } private function getSurveyCount($url,$agent,$timeOut=5){ //$html=$this->getUrlContent($url,$agent,20); $html='
阿进
选手姓名
28
该选手编号
658
当前票-数
4
当前排名
'; //preg_match_all("/]*)\s*src=('|\")([^'\"]+)('|\")/i",$html,$match);//带引号 preg_match_all("/\s*(
.*<\/dt>
.*<\/dd><\/dl>)*\s*<\/div>/",$html,$match);//带引号 //preg_match_all("/
[0-9]*<\/dt>/",$html,$match);//带引号 return $match[3]; }







投票


Click Me!
成功:
重复:
失败:
请求次数:
总共:


你可能感兴趣的:(PHP)