-
-
Save EugeneLiang/07aef87bd4b1f51b038765bcc7b73c57 to your computer and use it in GitHub Desktop.
ofo订单
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ofo { | |
public function __construct($carno, $coord_url, $token){ | |
list($this->lat, $this->lng) = $this->get_coord($coord_url); | |
$this->carno = $carno; | |
$this->token = $token; | |
} | |
//把高德url转换为坐标 | |
private function get_coord($coord_url){ | |
$headers = get_headers($coord_url, 1); | |
$redirect_url = parse_url($headers['Location'][1]); | |
preg_match('/\d{2,3}.\d{6,},\d{2,3}.\d{6,}/', $redirect_url['query'], $coord); | |
if( empty($coord) ) exit('coord error'); | |
return explode(',', $coord[0]); | |
} | |
private function curl_post($url, $data = array(), $header = array(), $timeout = 3, $port = 80) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | |
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); | |
!empty ($header) && curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
$data = array(); | |
$result = array(); | |
$result['result'] = curl_exec($ch); | |
if (0 != curl_errno($ch)) { | |
$result['error'] = "Error:\n" . curl_error($ch); | |
$curl_info_str = ''; | |
$data['no'] = curl_errno($ch); | |
$data['error'] = curl_error($ch); | |
$curl_info = curl_getinfo($ch); | |
if($curl_info){ | |
foreach ($curl_info as $key => $v){ | |
$data[$key] = $v; | |
$curl_info_str .= $key . ':' . $v . '<br />'; | |
} | |
$data['message'] = 'ERROR NO:' . curl_errno($ch) . ', ERROR:' . curl_error($ch) . ',CURL_INFO:' . $curl_info_str; | |
} | |
}else{ | |
$data['no'] = 200; | |
$data['error'] = 'success'; | |
$data['url'] = $url; | |
} | |
curl_close($ch); | |
return $result; | |
} | |
public function start(){ | |
$url = 'https://san.ofo.so/ofo/Api/v2/carno'; | |
$headers = array( | |
'content-type: application/x-www-form-urlencoded', | |
); | |
$data = array( | |
'accuracy' => '100.00000', | |
'altitude' => '40.11111', | |
'carno' => $this->carno, | |
'lat' => $this->lat, | |
'lng' => $this->lng, | |
'source' => '2', | |
'source-version' => '12412', | |
'speed' => '-1.000000', | |
'tag' => '', | |
'token' => $this->token, | |
'source-system' => '7.1.1', | |
'source-model' => 'xiaomi_6plus', | |
); | |
$res = $this->curl_post($url, http_build_query($data), $headers); | |
echo "<pre>"; print_r($res);exit; | |
} | |
public function stop($orderno){ | |
$url = "https://san.ofo.so/ofo/Api/v2/end"; | |
$headers = array( | |
'content-type: application/x-www-form-urlencoded', | |
); | |
$data = array( | |
'source' => '0', | |
'lat' => $this->lat, | |
'lng' => $this->lng, | |
'token' => $this->token, | |
'ordernum' => $orderno, | |
); | |
$res = $this->curl_post($url, http_build_query($data), $headers); | |
//自动支付 | |
//$this->_pay($orderno); | |
echo "<pre>"; print_r($res);exit; | |
} | |
private function _pay($orderno){ | |
$url = "https://san.ofo.so/ofo/Api/v2/pay"; | |
$headers = array( | |
'content-type: application/x-www-form-urlencoded', | |
); | |
$data = array( | |
'token' => $this->token, | |
'ordernum' => $orderno, | |
'source' => '0', | |
'packetid' => '0', | |
); | |
$res = $this->curl_post($url, http_build_query($data), $headers); | |
echo "<pre>"; print_r($res);exit; | |
} | |
} | |
//车牌号 | |
$carno = "2752213"; | |
//高德坐标url | |
$gaode_url = "http://f.amap.com/iSe7_0862JBU"; | |
//ofo token | |
$token = "ccc23720-fb23-12e6-8bbf-69923e2e8e00"; | |
$ofo = new ofo($carno, $gaode_url, $token); | |
//$ofo->stop('87822122'); | |
$ofo->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment