Appearance
红绿灯API
红绿灯API提供了获取交通信号灯状态和路口信息的服务,对于需要实时交通信号数据的应用非常有用。
获取路口信息 API
接口描述
获取特定城市的路口信息列表,包括路口ID、名称和位置等。
请求方式
| URL | 请求方式 |
|---|---|
| https://lbs.xiaojukeji.com/api/v2/crossinfo | POST、GET |
请求
查询参数(GET)
| 参数名 | 必选 | 类型 | 描述 | 示例值 |
|---|---|---|---|---|
| key | 是 | string | 鉴权用的 API Key | YOUR_API_KEY |
| citycode | 是 | string | 城市代码,见城市代码表 | 1 |
| version | 否 | string | 当前版本号,若服务端版本号与参数一致则返回304未更新,不一致或不传则返回全量数据和最新版本号 | 2025121912 |
| format | 否 | string | 返回格式,proto/json,默认为 json | json |
请求体参数(POST)
当使用POST方法时,请求体应为 CrossInfoRequest 模型的JSON格式。
请求示例
GET
shell
curl -X GET "https://lbs.xiaojukeji.com/api/v2/crossinfo?key=YOUR_API_KEY&citycode=1"POST
shell
curl -s -X POST "https://lbs.xiaojukeji.com/api/v2/crossinfo?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"citycode":1}'响应
成功响应为 CrossInfoResponse 模型的JSON格式。
响应示例
json
{
"status": 10000,
"msg": "OK",
"trace_id": "ac197017694110713508015ee62707b0",
"results": {
"version": "2025121912",
"data": [
{
"cityCode": 1,
"crossId": 47563072,
"crossName": "张家庄路,香堤中路交界",
"latitude": 4020950,
"longitude": 11666784,
"systemTimeStamp": 1765871729,
"lampStatusList": [
{
"direction": 0,
"lampStatus": 11,
"dir_points": [
{
"latitude": 4021097,
"longitude": 11666784
},
{
"latitude": 4020950,
"longitude": 11666784
}
],
"lamp_points": [
{
"latitude": 4020950,
"longitude": 11666784
},
{
"latitude": 4020931,
"longitude": 11666780
}
]
},
{
"direction": 6,
"lampStatus": 11,
"dir_points": [
{
"latitude": 4020946,
"longitude": 11666772
},
{
"latitude": 4020950,
"longitude": 11666784
}
],
"lamp_points": [
{
"latitude": 4020950,
"longitude": 11666784
},
{
"latitude": 4020949,
"longitude": 11666873
}
]
}
]
}
]
}
}获取路口信号灯状态 API
接口描述
获取特定路口的信号灯相位状态信息,包括红绿灯的持续时间和当前状态。
请求方式
- HTTP 方法: GET / POST
- 请求URL:
/api/v2/trafficlight
请求参数
查询参数(GET)
| 参数名 | 必选 | 类型 | 描述 | 示例值 |
|---|---|---|---|---|
| key | 是 | string | 鉴权用的 API Key | YOUR_API_KEY |
| citycode | 是 | string | 城市代码,见城市代码表 | 1 |
| cross_ids | 是 | string[] | 路口ID | 9000119041941,74896013 |
| version | 否 | string | 当前版本号,若服务端版本号与参数一致则返回304未更新,不一致或不传则返回全量数据和最新版本号 | 202306201701 |
| format | 否 | string | 返回格式,proto/json,默认为 json | json |
请求体参数(POST)
当使用POST方法时,请求体应为 CrossInfoRequest 模型的JSON格式。
请求示例
GET
shell
curl -X GET "https://lbs.xiaojukeji.com/api/v2/trafficlight?key=YOUR_API_KEY&citycode=1&cross_ids=9000119041941,13297751&format=json"POST
shell
curl -s -X POST "https://lbs.xiaojukeji.com/api/v2/trafficlight?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"citycode":1,"cross_ids":["9000119041941","13297751"],"format":"json"}'响应
成功响应为包含信号灯相位状态的JSON格式。
响应示例
json
{
"status": 10000,
"msg": "OK",
"trace_id": "ac197017694110542ba0015e21afd4b0",
"results": {
"data": [
{
"cityCode": 1,
"confidence": 100,
"crossId": "9000119041941",
"crossName": "顺黄路,孙河组团六号路交界",
"latitude": 4005840,
"longitude": 11652326,
"phaseLampStatusList": [
{
"batchTime": "1765870980",
"confidence": 100,
"cycle": 87,
"dirPoints": [
{
"latitude": 4005837,
"longitude": 11652351
},
{
"latitude": 4005840,
"longitude": 11652326
}
],
"direction": 2,
"greenDuration": 17,
"lampStatus": 12,
"lampPoints": [
{
"latitude": 4005828,
"longitude": 11652320
},
{
"latitude": 4005690,
"longitude": 11652259
}
],
"offset": 70,
"phaseEndTime": 964,
"phaseStartTime": 954,
"redDuration": 66,
"version": "2.0",
"yellowDuration": 4
}
],
"systemTimeStamp": "1765871700"
}
],
"version": "202512161555"
}
}protobuf 格式说明
proto 格式返回的是二进制数据,需要使用 proto 解析器进行解析。
proto
syntax = "proto2";
// Common from crossinfo.proto
message Point {
optional int32 latitude = 1;
optional int32 longitude = 2;
}
message LampStatus {
optional int32 direction = 1;
optional int32 lamp_status = 2;
repeated Point dir_points = 3;
repeated Point lamp_points = 4;
}
message CrossInfo {
optional int32 city_code = 1;
optional int64 cross_id = 2;
optional string cross_name = 3;
optional int32 latitude = 4;
optional int32 longitude = 5;
optional int64 system_time_stamp = 6;
repeated LampStatus lamp_status_list = 7;
}
message CrossInfoResult {
repeated CrossInfo data = 1;
optional string version = 2;
}
message CrossInfoResponse {
optional int32 status = 1;
optional string msg = 2;
optional string trace_id = 3;
optional CrossInfoResult results = 4;
}
// PhaseLampStatus 表示 trafficlight 返回中的单个相位灯组状态
message PhaseLampStatus {
optional int64 batch_time = 1;
optional int32 confidence = 2;
optional int32 cycle = 3;
repeated Point dir_points = 4;
optional int32 direction = 5;
optional int32 green_duration = 6;
optional int32 lamp_status = 7;
repeated Point lamp_points = 8;
optional int32 offset = 9;
optional int32 phase_end_time = 10;
optional int32 phase_start_time = 11;
optional int32 red_duration = 12;
optional string version = 13;
optional int32 yellow_duration = 14;
}
// TrafficLight 表示 trafficlight 接口中单个路口的详细信息(对应 JSON 中的每个元素)
message TrafficLight {
optional int32 city_code = 1;
optional int32 confidence = 2;
optional int64 cross_id = 3;
optional string cross_name = 4;
optional int32 latitude = 5;
optional int32 longitude = 6;
repeated PhaseLampStatus phase_lamp_status_list = 7;
optional int64 system_time_stamp = 8;
}
message TrafficLightResult {
repeated TrafficLight data = 1;
optional string version = 2;
}
// TrafficLightResponse 为返回的包装(用于包含状态/消息以及数据数组)
message TrafficLightResponse {
optional int32 status = 1;
optional string msg = 2;
optional string trace_id = 3;
optional TrafficLightResult results = 4;
}