以下 5 种语言示例都是可直接运行的,只需把 YOUR_API_KEY 替换为实际 Key。
cURL
curl -X POST "https://v1.apizero.cn/api/ocr-idcard" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input_type": "url",
"input_data": "https://example.com/idcard-front.jpg"
}'
Python
import requests
resp = requests.request(
"POST",
"https://v1.apizero.cn/api/ocr-idcard",
headers={"X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json"},
json={
"input_type": "url",
"input_data": "https://example.com/idcard-front.jpg",
},
timeout=15,
)
resp.raise_for_status()
print(resp.json())
JavaScript (Node.js)
// Node.js 18+ / 浏览器原生 fetch
const res = await fetch("https://v1.apizero.cn/api/ocr-idcard", {
method: "POST",
headers: {
"X-Api-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
"input_type": "url",
"input_data": "https://example.com/idcard-front.jpg"
}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log(data);
Go
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
body := []byte(`{"input_type":"url","input_data":"https://example.com/idcard-front.jpg"}`)
req, _ := http.NewRequest("POST", "https://v1.apizero.cn/api/ocr-idcard", bytes.NewBuffer(body))
req.Header.Set("X-Api-Key", "YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
out, _ := io.ReadAll(resp.Body)
fmt.Println(string(out))
}
PHP
<?php
$payload = json_encode([
"input_type" => "url",
"input_data" => "https://example.com/idcard-front.jpg",
], JSON_UNESCAPED_UNICODE);
$ch = curl_init("https://v1.apizero.cn/api/ocr-idcard");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
"X-Api-Key: YOUR_API_KEY",
"Content-Type: application/json",
],
CURLOPT_TIMEOUT => 15,
]);
$body = curl_exec($ch);
curl_close($ch);
$data = json_decode($body, true);
print_r($data);