| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 | <?php	/*	 * curl 调用	 */	//echo post_request("http://www.baidu.com");	function post_request($url, $params=array()) {				$ch = curl_init();		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);		//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));		curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/html"));		curl_setopt($ch, CURLOPT_URL, $url);		curl_setopt($ch, CURLOPT_POST, true);		curl_setopt($ch, CURLOPT_TIMEOUT, 3);		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));  		$result = curl_exec($ch);	    $httpinfo= curl_getinfo($ch);		curl_close($ch);		//print_r($httpinfo);		$info = "{$httpinfo['http_code']}|$url|$result";		Log::save_run_log($info,'curl');		if($httpinfo['http_code'] == 200){			return $result;		} else {			return false;		}	}			function xml_unserialize(&$xml, $isnormal = FALSE) {		$xml_parser = new XML($isnormal);		$data = $xml_parser->parse($xml);		$xml_parser->destruct();		return $data;	}		/**	*	获得请求端的xml	*/		function post_request_xml($url, $params=array()) {				$ch = curl_init();		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);		//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));		curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/html"));		curl_setopt($ch, CURLOPT_URL, $url);		curl_setopt($ch, CURLOPT_POST, true);		curl_setopt($ch, CURLOPT_TIMEOUT, 3);		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));		  		$result = file_get_contents('php://input');			    $httpinfo= curl_getinfo($ch);		curl_close($ch);		//print_r($httpinfo);		$info = "{$httpinfo['http_code']}|$url|$result";		Log::save_run_log($info,'curl');		if($httpinfo['http_code'] == 200){			return $result;		} else {			return false;		}	}	/**	*	获得请求端的ip地址	*/	function  get_client_ip() {		global  $_SERVER;		if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {			$ip  =  $_SERVER["HTTP_X_FORWARDED_FOR"];		} elseif (isset($_SERVER["HTTP_CLIENT_IP"])) {			$ip  =  $_SERVER["HTTP_CLIENT_IP"];		} else {			$ip  =  $_SERVER["REMOTE_ADDR"];		}		return  $ip;	}		/**	*	接口999操作失败	*  forexample: response_999(__FILE__,__LINE__,__FUNCTION__,"SQL");	*/	function response_999($file,$line,$function,$err_type){		$parameters = get_parameters();		$file = strstr($file,"u.");		$log = "|response:999|file:$file|line:$line|function:$function|err_type:$err_type|$parameters";		Log::save_run_log($log,"run");		echo "-999";		exit;	}	/**	*	接口返回结果函数	*/	function response($result){		echo $result;		exit;	}		/**	 * 取得精确时间值	 */	function microtime_float(){   		list($usec, $sec) = explode(" ", microtime());    	return ((float)$usec + (float)$sec);	}			/**	*	取得请求参数,并组成字符串	*	格式为 {parameter:value|parameter:value|parameter:value|parameter:value……………………}	*/	function get_parameters() {		global $_GET,$_POST;		$parameters = "";		if($_GET){			foreach($_GET as $key => $val){				if($key == 'sign') 					continue;				else					$parameters .= "$key:$val|";			}		}		if($_POST){			foreach($_POST as $key => $val){				if($key == 'sign') 					continue;				else					$parameters .= "$key:$val|";			}		}		if(strlen($parameters) > 1 )			$parameters = substr($parameters,0,-1);		return "{".$parameters."}";	}		function get_browser_language()	{		if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){			$accept_lang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);			return $accept_lang[0];		} else {			return false;		}	}			function filterInput(&$info){		if(empty($info)) return false;		if(is_array($info)){			foreach ($info as $key=>$val){				$info[$key] = addslashes($val);			}		} else {			$info = addslashes($info);		}	}		function matchSex($total_friend,$sex,$friends){		$ran = rand(0,$total_friend-1);				if($sex == 2) return $ran;		if ($sex == 1 and $friends[$ran]['sex']=='male'){			return $ran;		} else if ($sex == 0 and $friends[$ran]['sex']=='female'){			return $ran;		} else {			$ran =  matchSex($total_friend,$sex,$friends);		}	}		function get_GetParameters() {		global $_GET;		$parameters = "";		if($_GET){			foreach($_GET as $key => $val){				$parameters .= "$key:$val|";			}		}		if(strlen($parameters) > 1 )			$parameters = substr($parameters,0,-1);		return $parameters;	}	function make_curl($url,$params=array()){	$ch = curl_init();	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);	curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));	curl_setopt($ch, CURLOPT_URL, $url);	curl_setopt($ch, CURLOPT_POST, true);	curl_setopt($ch, CURLOPT_TIMEOUT, 60);	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));	$result = curl_exec($ch);	$result = json_decode($result,true);	return $result;}?>
 |