通过API向第3方服务商请求服务,返回数据JSON格式处理成PHP数组格式
<?php
//API产品路径
$host = "http://plane.market.alicloudapi.com";
$path = "/ai_market/ai_airplane/get_airplane_info";
$method = "GET";
//APPCODE
$appcode = "841d8cf0822c4a0f883096df8539e20f676768888";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
array_push($headers, "Content-Type:application/json; charset=utf-8");
//参数配置
//日期,如:20190208
$DATE = "20200109";
//航班编号,如:MU5128
$FLIGHT_ID = "MU5128";
$querys = "DATE=".$DATE.
"&FLIGHT_ID=".$FLIGHT_ID;
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$T = curl_exec($curl);//接收请求的数据
var_dump(json_decode($T));
var_dump(json_decode($T, true));//解码json数据格式为PHP数组格式
?>
上图是PHP数组格式数据。