证件照检测+制作(无水印)
按指定规格检测并制作证件照,成功后直接返回无水印图片。
接口地址:https://api.zjzapi.com/idcardv5/all
请求方式:POST(application/x-www-form-urlencoded)
返回格式:json
接口费用:获取成功扣除0.6元
请求参数:
| 名称 | 必填 | 类型 | 说明 |
|---|---|---|---|
| key | 是 | string | 应用的key |
| item_id | 是 | int | 规格id,《查看规格列表》 |
| image | 是 | string | base64后的图片内容,大小不超过8M。 |
| colors | 否 | string | 颜色名称(需根据每个规格支持情况进行填写),不填写返回所有底色 |
| enhance | 否 | int | 人像增强,默认已支持,不需要可传参数0 |
| beauty | 否 | int | 美颜,默认已支持,不需要可传参数0 |
返回参数:
| 名称 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码 |
| msg | string | 返回说明 |
| data | array | 数据集 |
JSON返回示例:
{
"data": {
"pic_id": "9244614",
"list": {
"white": "http://demo.com/pic/20200511/913191c8906ce81a2107d6ff5157c014/white.jpg"
}
},
"code": 0,
"msg": "success"
}
请求示例代码:
请替换占位值后在服务端运行。图片使用原始 Base64 字符串,由表单编码器处理特殊字符;不要手动重复 URL 编码。HTTP 成功后仍需检查业务 code。
# Bash / zsh,cURL 7.76+;Windows 可使用 Git Bash 或 WSL。
curl --fail-with-body --max-time 60 --request POST 'https://api.zjzapi.com/idcardv5/all' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'key=YOUR_APP_KEY' \
--data-urlencode 'item_id=YOUR_ITEM_ID' \
--data-urlencode 'image=BASE64_ENCODED_IMAGE' \
--data-urlencode 'colors=white'
// Java 11+,保存为 Main.java,编译运行:javac -encoding UTF-8 Main.java && java Main
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) throws Exception {
Map<String, String> form = new LinkedHashMap<>();
form.put("key", "YOUR_APP_KEY");
form.put("item_id", "YOUR_ITEM_ID");
form.put("image", "BASE64_ENCODED_IMAGE");
form.put("colors", "white");
String body = form.entrySet().stream()
.map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)
+ "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8))
.collect(Collectors.joining("&"));
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10)).build();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.zjzapi.com/idcardv5/all"))
.timeout(Duration.ofSeconds(60))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
if (response.statusCode() < 200 || response.statusCode() >= 300) {
throw new IllegalStateException("HTTP " + response.statusCode());
}
// HTTP 成功不代表业务成功,还需检查响应 JSON 中的 code。
System.out.println(response.body());
}
}
# Python 3.8+,需先安装 requests:pip install requests
import requests
response = requests.post(
"https://api.zjzapi.com/idcardv5/all",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data={
"key": "YOUR_APP_KEY",
"item_id": "YOUR_ITEM_ID",
"image": "BASE64_ENCODED_IMAGE",
"colors": "white",
},
timeout=(10, 60),
)
response.raise_for_status()
# 按接口文档检查业务 code,再读取 data。
print(response.json())
<?php
// PHP 7.2+,需启用 cURL 扩展。
// 使用 http_build_query 编码表单,不能直接向 CURLOPT_POSTFIELDS 传数组。
$form = [
'key' => 'YOUR_APP_KEY',
'item_id' => 'YOUR_ITEM_ID',
'image' => 'BASE64_ENCODED_IMAGE',
'colors' => 'white',
];
$curl = curl_init('https://api.zjzapi.com/idcardv5/all');
curl_setopt_array($curl, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($form),
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 60,
]);
$result = curl_exec($curl);
$error = curl_error($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($result === false) {
throw new RuntimeException($error);
}
if ($status_code < 200 || $status_code >= 300) {
throw new RuntimeException('HTTP ' . $status_code);
}
// 按接口文档检查响应 JSON 中的业务 code,再读取 data。
echo $result;
// Go 1.16+,仅使用标准库。
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
)
func main() {
form := url.Values{
"key": {"YOUR_APP_KEY"},
"item_id": {"YOUR_ITEM_ID"},
"image": {"BASE64_ENCODED_IMAGE"},
"colors": {"white"},
}
request, err := http.NewRequest("POST", "https://api.zjzapi.com/idcardv5/all", strings.NewReader(form.Encode()))
if err != nil {
panic(err)
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{Timeout: 60 * time.Second}
response, err := client.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
panic(fmt.Errorf("HTTP %d", response.StatusCode))
}
result, err := io.ReadAll(response.Body)
if err != nil {
panic(err)
}
// 按接口文档检查响应 JSON 中的业务 code,再读取 data。
fmt.Println(string(result))
}
// Node.js 18+,保存为 request.mjs;仅在服务端运行,勿将凭据放进浏览器代码。
const form = new URLSearchParams([
["key", "YOUR_APP_KEY"],
["item_id", "YOUR_ITEM_ID"],
["image", "BASE64_ENCODED_IMAGE"],
["colors", "white"],
]);
const response = await fetch('https://api.zjzapi.com/idcardv5/all', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: form,
signal: AbortSignal.timeout(60000),
});
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
// 按接口文档检查业务 code,再读取 data。
console.log(await response.json());
// C# 10 / .NET 6+,放入控制台项目的 Program.cs。
using System;
using System.Collections.Generic;
using System.Net.Http;
using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(60) };
using var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("key", "YOUR_APP_KEY"),
new KeyValuePair<string, string>("item_id", "YOUR_ITEM_ID"),
new KeyValuePair<string, string>("image", "BASE64_ENCODED_IMAGE"),
new KeyValuePair<string, string>("colors", "white"),
});
// FormUrlEncodedContent 自动设置 application/x-www-form-urlencoded 并编码字段。
using var response = await client.PostAsync("https://api.zjzapi.com/idcardv5/all", content);
response.EnsureSuccessStatusCode();
// 按接口文档检查响应 JSON 中的业务 code,再读取 data。
Console.WriteLine(await response.Content.ReadAsStringAsync());