1) API application
2) API call
3) [b] Effect display [/b]
4) Accurate query
------------ -------------------------------------------------- ------------
1) API application
Aibang provides query interface API, you need to apply for Key www.aibang.com
The number of queries is limited , 2013-12-4 Up to 1000 times/10 times/minute per day
Returnjsondata
Provide data description
Provide demo file
2) API call
After calling the API to obtain the data, you can output it in your own format
/* aibang's api return josn data d_eng (sh109419@163.com) 2013-12-4 */ define("APP_KEY", "xx00ac396d6d75e8681fc8380060c5b2"); include_once "ABClient.php"; //header("Content-Type:text/html; charset=utf-8"); function bustransfer($city,$start,$end) { $client = new ABClient(APP_KEY); list($code, $arr) = $client->getBusTransfer($city, array("start_addr" =>$start, "end_addr"=>$end)); if ($code<>200){ return false; } $ret =""; $buses = $arr[buses][bus]; // show the top 3 records $ret = $start ."-->".$end."\n"; $count = 1; foreach ($buses as $bus) { if ($count > 3) break; $segments =$bus[segments][segment]; $ret .= "<方案".$count++.">\n"; // get line name and remove remark $linename = ""; foreach($segments as $segment) { if (!empty($linename)) $linename .= '--' ; $linename .= shortlinename($segment[line_name]); } $ret .= $linename . "\n" ; $total = sprintf("%d分钟 %d米 步行%d米",$bus[time],$bus[dist],$bus[foot_dist]); $ret .= $total . "\n" ; // detail $from = sprintf("从 %s ",$start); $ret .= $from; foreach($segments as $segment) { if ($segment[foot_dist] > 0) { $segfoot = sprintf("步行%d米 到达 %s",$segment[foot_dist],$segment[start_stat]); $ret .= $segfoot . "\n" ; } $stats = substr_count($segment[stats],';'); $line = sprintf("乘坐 %s(%d站) 到达 %s",shortlinename($segment[line_name]),$stats,$segment[end_stat]); $ret .= $line . "\n" ; } if ($bus[last_foot_dist] > 0) { $lastfoot = sprintf("步行%d米 到达 %s",$bus[last_foot_dist],$end); $ret .= $lastfoot; } } return $ret; } function shortlinename($linename){ return substr($linename,0,strpos($linename,'(')); } $a=bustransfer("南昌","老福山","青山路口"); var_dump($a);
3) Effect display
4) Accurate query
In bus query, you are required to enter the bus/subway station name
If you don’t know the accurate station name, you often cannot get the result,
On the web page, the system can prompt you to select the correct bus stop,
However, it is inconvenient to do this on WeChat
The improvement plan is as follows:
Aibang has a bus station query API
Use this API to find the stations near the user's input information and take out the first one as a bus transfer station
In this way, the probability of successful bus transfer search increases.
【Related Recommendations】
1. Special Recommendation: "php Programmer Toolbox" V0.1 version download
2. WeChat public account platform source code download
3. WeChat voting source code free download
The above is the detailed content of Detailed explanation of bus transfer function code developed by WeChat. For more information, please follow other related articles on the PHP Chinese website!