|
<?php |
|
class chelaile |
|
{ |
|
// 城市信息接口 |
|
private $citylist_url = 'https://web.chelaile.net.cn/cdatasource/citylist'; |
|
// 附近站点线路及信息 |
|
private $homePageInfo = 'https://api.chelaile.net.cn/bus/stop!homePageInfo.action'; |
|
//实时接口 |
|
private $lineDetail = 'http://api.chelaile.net.cn/bus/line!lineDetail.action'; |
|
//公交车细节 |
|
private $busesDetail = 'http://api.chelaile.net.cn/bus/line!busesDetail.action'; |
|
//公交车时刻表 |
|
private $getBusTime = 'http://api.chelaile.net.cn/bus/line!depTimeTable.action'; |
|
|
|
public $lat = ''; //维度 |
|
public $lng = ''; //经度 |
|
private $gpstype = 'wgs'; |
|
private $s = 'android'; //(必须,否则非法授权访问) |
|
private $v = '3.80.0'; //(必须,否则非法授权访问) |
|
private $src = 'webapp_default'; |
|
private $userId = ''; |
|
|
|
public $sign = 'PPgBLFF5779koWJpY09iQg%3D%3D'; //签名(无签名非法授权访问) |
|
|
|
public $lineId = ''; //(0574-628路-0) |
|
|
|
public $cityId = ''; //城市ID |
|
|
|
private $apiUrl2 = 'https://api.chelaile.net.cn/bus/stop!homePageInfo.action?type=1&act=2&gpstype=wgs&gpsAccuracy=65.000000&cityId=城市ID(从前面一个接口获取)&hist=&s=IOS&sign=&dpi=3&push_open=1&v=5.50.4&lat=纬度&lng=经度'; |
|
private $geo_type = ''; //(必备gcj) |
|
|
|
/** |
|
* 获取城市信息 |
|
* @Author Youngxj |
|
* @DateTime 2019-07-11 |
|
* @return [type] [description] |
|
*/ |
|
public function getCity() |
|
{ |
|
$url = $this->citylist_url . '?type=gpsRealtimeCity&lat=' . $this->lat . '&lng=' . $this->lng . '&gpstype=' . $this->gpstype . '&s=' . $this->s . '&v=' . $this->v . '&src=' . $this->src . '&userId=' . $this->userId; |
|
$data = $this->curl_request($url); |
|
if ($json_data = json_decode($data, 1)) { |
|
if ($json_data && isset($json_data['status']) && $json_data['status'] == 'OK') { |
|
return $json_data['data']['gpsRealtimeCity']; |
|
} else { |
|
return false; |
|
} |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
/** |
|
* 获取附近站点的线路及信息 |
|
* @Author Youngxj |
|
* @DateTime 2019-07-11 |
|
* @return [type] [description] |
|
*/ |
|
public function getArr() |
|
{ |
|
$url = $this->homePageInfo . '?type=1&act=2&gpstype=' . $this->gpstype . '&gpsAccuracy=65.000000&cityId=' . $this->cityId . '&hist=&s=' . $this->s . '&sign=&dpi=3&push_open=1&v=5.50.4&lat=' . $this->lat . '&lng=' . $this->lng; |
|
$data_json = $this->curl_request($url); |
|
|
|
$data = str_replace(array("YGKJ##", '**YGKJ'), "", $data_json); |
|
|
|
if ($json_data = json_decode($data, 1)) { |
|
if ($json_data && isset($json_data['jsonr']['status']) && $json_data['jsonr']['status'] == '00') { |
|
return $json_data['jsonr']['data']; |
|
} else { |
|
return false; |
|
} |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
/** |
|
* 获取公交车实时信息 |
|
* @Author Youngxj |
|
* @DateTime 2019-07-11 |
|
* @param [type] $lineId 线路lineId |
|
* @param [type] $geo_lng 公交站点lng |
|
* @param [type] $geo_lat 公交站点lat |
|
* @return [type] [description] |
|
*/ |
|
public function getBusInfo() |
|
{ |
|
$url = $this->lineDetail . '?sign=' . $this->sign . '&cityId=' . $this->cityId . '&geo_type=gcj&lineId=' . $this->lineId . '&isNewLineDetail=1&s=' . $this->s . '&last_src=app_xiaomi_store&geo_lng=' . $this->lng . '&geo_lat=' . $this->lat . '&v=' . $this->v; |
|
|
|
$data_json = $this->curl_request($url); |
|
|
|
$data = str_replace(array("YGKJ##", '**YGKJ'), "", $data_json); |
|
|
|
if ($json_data = json_decode($data, 1)) { |
|
if ($json_data && isset($json_data['jsonr']['status']) && $json_data['jsonr']['status'] == '00') { |
|
return $json_data['jsonr']['data']; |
|
} else { |
|
return false; |
|
} |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
/** |
|
* 获取公交车细节 |
|
* @Author Youngxj |
|
* @DateTime 2019-07-11 |
|
* @param [type] $targetOrder 所在公交站点ID |
|
* @return [type] [description] |
|
*/ |
|
public function getBusesDetail($targetOrder) |
|
{ |
|
$url = $this->busesDetail . '?sign=' . $this->sign . '&cityId=' . $this->cityId . '&lat=' . $this->lat . '&geo_type=gcj&gpstype=gcj&geo_lt=5&screenDensity=3.0&flpolicy=1&stats_referer=searchHistory&targetOrder=' . $targetOrder . '&lineId=' . $this->lineId . '&s=' . $this->s . '&geo_lng=' . $this->lng . '&geo_lat=' . $this->lat . '&v=' . $this->v; |
|
|
|
$data_json = $this->curl_request($url); |
|
$data = str_replace(array("YGKJ##", '**YGKJ'), "", $data_json); |
|
|
|
if ($json_data = json_decode($data, 1)) { |
|
if ($json_data && isset($json_data['jsonr']['status']) && $json_data['jsonr']['status'] == '00') { |
|
return $json_data['jsonr']['data']; |
|
} else { |
|
return false; |
|
} |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
/** |
|
* 获取公交时刻表 |
|
* @Author Youngxj |
|
* @DateTime 2019-07-11 |
|
* @param [type] $sId 所在公交站的sid |
|
* @return [type] [description] |
|
*/ |
|
public function getBusTime($sId = '0574-6437') |
|
{ |
|
$url = $this->getBusTime . '?sign=' . $this->sign . '&cityId=&stationId=' . $sId . '&geo_type=gcj&lineId=' . $this->lineId . '&s=android&geo_lng=' . $this->lng . '&geo_lat=' . $this->lat . '&v=' . $this->v; |
|
|
|
$data_json = $this->curl_request($url); |
|
|
|
$data = str_replace(array("YGKJ##", '**YGKJ'), "", $data_json); |
|
|
|
if ($json_data = json_decode($data, 1)) { |
|
if ($json_data && isset($json_data['jsonr']['status']) && $json_data['jsonr']['status'] == '00') { |
|
return $json_data['jsonr']['data']; |
|
} else { |
|
return false; |
|
} |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
/** |
|
* curl模拟提交 |
|
* @param [type] $url 访问的URL |
|
* @param string $post post数据(不填则为GET) |
|
* @param string $referer 自定义来路 |
|
* @param string $cookie 提交的$cookies |
|
* @param integer $returnCookie 是否返回$cookies |
|
* @param string $ua 自定义UA |
|
* @return [type] [description] |
|
*/public function curl_request($url, $post = '', $referer = '', $cookie = '', $returnCookie = 0, $ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0') |
|
{ |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, $url); |
|
curl_setopt($curl, CURLOPT_USERAGENT, $ua); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); |
|
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
curl_setopt($curl, CURLOPT_REFERER, $referer); |
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
$httpheader[] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; |
|
$httpheader[] = "Accept-Encoding:gzip, deflate"; |
|
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.9"; |
|
$httpheader[] = "Connection:close"; |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheader); |
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
|
if ($post) { |
|
curl_setopt($curl, CURLOPT_POST, 1); |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); |
|
} |
|
if ($cookie) { |
|
curl_setopt($curl, CURLOPT_COOKIE, $cookie); |
|
} |
|
curl_setopt($curl, CURLOPT_HEADER, $returnCookie); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 10); |
|
curl_setopt($curl, CURLOPT_ENCODING, "gzip"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
$data = curl_exec($curl); |
|
if (curl_errno($curl)) { |
|
return curl_error($curl); |
|
} |
|
curl_close($curl); |
|
if ($returnCookie) { |
|
list($header, $body) = explode("\r\n\r\n", $data, 2); |
|
preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches); |
|
$info['cookie'] = substr($matches[1][1], 1); |
|
$info['content'] = $body; |
|
return $info; |
|
} else { |
|
return $data; |
|
} |
|
} |
|
|
|
#获取百度经纬度(ak=百度ak码) |
|
public function addressbaidu($address) //$address:地址 |
|
|
|
{ |
|
$url = 'http://api.map.baidu.com/geocoder/v2/?address=' . $address . '&output=json&ak=Bsr5iefxHEwQD8iCFTx3GwWOem0ZoSBk'; |
|
if ($result = file_get_contents($url)) { |
|
$arr = explode(',"lat":', substr($result, 40, 36)); |
|
return $arr; |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
#获取高德经纬度(key=高德key值) |
|
public function addresstolatlag($address) |
|
{ |
|
//$address:地址 |
|
$url = 'http://restapi.amap.com/v3/geocode/geo?key=a5767d2101d83dffcb6cc0325eaccfb4&s=rsv3&city=35&address=' . $address; |
|
if ($result = file_get_contents($url)) { |
|
$result = json_decode($result, true); |
|
//判断是否成功 |
|
if (!empty($result['count'])) { |
|
return explode(',', $result['geocodes']['0']['location']); |
|
|
|
} else { |
|
return false; |
|
} |
|
|
|
} |
|
} |
|
|
|
/** |
|
* 方糖通知 |
|
* @Author Youngxj |
|
* @DateTime 2019-07-12 |
|
* @param [type] $text 标题 |
|
* @param string $desp 内容 |
|
* @param string $key [description] |
|
* @return [type] [description] |
|
*/ |
|
public function sc_send($text, $desp = '', $key = '') |
|
{ |
|
$postdata = http_build_query( |
|
array( |
|
'text' => $text, |
|
'desp' => $desp, |
|
) |
|
); |
|
|
|
$opts = array('http' => array( |
|
'method' => 'POST', |
|
'header' => 'Content-type: application/x-www-form-urlencoded', |
|
'content' => $postdata, |
|
), |
|
); |
|
$context = stream_context_create($opts); |
|
return $result = file_get_contents('https://sc.ftqq.com/' . $key . '.send', false, $context); |
|
|
|
} |