批量文档比对接口文档

调用地址:https://doccompare.market.alicloudapi.com/ocrservice/doccompare
请求方式:POST
返回类型:JSON

请求参数(Body):

{
// 比对文档参数
"queryParam": {
"docParamList": [{
// 自定义序号
"id": 0,
//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个
"url": "",
//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个
"img":""
}]
},
// 标准文档参数
"referenceParam": {
"docParamList": [{
// 自定义序号
"id": 0,
//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个
"url": "",
//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个
"img":""
}]
}
}

请求代码示例:

java版

    public static void main(String[] args) {
String url = "https://doccompare.market.alicloudapi.com/ocrservice/doccompare";
String appcode = "你自己的AppCode";
HashMap<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/json; charset=UTF-8");
//如果需要使用本地图片,需要将图片base64码放在img后面,如果使用网络图片,则需要将网络图片url放于url参数后面
String bodys = "{//比对文档参数\"queryParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]},//标准文档参数\"referenceParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]}}";
try {
/**
* 重要提示如下:
* HttpClientUtils请从
* https://gitee.com/duguangdemo/publicclouddemo/blob/master/src/main/java/util/HttpClientUtils.java
* 下载
* HttpExecuteResponse请从
* https://gitee.com/duguangdemo/publicclouddemo/blob/master/src/main/java/util/HttpExecuteResponse.java
* 下载
*
* 相应的依赖请参照
* https://gitee.com/duguangdemo/publicclouddemo/blob/master/pom.xml
*/
HttpExecuteResponse response = HttpClientUtils.doPost(url,bodys, headers);
System.out.println(response.getResponseAsString());
System.out.println(response.toString());
// 需要检查response的headers信息时可用以下代码,方便排查问题用
// for (Object json : response.getHeaders()) {
// System.out.println(json);
// }

} catch (Exception e) {
e.printStackTrace();
}
}

c#版

//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;


private const String host = "https://doccompare.market.alicloudapi.com";
private const String path = "/ocrservice/doccompare";
private const String method = "POST";
private const String appcode = "你自己的AppCode";

static void Main(string[] args)
{
String querys = "";
String bodys = "{//比对文档参数\"queryParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]},//标准文档参数\"referenceParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]}}";
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;

if (0 < querys.Length)
{
url = url + "?" + querys;
}

if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
httpRequest.ContentType = "application/json; charset=UTF-8";
if (0 < bodys.Length)
{
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}

Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");

}

public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}

PHP版:

<?php
$host = "https://doccompare.market.alicloudapi.com";
$path = "/ocrservice/doccompare";
$method = "POST";
$appcode = "你自己的AppCode";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//根据API的要求,定义相对应的Content-Type
array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
$querys = "";
$bodys = "{//比对文档参数\"queryParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]},//标准文档参数\"referenceParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]}}";
$url = $host . $path;

$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);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
var_dump(curl_exec($curl));
?>

Python2:

import urllib, urllib2, sys
import ssl


host = 'https://doccompare.market.alicloudapi.com'
path = '/ocrservice/doccompare'
method = 'POST'
appcode = '你自己的AppCode'
querys = ''
bodys = {}
url = host + path

bodys[''] = "{//比对文档参数\"queryParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]},//标准文档参数\"referenceParam\":{\"docParamList\":[{//自定义序号\"id\":0,//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\"}]}}"
post_data = bodys['']
request = urllib2.Request(url, post_data)
request.add_header('Authorization', 'APPCODE ' + appcode)

request.add_header('Content-Type', 'application/json; charset=UTF-8')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(request, context=ctx)
content = response.read()
if (content):
print(content)

Python3:

import urllib.request
import urllib.parse
import json
import time
import base64
with open('1.jpg', 'rb') as f: # 以二进制读取本地图片
data = f.read()
encodestr = str(base64.b64encode(data),'utf-8')
#请求头
# 请修改为你自己的appcode,可从云市场订单或者api网关处获得
AppCode = "你自己的AppCode"
headers = {
'Authorization': 'APPCODE ' + AppCode,
'Content-Type': 'application/json; charset=UTF-8'
}

def posturl(url,data={}):
try:
params=json.dumps(dict).encode(encoding='UTF8')
req = urllib.request.Request(url, params, headers)
r = urllib.request.urlopen(req)
html =r.read()
r.close();
return html.decode("utf8")
except urllib.error.HTTPError as e:
print(e.code)
print(e.read().decode("utf8"))
time.sleep(1)
if __name__=="__main__":
url_request="https://doccompare.market.alicloudapi.com/ocrservice/doccompare"
dict = {"queryParam":{"docParamList":[{"id":0,"url":"","img":""}]},"referenceParam":{"docParamList":[{"id":0,"url":"","img":""}

html = posturl(url_request, data=dict)
print(html)

正常返回示例:

{
"doc": {
"match_list": [
{
"ajust_info": {
// 矫正图片base64
"base64": "",
"matrix": [
1.000000,
0.000000,
0.000000,
0.000000,
1.000000,
0.000000,
0.000000,
0,
1
],
// 图片是否需要矫正
"need_ajust": true
},
"match_detail": [
{
//类型为修改
"type": "modify",
"tci_detail": [
{
"word": "3.4非暴利承诺条款:乙方和丙方保证向甲方提供的产品利润不超过20%,否则视为存在暴利。如果乙方",
// 字块坐标信息
"pos": [
{
"x": 29,
"y": 182
},
{
"x": 595,
"y": 184
},
{
"x": 595,
"y": 198
},
{
"x": 29,
"y": 196
}
],
// 标准文档
"type": "reference"
},
{
"word": "3.4非暴利承诺条款:乙方和丙方保证向甲方提供的产品利润不超过10%否则视为存在暴利。如果乙方",
"pos": [
{
"x": 29,
"y": 183
},
{
"x": 595,
"y": 183
},
{
"x": 595,
"y": 197
},
{
"x": 29,
"y": 197
}
],
// 对比文档
"type": "query"
}
],
//单字信息
"char_list": [
{
//类型为删除
"type": "delete",
// 标准文档单字信息
"reference_charInfo": {
// 单字高度
"h": 11,
// 单字宽度
"w": 2,
// 单字x坐标
"x": 422,
// 单字y坐标
"y": 184,
// 单字内容
"word": ","
},
// 对比文档单字信息
"query_charInfo": {
"h": 2018482020,
"w": 32630,
"x": 0,
"y": 2018481728,
"word": ""
}
},
{
//类型为修改
"type": "modify",
"reference_charInfo": {
"h": 11,
"w": 4,
"x": 401,
"y": 184,
"word": "2"
},
"query_charInfo": {
"h": 11,
"w": 0,
"x": 405,
"y": 183,
"word": "1"
}
}
]
},
{
"type": "modify",
"tci_detail": [
{
"word": "和丙方提供给甲方的产品利润超过20%,乙方和丙方同意按照该产品的10倍价格向甲方支付违约金。",
"pos": [
{
"x": 30,
"y": 206
},
{
"x": 570,
"y": 208
},
{
"x": 570,
"y": 221
},
{
"x": 30,
"y": 219
}
],
"type": "reference"
},
{
"word": "和丙方提供给甲方的产品利润超过20%,乙方和丙方同意按照该产品的5倍价格向甲方支付违约金。",
"pos": [
{
"x": 30,
"y": 206
},
{
"x": 570,
"y": 208
},
{
"x": 570,
"y": 221
},
{
"x": 30,
"y": 219
}
],
"type": "query"
}
],
"char_list": [
{
"type": "modify",
"reference_charInfo": {
"h": 11,
"w": 6,
"x": 417,
"y": 208,
"word": "0"
},
"query_charInfo": {
"h": 11,
"w": 6,
"x": 415,
"y": 208,
"word": "5"
}
},
{
"type": "delete",
"reference_charInfo": {
"h": 11,
"w": 0,
"x": 415,
"y": 208,
"word": "1"
},
"query_charInfo": {
"h": 11,
"w": 6,
"x": 415,
"y": 208,
"word": ""
}
}
]
},
{
"type": "delete",
"tci_detail": [
{
"word": "时应该满足甲方的技术标准和质量要求。",
"pos": [
{
"x": 29,
"y": 300
},
{
"x": 248,
"y": 300
},
{
"x": 248,
"y": 313
},
{
"x": 29,
"y": 313
}
],
"type": "reference"
},
{
"word": "",
"pos": [
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"type": "query"
}
],
"char_list": []
},
{
"type": "delete",
"tci_detail": [
{
"word": "同订单交货。货物送到甲方指定的地点进行外观、数量、品种、质量验收。",
"pos": [
{
"x": 30,
"y": 371
},
{
"x": 431,
"y": 371
},
{
"x": 431,
"y": 384
},
{
"x": 30,
"y": 384
}
],
"type": "reference"
},
{
"word": "",
"pos": [
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"type": "query"
}
],
"char_list": []
},
{
"type": "modify",
"tci_detail": [
{
"word": "―原因,需要调整非标品及甲方定制品的,对于价格需要三方另行协商。",
"pos": [
{
"x": 28,
"y": 487
},
{
"x": 407,
"y": 487
},
{
"x": 407,
"y": 501
},
{
"x": 28,
"y": 501
}
],
"type": "reference"
},
{
"word": "原因,需要调整非标品及甲方定制品的,对于价格需要三方另行协商。",
"pos": [
{
"x": 28,
"y": 487
},
{
"x": 407,
"y": 487
},
{
"x": 407,
"y": 501
},
{
"x": 28,
"y": 501
}
],
"type": "query"
}
],
"char_list": [
{
"type": "delete",
"reference_charInfo": {
"h": 12,
"w": 1,
"x": 29,
"y": 487,
"word": "―"
},
"query_charInfo": {
"h": 11,
"w": 6,
"x": 415,
"y": 208,
"word": ""
}
}
]
},
{
"type": "add",
"tci_detail": [
{
"word": "",
"pos": [
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"type": "reference"
},
{
"word": "时应该满足甲方的技术标准和质量要求。若不达到要求,甲方有权全额退款",
"pos": [
{
"x": 29,
"y": 300
},
{
"x": 452,
"y": 300
},
{
"x": 452,
"y": 314
},
{
"x": 29,
"y": 314
}
],
"type": "query"
}
],
"char_list": []
},
{
"type": "add",
"tci_detail": [
{
"word": "",
"pos": [
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"type": "reference"
},
{
"word": "同订单交货。",
"pos": [
{
"x": 30,
"y": 371
},
{
"x": 101,
"y": 371
},
{
"x": 101,
"y": 383
},
{
"x": 30,
"y": 383
}
],
"type": "query"
}
],
"char_list": []
}
],
// 比对文档自定义id
"query_id": 0,
// 标准文档自定义id
"refer_id": 0
}
]
}
}

失败返回示例:

{
"error_code": 400,
"error_msg": "img和url参数不能同时存在"
}

错误码定义:

错误码错误信息描述
400参数错误具体错误请参考返回的error_msg
401您无该功能的权限,请开通后使用您无该功能的权限,请开通后使用
403购买的容量已用完或者签名错误购买的容量已用完或者签名错误
500服务器错误,请稍后重试服务器错误,请稍后重试