获取所有用户信息_获取用户大致信息

2021-7-16发布 3233 0 0

游动网络

保密 | 这个家伙很懒,什么都没有留下

获取所有用户信息_获取用户大致信息

//----------------------------------


// 小明API 获取用户大致信息 调用类


//----------------------------------


class freeApi{

private $apiUrl = 'http://api.guaqb.cn/v1/details/';


/**


* url拼接


* @return string


*/


private function handleUrl($params){

$o = "";


foreach ( $params as $k => $v )


{

$o.= "$k=" . urlencode( $v ). "&" ;


}


$params = substr($o,0,-1);


return $params;


}


/**


* 获取结果


* @return array


*/


public function getResult(){

$params['json'] = 'yes';


$params['key'] = 'yourkey';


$params['secret'] = 'yoursecret';


echo $this->apiUrl.'?'.$this->handleUrl($params);


return $this->freeApiCurl($this->apiUrl.'?'.$this->handleUrl($params));


}


/**


* 请求接口返回内容


* @param string $url [请求的URL地址]


* @param string $params [请求的参数]


* @param int $ipost [是否采用POST形式]


* @return string


*/


public function freeApiCurl($url,$params=false,$ispost=0){

$ch = curl_init();


curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );


curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );


curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' );


curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );


curl_setopt( $ch, CURLOPT_TIMEOUT , 60);


curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );


if( $ispost )


{

curl_setopt( $ch , CURLOPT_POST , true );


curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );


curl_setopt( $ch , CURLOPT_URL , $url );


}


else


{

if($params){

curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );


}else{

curl_setopt( $ch , CURLOPT_URL , $url);


}


}


$response = curl_exec( $ch );


if ($response === FALSE) {

return false;


}


curl_close( $ch );


return $response;


}


}


$api = new freeApi();


var_dump($api->getResult());