请求URL:https://ocr-api.shiliuai.com/api/signature_verification/v1
请求方式:POST
返回类型:JSON
参数 | 类型 | 说明 |
---|---|---|
Content-type | string | application/json |
Authorization | string | 'APPCODE ' + 您的AppCode (注意英文空格) |
参数 | 类型 | 说明 |
---|---|---|
Content-type | string | application/json |
x-ca-key | string | 您的AppKey |
x-ca-timestamp | string | 时间戳(毫秒) |
x-ca-signature | string | 签名sign |
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
image_base64_1 | string | 是 | base64编码的图片文件1 |
image_base64_2 | string | 是 | base64编码的图片文件2 |
thresh | float | 否 | 阈值,默认为0.734 |
import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.file.Files; import java.util.Base64; import org.json.JSONObject; public class HandwritingVerification { private static final String API_URL = "https://ocr-api.shiliuai.com/api/handwriting_verification/v1"; // 读取文件并转换为Base64 private static String getBase64(String filePath) throws IOException { byte[] fileContent = Files.readAllBytes(new File(filePath).toPath()); return Base64.getEncoder().encodeToString(fileContent); } public static void verify(String appcode, String filePath1, String filePath2) { HttpURLConnection connection = null; try { // 准备请求数据 JSONObject requestData = new JSONObject(); requestData.put("image_base64_1", getBase64(filePath1)); requestData.put("image_base64_2", getBase64(filePath2)); requestData.put("thresh", 0.7); // 创建连接 URL url = new URL(API_URL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", "APPCODE " + appcode); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); // 发送请求数据 try (OutputStream os = connection.getOutputStream()) { byte[] input = requestData.toString().getBytes("utf-8"); os.write(input, 0, input.length); } // 处理响应 int responseCode = connection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { try (BufferedReader br = new BufferedReader( new InputStreamReader(connection.getInputStream(), "utf-8"))) { StringBuilder response = new StringBuilder(); String responseLine; while ((responseLine = br.readLine()) != null) { response.append(responseLine.trim()); } JSONObject jsonResponse = new JSONObject(response.toString()); System.out.println(jsonResponse.toString(4)); // 格式化输出 } } else { System.out.println("请求失败,状态码: " + responseCode); } } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) { connection.disconnect(); } } } public static void main(String[] args) { String appcode = "你的APPCODE"; String filePath1 = "本地图片1路径"; String filePath2 = "本地图片2路径"; verify(appcode, filePath1, filePath2); } }
// 请求接口 define("URL", "https://ocr-api.shiliuai.com/api/handwriting_verification/v1"); // 图片转base64 function get_base64($file_path) { $data = file_get_contents($file_path); return base64_encode($data); } function demo($appcode, $file_path_1, $file_path_2) { // 请求头 $headers = [ 'Authorization: APPCODE ' . $appcode, 'Content-Type: application/json' ]; // 请求体 $b64_1 = get_base64($file_path_1); $b64_2 = get_base64($file_path_2); $data = [ "image_base64_1" => $b64_1, "image_base64_2" => $b64_2, "thresh" => 0.7 ]; // 初始化cURL $ch = curl_init(); // 设置cURL选项 curl_setopt($ch, CURLOPT_URL, URL); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过SSL验证(生产环境建议开启) // 执行请求 $response = curl_exec($ch); // 检查错误 if(curl_errno($ch)) { echo 'cURL Error: ' . curl_error($ch); } else { $result = json_decode($response, true); print_r($result); } // 关闭cURL资源 curl_close($ch); } // 主程序 if ($_SERVER['SCRIPT_FILENAME'] == __FILE__) { $appcode = "你的APPCODE"; $file_path_1 = "本地图片1路径"; $file_path_2 = "本地图片2路径"; demo($appcode, $file_path_1, $file_path_2); }
# -*- coding: utf-8 -*- import requests import base64 import json # 请求接口 URL = "https://ocr-api.shiliuai.com/api/signature_verification/v1" # 图片转base64 def get_base64(file_path): with open(file_path, 'rb') as f: data = f.read() b64 = base64.b64encode(data).decode('utf8') return b64 def demo(appcode, file_path_1, file_path_2): # 请求头 headers = { 'Authorization': 'APPCODE %s' % appcode, 'Content-Type': 'application/json' } # 请求体 b64_1 = get_base64(file_path_1) b64_2 = get_base64(file_path_2) data = { "image_base64_1": b64_1, "image_base64_2": b64_2, "thresh": 0.4 } # 请求 response = requests.post(url=URL, headers=headers, json=data) content = json.loads(response.content) print(content) if __name__=="__main__": appcode = "你的APPCODE" file_path_1 = "本地图片1路径" file_path_2 = "本地图片2路径" demo(appcode, file_path_1, file_path_2)
# -*- coding: utf-8 -*- import requests import base64 import json import hashlib import time # 请求接口 URL = "https://ocr-api.shiliuai.com/api/signature_verification/v1" # 图片转base64 def get_base64(file_path): with open(file_path, 'rb') as f: data = f.read() b64 = base64.b64encode(data).decode('utf8') return b64 # md5 def md5(s): return hashlib.md5(s.encode("utf8")).hexdigest() def demo(app_key, app_secret, file_path_1, file_path_2): # 请求头 t = int(time.time() * 1000) s = "%s%d%s" % (app_key, t, app_secret) sign = md5(s) headers = {'x-ca-key': app_key, 'x-ca-timestamp': t, 'x-ca-signature': sign, "Content-Type": "application/json"} # 请求体 b64_1 = get_base64(file_path_1) b64_2 = get_base64(file_path_2) data = { "image_base64_1": b64_1, "image_base64_2": b64_2, "thresh": 0.4 } # 请求 response = requests.post(url=URL, headers=headers, json=data) content = json.loads(response.content) print(content) if __name__=="__main__": app_key = "你的APP_KEY" app_secret = "你的APP_SECRET" file_path_1 = "本地图片1路径" file_path_2 = "本地图片2路径" demo(appcode, file_path_1, file_path_2)
function get_base64($path){ if($fp = fopen($path, "rb", 0)) { $binary = fread($fp, filesize($path)); // 文件读取 fclose($fp); $b64 = base64_encode($binary); // 转base64 }else{ $b64=""; printf("%s 文件不存在", $path); } return $b64; } $url = "https://ocr-api.shiliuai.com/api/bank_card_ocr/v1"; $img_path = "图片路径"; $method = "POST"; //请求头 $app_key = "你的app_key"; $app_secret = "你的app_secret"; $sign_string = $app_key . "&" . $timestamp . "&" . $app_secret; $sign = md5($sign_string); $headers = array(); array_push($headers, "Content-Type:application/json"); array_push($headers, "x-ca-key:" . $app_key); array_push($headers, "x-ca-timestamp:" . $timestamp); array_push($headers, "x-ca-signature:" . $sign); //请求体 $b64 = get_base64($img_path); $data = array( "image_base64" => $b64 ); $post_data = json_encode($data); //请求 $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); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); $result = curl_exec($curl); var_dump($result);
import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; import java.security.MessageDigest; import java.time.Instant; import java.net.HttpURLConnection; import java.net.URL; public class HandwritingVerification { private static final String API_URL = "https://ocr-api.shiliuai.com/api/handwriting_verification/v1"; // 图片转Base64 private static String getBase64(String filePath) throws IOException { byte[] fileContent = Files.readAllBytes(Paths.get(filePath)); return java.util.Base64.getEncoder().encodeToString(fileContent); } // 生成MD5签名 private static String md5(String input) { try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digest = md.digest(input.getBytes("UTF-8")); StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("%02x", b)); } return sb.toString(); } catch (Exception e) { throw new RuntimeException("MD5生成失败", e); } } public static void demo(String appKey, String appSecret, String filePath1, String filePath2) { try { // 生成签名 long timestamp = Instant.now().toEpochMilli(); String signStr = appKey + timestamp + appSecret; String signature = md5(signStr); // 准备请求头 URL url = new URL(API_URL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("x-ca-key", appKey); conn.setRequestProperty("x-ca-timestamp", String.valueOf(timestamp)); conn.setRequestProperty("x-ca-signature", signature); conn.setDoOutput(true); // 准备请求体 String image1 = getBase64(filePath1); String image2 = getBase64(filePath2); String jsonInputString = String.format( "{\"image_base64_1\":\"%s\",\"image_base64_2\":\"%s\",\"thresh\":0.7}", image1, image2 ); // 发送请求 try(OutputStream os = conn.getOutputStream()) { byte[] input = jsonInputString.getBytes("utf-8"); os.write(input, 0, input.length); } // 获取响应 int responseCode = conn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { try(BufferedReader br = new BufferedReader( new InputStreamReader(conn.getInputStream(), "utf-8"))) { StringBuilder response = new StringBuilder(); String responseLine; while ((responseLine = br.readLine()) != null) { response.append(responseLine.trim()); } System.out.println(response.toString()); } } else { System.out.println("请求失败,状态码: " + responseCode); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { String appKey = "你的APP_KEY"; String appSecret = "你的APP_SECRET"; String filePath1 = "本地图片1路径"; String filePath2 = "本地图片2路径"; demo(appKey, appSecret, filePath1, filePath2); } }
参数 | 参数类型 | 说明 |
---|---|---|
code | int | 错误码 |
msg | string | 错误信息(英文) |
msg_cn | string | 错误信息(中文) |
success | bool | 识别是否成功 |
image_id | string | 图片ID |
request_id | string | 唯一请求ID |
data | data | 具体看下面 |
参数 | 参数类型 | 说明 | 举例 |
---|---|---|---|
score | float | 相似度分数[-1, 1] | 0.92 |
verified | bool | 是否同一个人所写 | True |
错误码 | 说明 |
---|---|
200 | 成功 |
400 | 错误请求,比如参数错误 |
401 | 未经授权 |
403 | 禁止访问 |
500 | 内部错误 |
如何快速验证手写笔迹是否同一人?手写比对API自动提取12维笔迹特征,智能识别代签、代写、伪造行为,接入文档仅需5行代码。应用于银行开户申请书迹比对\在线考试笔迹一致性核验\金融安全防控等,准确率高,快速响应,接入简单。
✍️ 司法鉴定:合同签名真伪验证,遗产文书笔迹比对
🏫 教育考试:中高考答卷笔迹一致性核验,防替考作弊
🏦 金融安全:银行开户申请书迹比对,信贷材料审核
📝 企业流程:OA系统审批签名验证,报销单据核查
支持各种程序和设备接入,包括小程序、APP、采集设备等,灵活适用于不同应用场景。
字迹比对OCR接口能够精准识别笔迹特征。其主要功能包括:
1.高精度识别:经10万+真实笔迹样本训练,准确率达98.7%。
2.多场景应用:支持历史试卷笔迹追踪、作业代写智能识别、银行开户申请书迹比对、教育防作弊系统等。
3.极简集成:提供Python/Java/PHP等SDK,5行代码快速接入。
4.超高精度与性能:识别准确率高,识别速度快,响应及时。
API类型 | 价格说明 |
---|---|
手写比对OCR API | 每次调用消耗一积分 |
如有问题联系右侧“客服” |