forked from yidun/antispam-nodejs-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageCheckDemo.js
96 lines (95 loc) · 11.4 KB
/
imageCheckDemo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var utils=require("./utils");
//产品密钥ID,产品标识
var secretId="your_secret_id";
// 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
var secretKey="your_secret_key";
// 业务ID,易盾根据产品业务特点分配
var businessId="your_business_id";
// 易盾反垃圾云服务图片在线检测接口地址
var apiurl="https://as.dun.163yun.com/v4/image/check";
//请求参数
var post_data = {
// 1.设置公有有参数
secretId:secretId,
businessId:businessId,
version:"v4",
timestamp:new Date().getTime(),
nonce:utils.noncer()
// 2.1设置私有参数
// account:"[email protected]",
// ip:"123.115.77.137"
};
// 2.2请求图片参数
var images=[{
name:"https://nos.netease.com/yidun/2-0-0-a6133509763d4d6eac881a58f1791976.jpg",
type:1,
data:"https://nos.netease.com/yidun/2-0-0-a6133509763d4d6eac881a58f1791976.jpg"
},{
name:"{\"imageId\": 33451123, \"contentId\": 78978}",
type:2,
data:"iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAYNElEQVR4nO2dP3vivNKHnfc6FWmhZVvTAk9JvkPSLikfsvUpSZ18hpAtl7TJdyBlYFvThpa0UK7fwtf6OP4zM/ZIlk1+d5HLOytpRsbjGVmyfBaGoQcAcMf/uTYAgK8OnBAAx8AJAXAMnBAAx8AJAXAMnBAAx8AJAXAMnBAAx8AJAXBNSOLauvpYLBb0qWBZr9c12Pnw8FCDnUoVEhaLRQ2nqyHQpwKREADHwAkBcAycUErYkuS8LXaCGDghAI6BE0o5Oztz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B9jAk9o0m+0BKMCT0PY0KMCTEmzAPpKACOQTpqsrqwfaSjntH8QmhJY9NR7bK17XZbW16h4XA4SIqF3Ho6JZvNRtnCfr83YkmYeCHj7O8bUnIh274+eet0Or7vl+pUFnYtYb/fjz+lWC1IKC309E54fX2tN+LroPzI7inBXr6+7+vvWaPRiP6m6mKxoFcC1hBjMCYEwDFwwk/YHhM2hxaNCa0O1ZowJoQTfsL2FEVzaNEUhdWZA0xRAADghJ9BOioUsiAdlQMn/ATSUaGQBemoHDghAI6BEwLgGDjhJzAmFApZMCaUAyf8BMaEQiELxoRyzk7yCgOgRSASAuAYOCEAjoETAuAYOCEAjoETAuAYOCEAjoETAuAYOCEAjoETAuCY/wc8SC3r28PmnQAAAABJRU5ErkJggg=="
}];
post_data.images=JSON.stringify(images);
var signature=utils.genSignature(secretKey,post_data);
post_data.signature=signature;
//http请求结果
var responseCallback=function(responseData){
var data = JSON.parse(responseData);
var code=data.code;
var msg=data.msg;
if(code==200){
// 反垃圾检测结果
var antispamArray=data.antispam;
for(var i=0;i<antispamArray.length;i++){
var obj=antispamArray[i];
var name=obj.name;
var taskId=obj.taskId;
var status=obj.status;
var action=obj.action;
var labelsArray=obj.labels;
console.log("taskId="+taskId+",status="+status+",name="+name+",action="+action);
// 产品需根据自身需求,自行解析处理,本示例只是简单判断分类级别
for(var k=0;k<labelsArray.length;k++){
var labelObj=labelsArray[k];
var label=labelObj.label;
var level=labelObj.level;
var rate=labelObj.rate;
// subLabels这二级分类数组,根据需要解析
var subLabels=labelObj.subLabels;
console.log("lable:"+label+",level:"+level+",rate:"+rate);
}
switch (action) {
case 0:
console.log("#图片机器检测结果:最高等级为\"正常\"\n");
break;
case 1:
console.log("#图片机器检测结果:最高等级为\"嫌疑\"\n");
break;
case 2:
console.log("#图片机器检测结果:最高等级为\"确定\"\n");
break;
default:
break;
}
}
// ocr结果
var ocrArray=data.ocr;
for(var i=0;i<ocrArray.length;i++){
var obj=ocrArray[i];
var name=obj.name;
var taskId=obj.taskId;
var detailsArray=obj.details;
console.log("taskId="+taskId+",name="+name);
for(var k=0;k<detailsArray.length;k++){
var detail=detailsArray[k];
var content=detail.content;
// lineContents为ocr片段及坐标信息,根据需要解析
var lineContents=detail.lineContents;
console.log("识别ocr文本内容:"+content);
}
}
}else{
console.log('ERROR:code=' + code+',msg='+msg);
}
}
utils.sendHttpRequest(apiurl,"POST",post_data,responseCallback);