2020-03-11 14:23:25 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace taoler\com;
|
|
|
|
|
|
|
|
|
|
class Api
|
|
|
|
|
{
|
2020-03-18 21:30:30 +08:00
|
|
|
|
public static function urlPost($url, $data)
|
2020-03-11 14:23:25 +08:00
|
|
|
|
{
|
|
|
|
|
if($url == ''){
|
|
|
|
|
return json(['code'=>-1,'msg'=>'800']);
|
|
|
|
|
}
|
|
|
|
|
$ch =curl_init ();
|
|
|
|
|
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
|
|
|
|
|
curl_setopt($ch,CURLOPT_POST, 1);
|
2020-03-18 21:30:30 +08:00
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
2020-03-11 14:23:25 +08:00
|
|
|
|
$data = curl_exec($ch);
|
|
|
|
|
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
if($httpCode == '200'){
|
|
|
|
|
return json_decode($data);
|
|
|
|
|
} else {
|
|
|
|
|
return json(['code'=>-1,'msg'=>'Զ<>̷<EFBFBD><CCB7><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-18 21:30:30 +08:00
|
|
|
|
|
|
|
|
|
public static function urlGet($url)
|
|
|
|
|
{
|
|
|
|
|
$ch =curl_init ();
|
|
|
|
|
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
//curl_setopt($ch, CURLOPT_HEADER, 0); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD>Ὣͷ<E1BDAB>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ϊ1<CEAA><31>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣͷ,Ϊ0<CEAA><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1) ; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CURLOPT_RETURNTRANSFER ʱ<><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>
|
|
|
|
|
$data = curl_exec($ch);
|
|
|
|
|
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
if($httpCode == '200'){
|
|
|
|
|
return json_decode($data);
|
|
|
|
|
} else {
|
|
|
|
|
return json(['code'=>-1,'msg'=>'Զ<>̷<EFBFBD><CCB7><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function get_real_ip()
|
|
|
|
|
{
|
|
|
|
|
static $realip;
|
|
|
|
|
if (isset($_SERVER)) {
|
|
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
|
|
|
|
$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
|
} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {
|
|
|
|
|
$realip = $_SERVER['HTTP_CLIENT_IP'];
|
|
|
|
|
} else {
|
|
|
|
|
$realip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (getenv('HTTP_X_FORWARDED_FOR')) {
|
|
|
|
|
$realip = getenv('HTTP_X_FORWARDED_FOR');
|
|
|
|
|
} else if (getenv('HTTP_CLIENT_IP')) {
|
|
|
|
|
$realip = getenv('HTTP_CLIENT_IP');
|
|
|
|
|
} else {
|
|
|
|
|
$realip = getenv('REMOTE_ADDR');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $realip;
|
|
|
|
|
}
|
2020-03-11 14:23:25 +08:00
|
|
|
|
}
|