12306余票和票价查询

只提供学习,请不要用于商业用途

接口状态: 正常
总调用: 107
添加时间: 2026-05-22
更新时间: 2026-06-03 耗时: 1.93ms | 缓存: 未命中
广告位
创创云
广告位
顶端云
广告位
语鹿CDN
广告位
广告位招租

请求信息

请求地址:
https://api-v2.yuafeng.cn/API/12306_piaojia.php
示例地址:
https://api-v2.yuafeng.cn/API/12306_piaojia.php?from=深圳北&to=上海虹桥&date=2026-05-23

请求参数

参数名 类型 必填 说明
date string 日期,格式年-月-日
from string 出发站
to string 终点站

收费情况

是否收费 单次调用费用 收费类型 免费调用额度 QPS限制情况
0.0000 元/次 免费调用 接口级限制

状态码说明

状态码 说明
200 请求成功,服务器已成功处理了请求。
403 服务器拒绝请求。这可能是由于缺少必要的认证凭据(如API密钥)或权限不足。
404 请求的资源未找到。请检查您的请求地址是否正确。
429 请求过于频繁。您已超出速率限制,请稍后再试。
500 服务器内部错误。服务器在执行请求时遇到了问题。

在线测试

{ "code": 200, // 接口状态码,200代表请求成功 "message": "request success", // 接口返回提示信息,代表本次查询成功 "data": { // 核心返回业务数据 "fromStation": "湛江", // 出发站点名称 "fromCode": "ZJZ", // 出发站车站编码 "toStation": "上海虹桥", // 到达站点名称 "toCode": "AOH", // 到达站车站编码 "queryDate": "2026-05-23", // 车票查询日期 "trainList": [ // 列车班次数组,所有车次信息集合 { "trainNo": "K512", // 列车车次编号 "trainType": "快速列车", // 列车类型 "fromStation": "湛江", // 该车次出发站 "toStation": "上海虹桥", // 该车次终点站 "departTime": "00:34", // 发车时间 "arriveTime": "07:02", // 预计到站时间 "ticket": { // 各席位余票状态 "business": "--", // 商务座,--代表无此席位 "firstClass": "--", // 一等座 "secondClass": "--", // 二等座 "softSleeperHigh": "--", // 高级软卧 "softSleeper": "无", // 软卧,无代表没票 "dBed": "--", // 动卧 "hardSleeper": "无", // 硬卧 "softSeat": "--", // 软座 "hardSeat": "无", // 硬座 "noSeat": "有" // 无座票,有代表可购买 }, "price": { // 对应各席位票价 "business": "--", // 商务座价格 "firstClass": "--", // 一等座价格 "secondClass": "--", // 二等座价格 "softSleeperHigh": "--", // 高级软卧价格 "softSleeper": "¥758.0", // 软卧票价 "dBed": "--", // 动卧票价 "hardSleeper": "¥439.0", // 硬卧票价 "softSeat": "--", // 软座票价 "hardSeat": "¥258.0", // 硬座票价 "noSeat": "¥258.0" // 无座票价 } }, { "trainNo": "G248", // 列车车次编号 "trainType": "高速动车组", // 列车类型 "fromStation": "湛江", // 该车次出发站 "toStation": "上海虹桥", // 该车次终点站 "departTime": "09:52", // 发车时间 "arriveTime": "19:25", // 预计到站时间 "ticket": { // 各席位余票状态 "business": "12", // 商务座剩余12张票 "firstClass": "有", // 一等座有票 "secondClass": "有", // 二等座有票 "softSleeperHigh": "--", // 高级软卧无此席位 "softSleeper": "--", // 软卧无此席位 "dBed": "--", // 动卧无此席位 "hardSleeper": "--", // 硬卧无此席位 "softSeat": "--", // 软座无此席位 "hardSeat": "--", // 硬座无此席位 "noSeat": "有" // 无座可购买 }, "price": { // 对应各席位票价 "business": "¥3798.0", // 商务座价格 "firstClass": "¥1781.0", // 一等座价格 "secondClass": "¥1122.0", // 二等座价格 "softSleeperHigh": "--", // 高级软卧价格 "softSleeper": "--", // 软卧价格 "dBed": "--", // 动卧价格 "hardSleeper": "--", // 硬卧价格 "softSeat": "--", // 软座价格 "hardSeat": "--", // 硬座价格 "noSeat": "¥1122.0" // 无座票价 } }, { "trainNo": "G252", // 列车车次编号 "trainType": "高速动车组", // 列车类型 "fromStation": "湛江", // 该车次出发站 "toStation": "上海虹桥", // 该车次终点站 "departTime": "14:08", // 发车时间 "arriveTime": "22:43", // 预计到站时间 "ticket": { // 各席位余票状态 "business": "3", // 商务座剩余3张票 "firstClass": "有", // 一等座有票 "secondClass": "有", // 二等座有票 "softSleeperHigh": "--", // 高级软卧无此席位 "softSleeper": "--", // 软卧无此席位 "dBed": "--", // 动卧无此席位 "hardSleeper": "--", // 硬卧无此席位 "softSeat": "--", // 软座无此席位 "hardSeat": "--", // 硬座无此席位 "noSeat": "有" // 无座可购买 }, "price": { // 对应各席位票价 "business": "¥3209.0", // 商务座价格 "firstClass": "¥1610.0", // 一等座价格 "secondClass": "¥1093.0", // 二等座价格 "softSleeperHigh": "--", // 高级软卧价格 "softSleeper": "--", // 软卧价格 "dBed": "--", // 动卧价格 "hardSleeper": "--", // 硬卧价格 "softSeat": "--", // 软座价格 "hardSeat": "--", // 硬座价格 "noSeat": "¥1093.0" // 无座票价 } } ] } }

调用示例

<?php
$url = 'https://api-v2.yuafeng.cn/API/12306_piaojia.php';
$params = ['date' => 'YOUR_VALUE', 'from' => 'YOUR_VALUE', 'to' => 'YOUR_VALUE', ];
$url .= '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
-- 加载依赖库(需确保已安装 luasocket,安装命令:luarocks install luasocket)
 local http = require("socket.http")
 local ltn12 = require("ltn12")
 local url = require("socket.url")
 -- 1. 基础配置(替换为你的实际参数)
 local baseUrl = "https://api-v2.yuafeng.cn/API/12306_piaojia.php"
 local urlParam = "YOUR_VALUE"  -- 替换为实际URL参数值
 local apikey = "YOUR_VALUE"    -- 替换为实际API密钥
 -- 2. 编码查询参数(避免特殊字符导致请求错误,对应Java的URLEncoder)
 local encodedParam = url.escape(urlParam)
 local encodedApikey = url.escape(apikey)
 -- 3. 构建完整请求URL(拼接基础URL和查询参数)
 local fullUrl = string.format("%s?%s&apikey=%s", baseUrl, encodedParam, encodedApikey)
 -- 4. 配置请求选项(设置超时、响应接收方式)
 local response = {}  -- 用于存储响应内容
 local requestOptions = {
     url = fullUrl,
     method = "GET",
     timeout = 5,  -- 超时时间(秒),对应Java的5000ms
     sink = ltn12.sink.table(response)  -- 将响应写入response表
 }
 -- 5. 发送请求并处理结果
 local statusCode, responseHeaders, responseStatusLine = http.request(requestOptions)
 -- 6. 解析响应
 if statusCode == 200 then  -- 对应Java的 HTTP_OK(200)
     -- 拼接响应内容(response表中存储的是按行分割的字符串)
     local responseBody = table.concat(response)
     print("请求成功,响应内容:")
     print(responseBody)
 else
     -- 打印失败信息(状态码、错误描述)
     print("请求失败,响应码: " .. tostring(statusCode))
     print("响应状态描述: " .. tostring(responseStatusLine))
 end
package main
import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
)

func main() {
	// API 的基础 URL
	baseURL := "https://api-v2.yuafeng.cn/API/12306_piaojia.php"
	// 要传递的参数
	urlParam := "YOUR_VALUE"
	//你的apikey
	apikey := "YOUR_VALUE"
	
	// 构建带参数的请求 URL
	requestURL := fmt.Sprintf("%s?apikey=%s&%s", baseURL, url.QueryEscape(apikey), url.QueryEscape(urlParam))

	// 发送 GET 请求
	resp, err := http.Get(requestURL)
	if err != nil {
		fmt.Printf("请求发送失败: %v\n", err)
		return
	}
	defer resp.Body.Close()

	// 读取响应内容
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Printf("读取响应失败: %v\n", err)
		return
	}

	// 输出响应结果
	fmt.Println(string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class HttpRequestDemo {
    public static void main(String[] args) {
        try {
            // 基础URL
            String baseUrl = "https://api-v2.yuafeng.cn/API/12306_piaojia.php";
            
            // 参数
            String urlParam = "YOUR_VALUE"; // 替换为实际的URL参数值
            String apikey = "YOUR_VALUE";   // 替换为实际的API密钥
            
            // 构建查询参数
            String query = String.format("%s&apikey=%s",
                    URLEncoder.encode(urlParam, StandardCharsets.UTF_8.toString()),
                    URLEncoder.encode(apikey, StandardCharsets.UTF_8.toString()));
            
            // 创建完整的URL
            String fullUrl = baseUrl + "?" + query;
            
            // 创建URL对象
            URL url = new URL(fullUrl);
            
            // 打开连接
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            
            // 设置请求方法
            connection.setRequestMethod("GET");
            
            // 设置超时时间(可选)
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(5000);
            
            // 获取响应代码
            int responseCode = connection.getResponseCode();
            
            // 读取响应内容
            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader reader = new BufferedReader(
                    new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
                
                StringBuilder response = new StringBuilder();
                String line;
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }
                reader.close();
                
                String result = response.toString();
                
                // 输出响应结果
                System.out.println(result);
            } else {
                System.out.println("请求失败,响应码: " + responseCode);
            }
            
            // 关闭连接
            connection.disconnect();
            
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("请求失败,报错块: " + e.getMessage());
        }
    }
}
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

public class HttpRequestDemo {
    public static void main(String[] args) {
        // OkHttpClient 实例,可复用,建议全局单例
        OkHttpClient client = new OkHttpClient();

        // 参数
        String urlParam = "YOUR_VALUE"; // 替换为实际的URL参数值
        urlParam = urlParam + "&apikey=" + "YOUR_VALUE";   // 替换为实际的API密钥
        String apiBaseUrl = "https://api-v2.yuafeng.cn/API/12306_piaojia.php"; 

        // 构建带参数的请求 URL
        String requestUrl = apiBaseUrl + "?" + urlParam;

        // 构建请求
        Request request = new Request.Builder()
                .url(requestUrl)
                .get() // 明确为 GET 请求(OkHttp 默认也是 GET,可省略)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) {
                // 如果请求成功,获取并打印响应体内容
                assert response.body() != null;
                System.out.println(response.body().string());
            } else {
                // 请求失败时,打印响应码等信息
                System.out.println("请求失败,响应码:" + response.code());
            }
        } catch (IOException e) {
            // 捕获 IO 异常并打印
            e.printStackTrace();
            System.out.println("请求失败,报错块: " + e.getMessage());
        }
    }
}
import requests

url = "https://api-v2.yuafeng.cn/API/12306_piaojia.php"
params = {
    'date': 'YOUR_VALUE',
    'from': 'YOUR_VALUE',
    'to': 'YOUR_VALUE',
}
response = requests.get(url, params=params)
print(response.text)
const url = new URL('https://api-v2.yuafeng.cn/API/12306_piaojia.php');
const params = {
    'date': 'YOUR_VALUE',
    'from': 'YOUR_VALUE',
    'to': 'YOUR_VALUE',
};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));

fetch(url)
    .then(response => response.text())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));