Home php教程 php手册 PHP火车余票查询的API,12306官方的API

PHP火车余票查询的API,12306官方的API

Jun 21, 2016 am 08:49 AM
quot replace str time

我在做自己微信的时候需要的火车票查询的东西,注册的东西等等太多了,今天就简单的做了下测试看能获取到不,数据怎么样处理速度怎么样,因为是个人做所以就没有去其他网站上找接口,就自己做了下!下边把方法放出来!

 

<?php /**
 *火车票查询方法 简单尝试
 *
 * @copyright			widuu
 * @license			http://www.widuu.com
 * @lastmodify			2013-6-20
 */

function json_array($json){
		if($json){
			foreach ((array)$json as $k=>$v){
				$data[$k] = !is_string($v)? json_array($v):$v;
			}
			return $data;
		}
	}
function doget ($start,$end,$time) // get获取数据使用
	{
		if(empty($time)){
			$time = date('Y-m-d',time());
		}else{
			if(substr($time,0,1)!=0){
				$time = date('Y-0',time()).$time;
				echo substr($time,0,1);
			}else{
				$time = date('Y-',time()).$time;
			}
		}
		$name = include ("../name.php");
		$star = $name[$start];
		$end = $name[$end];
		$url = "http://dynamic.12306.cn/otsquery/query/queryRemanentTicketAction.do?method=queryLeftTicket&orderRequest.train_date={$time}&orderRequest.from_station_telecode={$star}&orderRequest.to_station_telecode={$end}&orderRequest.train_no=&trainPassType=QB&trainClass=QB%23D%23Z%23T%23K%23QT%23&includeStudent=00&seatTypeAndNum=&orderRequest.start_time_str=00%3A00--24%3A00";
		$optionget = array('http' => array('method' => "GET", 'header' => "User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.0.04506; CIBA)\r\nAccept:*/*\r\nReferer:http://dynamic.12306.cn/otsquery/query/queryRemanentTicketAction.do?method=init")); 
		$file = file_get_contents($url, false , stream_context_create($optionget));
		return json_array(json_decode($file));
	}
	$result = doget("北京","廊坊","6-23");
  	$result = strip_tags($result['datas']);
	$return_str = str_replace(" ","",$result);
	$return_str = str_replace("\\n","",$return_str);
	$a = explode(",",$return_str);
	$name =array();
	$c = array_chunk($a,16);
	array_pop($c);
	foreach($c as $k =>$v){
		$str="余票:<br>商务座:".$v[5].",特等座:".$v[6].",一等座:".$v[7].",二等座:".$v[8].",高级软卧:".$v[9].",软卧:".$v[10].",硬卧:".$v[11].",软座:".$v[12].",硬座:".$v[13].",无座:".$v[14].",其他:".$v[15];
		$str = preg_replace("/,硬座\:--,/","",$str);
		$str = preg_replace("/商务座\:--,/","",$str);
		$str = preg_replace("/,特等座\:--,/","",$str);
		$str = preg_replace("/,一等座\:--,/","",$str);
		$str = preg_replace("/,二等座\:--,/","",$str);
		$str = preg_replace("/,高级软卧\:--,/","",$str);
		$str = preg_replace("/,软卧\:--,/","",$str);
		$str = preg_replace("/,硬卧\:--,/","",$str);
		$str = preg_replace("/,软座\:--,/","",$str);
		$str = preg_replace("/,硬座\:--,/","",$str);
		$str = preg_replace("/,其他\:--/","",$str);
		echo "车次:{$v[1]},发站:{$v[2]},到站:{$v[3]},历时:{$v[4]},<br>{$str}<br>";
	}



http://www.widuu.com/archives/06/682.html
Copy after login



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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Monotonic clock processing of time package Monotonic clock processing of time package Aug 04, 2023 pm 05:45 PM

Today we are mainly going to take a look at the time application method of golang time package. The general rule between the two is that "wall time" is used to tell time, and "monotonic clock" is used to measure time; there are other clock processing methods.

How to use the REPLACE function to replace a specified part of a string in MySQL How to use the REPLACE function to replace a specified part of a string in MySQL Jul 25, 2023 pm 01:18 PM

MySQL is a commonly used relational database management system that provides a variety of functions to process and operate data. Among them, the REPLACE function is used to replace the specified part of the string. In this article, we will introduce how to use the REPLACE function for string replacement in MySQL and demonstrate its usage through code examples. First, let’s take a look at the syntax of the REPLACE function: REPLACE(str,search_str,replace_str).

What are the string search and replace techniques in Python? What are the string search and replace techniques in Python? Oct 20, 2023 am 11:42 AM

What are the string search and replace techniques in Python? (Specific code example) In Python, strings are a common data type, and we often encounter string search and replace operations in daily programming. This article will introduce some common string search and replacement techniques, accompanied by specific code examples. To find a specific substring in a string, you can use the find() method or index() method of the string. The find() method returns the index of the first occurrence of the substring in the string.

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to use Java8 Time API How to use Java8 Time API Apr 28, 2023 pm 12:25 PM

1. Overview As part of this article, let us start with some problems with the existing Date and CalendarAPI and explore how the new Java8Date and TimeAPI solve these problems. We will also take a look at the core classes in the Java8 time class library, such as LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Period, Duration and their APIs. 2. The problem of thread safety of the old time API (before Java 8)-Date and Calendar classes are not thread-safe, making it difficult for developers to debug concurrency problems of these APIs and need to write additional code to deal with them.

What is the difference and usage between time and datetime in python What is the difference and usage between time and datetime in python May 02, 2023 am 11:01 AM

1. Two ways to represent time in Python: timestamp: offset in seconds relative to 1970.1.100:00:00, unique time tuple struct_time: a total of 9 elements>tm_year: year 1-12> tm_mon: month 1-12>tm_mday: day 1-31>tm_hour: hour 0-23>tm_min: minute 0-59>tm_sec: second 0-59>tm_wday: week 0-6 (0 means Sunday)>tm_day: Day of the year 1-366>tm_isdst: whether it is daylight saving, the default is -1.ti

Python built-in type str source code analysis Python built-in type str source code analysis May 09, 2023 pm 02:16 PM

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages ​​(such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

How to obtain and convert time in Python time module How to obtain and convert time in Python time module May 13, 2023 pm 12:19 PM

Pythontime module time acquisition and conversion Python's Time library can perform time-related processing, such as accessing the current date and time, outputting time in different formats, and waiting for a specified time. 1. Get the time 1.1. Timestamp importtimetimestamp=time.time()#1682737552.5009851 Greenwich Mean Time (GMT) The total number of seconds from 00:00:00 on January 1, 1970 to the present 1.2. Structured time importtimestruct_time= time.localtime()#time.struct_time(tm_year=2

See all articles