PHP调用示例
<?php
// 车牌号查询API调用示例
$apiUrl = "https://41game.com/data/platequery.php";
$plateNumber = "京A12345";
$apiKey = "your_api_key_here";
// 构建请求参数
$params = [
'plate' => $plateNumber,
'key' => $apiKey,
'num' => 1, // 可指定返回条数
'format' => 1
];
// 初始化curl
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $apiUrl . '?' . http_build_query($params),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
]);
// 执行请求
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// 解析结果
if ($httpCode == 200) {
$result = json_decode($response, true);
if ($result['code'] == 200) {
// 请求成功
echo "省份名称:" . $result['province_name'] . "\n";
echo "城市:" . $result['city'] . "\n";
echo "组织机构:" . $result['organization'] . "\n";
echo "车辆类型:" . $result['type'] . "\n";
} else {
echo "API返回错误:" . json_encode($result);
}
} else {
echo "请求失败,HTTP状态码:" . $httpCode;
}
?>
Python调用示例
import requests
# 车牌号查询API调用示例
api_url = "https://41game.com/data/platequery.php"
plate_number = "京A12345"
api_key = "your_api_key_here"
# 构建请求参数
params = {
'plate': plate_number,
'key': api_key,
'num': 1,
'format': 1
}
# 发起请求
response = requests.get(api_url, params=params, timeout=10, verify=False)
# 解析结果
if response.status_code == 200:
result = response.json()
if result['code'] == 200:
# 请求成功
print(f"省份名称:{result['province_name']}")
print(f"城市:{result['city']}")
print(f"组织机构:{result['organization']}")
print(f"车辆类型:{result['type']}")
else:
print(f"API返回错误:{result}")
else:
print(f"请求失败,状态码:{response.status_code}")
Java调用示例
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class PlateQueryApiDemo {
public static void main(String[] args) {
try {
// 车牌号查询API地址
String apiUrl = "https://41game.com/data/platequery.php";
String plateNumber = "京A12345";
String apiKey = "your_api_key_here";
// 构建请求URL
String requestUrl = apiUrl + "?plate=" + URLEncoder.encode(plateNumber, "UTF-8")
+ "&key=" + URLEncoder.encode(apiKey, "UTF-8")
+ "&num=1"
+ "&format=1";
// 发起请求
URL url = new URL(requestUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
// 读取响应
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = in.readLine()) != null) {
response.append(line);
}
in.close();
// 输出结果
System.out.println("接口返回结果:" + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
返回示例
{
"code":200,
"province_name":"北京市",
"city":"北京市",
"organization":"中央国家机关",
"type":"10"
}
{
"code":400,
"message":"车牌号格式错误",
"data":null
}