Home > WeChat Applet > WeChat Development > WeChat public platform development--bus transfer

WeChat public platform development--bus transfer

黄舟
Release: 2016-12-30 10:32:00
Original
1943 people have browsed it

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 http://www.aibang.com

The number of queries is limited, 2013-12-4, up to 1000 times/10 times per day/minute

Return json data

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 .= &#39;--&#39; ;
			$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],&#39;;&#39;); 
			$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,&#39;(&#39;));
}

$a=bustransfer("南昌","老福山","青山路口");
var_dump($a);
Copy after login

3) Effect display

WeChat public platform development--bus transfer

4) Accurate query

In bus query, the required input is the bus/subway station name

If you don’t know the exact bus station name, you often won’t get the result.

On the web page, the system can prompt you to select the accurate bus stop,

WeChat public platform development--bus transfer

However, it is inconvenient to do this on WeChat

The improvement plan is as follows:

Aibang has a bus station query API

Find user input information through this API Nearby stations and take out the first bus transfer station

In this way, the probability of successful bus transfer search is increased.

The above is the content of WeChat public platform development-bus transfer. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template