Step By Step
云市场的使用大体流程可以参考之前的文档
阿里云市场印刷文字识别_银行卡识别接口的Java调用
1.获取参数
- 图片地址
这边使用了oss存储接口的参数,可以在oss上直接获取下图片的链接
注意读写权限为公共读,要不服务器访问不到
- appcode
购买后,控制台-云市场-即可看到购买的服务
2.java code
工具类请参考云市场使用流程里面的
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.util.HashMap;
import java.util.Map;
public class mixedMultiCommon {
public static void main(String[] args) {
String host = "https://multcommon.market.alicloudapi.com";
String path = "/ocrservice/mixedMultiCommon";
String method = "POST";
String appcode = "appcode";
Map<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");
Map<String, String> querys = new HashMap<String, String>();
String bodys = "{\"img\":\"\",\"url\":\"图片url\"}";
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
*/
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
System.out.println(response.toString());
//获取response的body
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
####3.识别结果
{
"sid": "79bbb7f20d3c5bb02e70b47c071a97b990f0c2e9bb74d00c3e4c09e253e51c777cc27480",
"height": 640,
"width": 479,
"orgHeight": 640,
"orgWidth": 479,
"count": 1,
"subMsgs": [{
"index": 1,
"op": "idcard",
"result": {
"algo_version": "0122410b9bb1f2a16e432e55d491b446b16e1600",
"angle": 0,
"data": {
"签发机关": "衡阳市公安局珠晖分局",
"有效期限": "2016.04.12-2026.04.12"
},
"ftype": 0,
"height": 270,
"orgHeight": 270,
"orgWidth": 453,
"prism_keyValueInfo": [{
"key": "签发机关",
"keyProb": 100,
"value": "衡阳市公安局珠晖分局",
"valuePos": [{
"x": 186,
"y": 183
}, {
"x": 349,
"y": 182
}, {
"x": 349,
"y": 198
}, {
"x": 187,
"y": 200
}],
"valueProb": 100
}, {
"key": "有效期限",
"keyProb": 100,
"value": "2016.04.12-2026.04.12",
"valuePos": [{
"x": 185,
"y": 221
}, {
"x": 362,
"y": 220
}, {
"x": 362,
"y": 233
}, {
"x": 186,
"y": 234
}],
"valueProb": 100
}],
"sliceRect": {
"x0": 36,
"y0": 198,
"x1": 440,
"y1": 196,
"x2": 465,
"y2": 465,
"x3": 13,
"y3": 463
},
"width": 453
},
"sliceRect": {
"x0": 36,
"y0": 198,
"x1": 440,
"y1": 196,
"x2": 465,
"y2": 465,
"x3": 13,
"y3": 463
},
"type": "身份证反面"
}]
}