require_once("curl.func.php");
$method = "POST";
$url = "https://open.6api.net/train/traininfo";
$headers = NULL;
$params = array(
"appkey" => "yourappsecret",
"trainno_uuid" => "24000G10690G",
"departstation_code" => "VNP",
"terminalstation_code" => "ZBK"
);
$result = api_curl($method, $url, $headers, $params);
if ($result) {
$body = json_decode($result["body"], TRUE);
$status_code = $body["status"];
if ($status_code == "200") {
var_dump($body["result"]);
}else
var_dump($body);
}else
echo "发送请求失败";
/**
* 主函数
* @param args
*/
public static void main(String args[])
{
//请求地址设置
String url = "https://open.6api.net/train/traininfo";
//请求方法设置
String requestMethod = "POST";
//请求头部设置
Map<String, String> headers = new HashMap<String, String>();
//请求参数设置
Map<String, String> params = new HashMap<String, String>();
params.put("appkey", "yourappsecret");
params.put("trainno_uuid", "24000G10690G");
params.put("departstation_code", "VNP");
params.put("terminalstation_code", "ZBK");
String result = proxyToDesURL(requestMethod, url, headers, params);
if (result != null) {
JSONObject jsonObject = JSONObject.parseObject(result);
String status_code = jsonObject.getString("status");
if (status_code.equals("200")) {
System.out.println("请求成功:" + jsonObject.getString("result"));
} else {
System.out.println("请求失败:" + jsonObject.getString("msg"));
}
} else {
System.out.println("发送请求异常");
}
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 测试环境: python2.7
# 安装requests依赖 => pip install requests/ easy_install requests
import requests
import json
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
def api_send_request(method, url, params=None, headers=None):
'''
转发请求到目的主机
@param method str 请求方法
@param url str 请求地址
@param params dict 请求参数
@param headers dict 请求头
'''
method = str.upper(method)
if method == "POST":
return requests.post(url=url, data=params, headers=headers)
elif method == "GET":
return requests.get(url=url, params=params, headers=headers)
else:
return None
method = "POST"
url = "https://open.6api.net/train/traininfo"
headers = None
params = {
"appkey" : "yourappsecret",
"trainno_uuid" : "24000G10690G",
"departstation_code" : "VNP",
"terminalstation_code" : "ZBK"
}
result = api_send_request(method=method, url=url, params=params, headers=headers)
if result:
body = result.result
response = json.loads(body)
status_code = response["status"]
if (status_code == "200"):
print("请求成功:%s" % (body,))
else:
print("请求失败: %s" % (body,))
else:
print("发送请求失败")
{
"status": 200,
"msg": "OK",
"result": {
"start_station_name": "北京南",
"end_station_name": "青岛",
"station_train_code": "G1069",
"train_class_name": "高速",
"service_type": "有空调",
"list": [
{
"station_no": "01",
"arrive_time": "----",
"station_name": "北京南",
"isChina": "1",
"start_time": "12:31",
"stopover_time": "----",
"isEnabled": true
},
{
"station_no": "02",
"arrive_time": "12:52",
"station_name": "廊坊",
"isChina": "1",
"start_time": "12:54",
"stopover_time": "2分钟",
"isEnabled": true
},
{
"station_no": "03",
"arrive_time": "13:29",
"station_name": "沧州西",
"isChina": "1",
"start_time": "13:31",
"stopover_time": "2分钟",
"isEnabled": true
},
{
"station_no": "04",
"arrive_time": "13:58",
"station_name": "德州东",
"isChina": "1",
"start_time": "14:19",
"stopover_time": "21分钟",
"isEnabled": true
},
{
"station_no": "05",
"arrive_time": "14:43",
"station_name": "济南西",
"isChina": "1",
"start_time": "14:45",
"stopover_time": "2分钟",
"isEnabled": true
},
{
"station_no": "06",
"arrive_time": "15:02",
"station_name": "济南",
"isChina": "1",
"start_time": "15:04",
"stopover_time": "2分钟",
"isEnabled": true
},
{
"station_no": "07",
"arrive_time": "15:46",
"station_name": "淄博",
"isChina": "1",
"start_time": "15:48",
"stopover_time": "2分钟",
"isEnabled": true
},
{
"station_no": "08",
"arrive_time": "16:23",
"station_name": "潍坊",
"isChina": "1",
"start_time": "16:25",
"stopover_time": "2分钟",
"isEnabled": false
},
{
"station_no": "09",
"arrive_time": "17:22",
"station_name": "青岛北",
"isChina": "1",
"start_time": "17:27",
"stopover_time": "5分钟",
"isEnabled": false
},
{
"station_no": "10",
"arrive_time": "17:50",
"station_name": "青岛",
"isChina": "1",
"start_time": "17:50",
"stopover_time": "----",
"isEnabled": false
}
]
}
}