-
Notifications
You must be signed in to change notification settings - Fork 11
/
ImageCheckV5ApiDemo.cs
217 lines (209 loc) · 21.2 KB
/
ImageCheckV5ApiDemo.cs
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
namespace Com.Netease.Is.Antispam.Demo
{
class ImageCheckV5ApiDemo
{
public static void imageCheck()
{
/** 产品密钥ID,产品标识 */
String secretId = "your_secret_id";
/** 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露 */
String secretKey = "your_secret_key";
/** 业务ID,易盾根据产品业务特点分配 */
String businessId = "your_business_id";
/** 易盾反垃圾云服务图片在线检测接口地址 */
String apiUrl = "http://as.dun.163.com/v5/image/check";
Dictionary<String, String> parameters = new Dictionary<String, String>();
long curr = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
String time = curr.ToString();
// 1.设置公共参数
parameters.Add("secretId", secretId);
parameters.Add("businessId", businessId);
parameters.Add("version", "v5");
parameters.Add("timestamp", time);
parameters.Add("nonce", new Random().Next().ToString());
// 2.设置私有参数
JArray jarray = new JArray();
JObject image1 = new JObject();
image1.Add("name", "https://nos.netease.com/yidun/2-0-0-a6133509763d4d6eac881a58f1791976.jpg");
image1.Add("type", 1);
image1.Add("data", "https://nos.netease.com/yidun/2-0-0-a6133509763d4d6eac881a58f1791976.jpg");
jarray.Add(image1);
JObject image2 = new JObject();
image2.Add("name", "{\"imageId\": 33451123, \"contentId\": 78978}");
image2.Add("type", 2);
image2.Add("data", "iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAYNElEQVR4nO2dP3vivNKHnfc6FWmhZVvTAk9JvkPSLikfsvUpSZ18hpAtl7TJdyBlYFvThpa0UK7fwtf6OP4zM/ZIlk1+d5HLOytpRsbjGVmyfBaGoQcAcMf/uTYAgK8OnBAAx8AJAXAMnBAAx8AJAXAMnBAAx8AJAXAMnBAAx8AJAXBNSOLauvpYLBb0qWBZr9c12Pnw8FCDnUoVEhaLRQ2nqyHQpwKREADHwAkBcAycUErYkuS8LXaCGDghAI6BE0o5OztzbYKIttgJYuCEUtqS5rXFThADJwTAMXBCABwDJwTAMXBCKW154NEWO0HMf5T1f/365fu+EVOscn19vd1urarwff/t7U3ZCGvn/f39z58/NSoOh4OmesR0OqXtnM/nV1dXGhW+7//69UvTQj1st9vr62tNC1on9H1/NBpFd98wDM/OzpJ/ozL653VRgxrh+fk5qyW2PLdNNsKcn5+Px2NWC02n06EL7Ha73W6n1KInCILfv38TBT4+PpQqOp2O/nzWgD710Dqhl7juUx4YX81Jb0y6aylhblflQmFHNG1KHBWALBgTAuAYA5EwFbXodDQ+LiXUp6PyjlRORxEGQTWQjqYrIh0FNYNImO4IIiGoGUTCdEVEQlAziITpjiASgppBJExXRCQENYMpCgAcYyAS0jw9Pb2+vtrW0oStu3a73f39vb4RusD3798nk4lShd7O29vb/X5PFFAaKeTm5sa2islkMp1O7erI3YMthq3+9vb258+fqHB0kPwbhuFsNrPbAc/zPO/PXyLVKcIwHI1GdAuLxYKoHneHAFseloK9bw6HQ7YRQyeVYjab0TbozyfSUQAcA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7gS2OtzNpvZthPpKACOgRMC4JhTc0LnUxSS9jVTFOHf0QgxnaBHaCdBWGk6IVdoVZEcpZ0Ep+aEuSel2i+aEgqnKCTt51ZP/cZFJSMziqobuSbkdhJUm06wOsegnHhQ2klwak4IQOs4NSdEOiq0xIidBEhH5ZyaEyIdFVpixE4CpKNyTs0JAWgdcEIAHGN92dpkMomPw7yVStn/ZUsS2BsTBkHw+vpK1H1/fxe2nzuKI7Kd5N/VakVvH0Yb6Xlet9ul9xeT20mQyq6zv2Z8Pot+d3pZXMTj4yN92VxeXna73az2+Dh5feYSFyhSxBrJE5Kw1dlla0mS67+I/w0zK8XY8qxQv2ytnuVgyV7nltQvAxwOh0Xa5UL9srV4ZalV1us1bYYeLFsDoPXU6oR0SlOUjxXNASiFtIXVqgvb10xRGLeENcn2FIVtaO0GhZWp1Qlp04s6GUGXryCkLaxWXdh+yD36TwlTJc1awppE2ElgY5KgGsoJElNTKQRIRwFwDJwQAMdgTGiyurB9jAk9o0m+0BKMCT0PY0KMCTEmzAPpKACOQTpqsrqwfaSjntH8QmhJY9NR7bK17XZbW16h4XA4SIqF3Ho6JZvNRtnCfr83YkmYeCHj7O8bUnIh274+eet0Or7vl+pUFnYtYb/fjz+lWC1IKC309E54fX2tN+LroPzI7inBXr6+7+vvWaPRiP6m6mKxoFcC1hBjMCYEwDFwwk/YHhM2hxaNCa0O1ZowJoQTfsL2FEVzaNEUhdWZA0xRAADghJ9BOioUsiAdlQMn/ATSUaGQBemoHDghAI6BEwLgGDjhJzAmFApZMCaUAyf8BMaEQiELxoRyzk7yCgOgRSASAuAYOCEAjoETAuAYOCEAjoETAuAYOCEAjoETAuAYOCEAjoETAuCY/wc8SC3r28PmnQAAAABJRU5ErkJggg==");
jarray.Add(image2);
parameters.Add("images", jarray.ToString());
// parameters.Add("account", "csharp@163.com");
// parameters.Add("ip", "123.115.77.137");
// 3.生成签名信息,指定国密SM3加密
// parameters.Add("signatureMethod", "SM3");
String signature = Utils.genSignature(secretKey, parameters.GetValueOrDefault("signatureMethod", "MD5"), parameters);
parameters.Add("signature", signature);
// 4.发送HTTP请求
HttpClient client = Utils.makeHttpClient();
String result = Utils.doPost(client, apiUrl, parameters, 10000);
if(result != null)
{
JObject ret = JObject.Parse(result);
int code = ret.GetValue("code").ToObject<Int32>();
String msg = ret.GetValue("msg").ToObject<String>();
if (code == 200)
{
JArray resultArray = (JArray)ret.SelectToken("result");
foreach (var item in resultArray)
{
JObject tmp = (JObject)item;
JObject antispam = tmp.GetValue("antispam").ToObject<JObject>();
String name = antispam.GetValue("name").ToObject<String>();
int status = antispam.GetValue("status").ToObject<Int32>();
String taskId = antispam.GetValue("taskId").ToObject<String>();
if(status == 2){
int suggestion = antispam.GetValue("suggestion").ToObject<Int32>();
JArray labels = (JArray)antispam.SelectToken("labels");
Console.WriteLine(String.Format("taskId={0},status={1},name={2},suggestion={3}", taskId, status, name, suggestion));
// 产品需根据自身需求,自行解析处理,本示例只是简单判断分类级别
foreach (var lable in labels)
{
JObject lableData = (JObject)lable;
int label = lableData.GetValue("label").ToObject<Int32>();
int level = lableData.GetValue("level").ToObject<Int32>();
double rate = lableData.GetValue("rate").ToObject<Double>();
// 返回二级分类信息,根据需要解析
JArray subLabels = (JArray)lableData.SelectToken("subLabels");
Console.WriteLine(String.Format("label:{0}, level={1}, rate={2}, subLabels={3}", label, level, rate, subLabels));
}
switch (suggestion) {
case 0:
Console.WriteLine("#图片机器检测结果:最高等级为\"正常\"\n");
break;
case 1:
Console.WriteLine("#图片机器检测结果:最高等级为\"嫌疑\"\n");
break;
case 2:
Console.WriteLine("#图片机器检测结果:最高等级为\"确定\"\n");
break;
default:
break;
}
}else {
Console.WriteLine(String.Format("图片检测失败,taskId={0},status={1},name={2}", taskId, status, name));
}
// ocr结果
if(null!=tmp.GetValue("ocr")){
JObject ocr = tmp.GetValue("ocr").ToObject<JObject>();
JArray ocrDetails = (JArray)ocr.SelectToken("details");
foreach (var ocrDetail in ocrDetails)
{
JObject lObject = (JObject)ocrDetail;
String content = lObject.GetValue("content").ToObject<String>();
JArray lineContents = (JArray)lObject.SelectToken("lineContents");
Console.WriteLine(String.Format("识别ocr文本内容:{0}, ocr片段及坐标信息:{1}", content, lineContents));
}
}
// 人脸信息
if(null!=tmp.GetValue("face")){
JObject face = tmp.GetValue("face").ToObject<JObject>();
JArray faceDetails = (JArray)face.SelectToken("details");
foreach (var faceDetail in faceDetails)
{
JObject lObject = (JObject)faceDetail;
String faceNumber = lObject.GetValue("faceNumber").ToObject<String>();
JArray faceContents = (JArray)lObject.SelectToken("faceContents");
Console.WriteLine(String.Format("识别人脸数量:{0}, 人物信息及坐标信息:{1}", faceNumber, faceContents));
}
}
// 图片质量检测结果
if(null!=tmp.GetValue("quality")){
JObject quality = tmp.GetValue("quality").ToObject<JObject>();
JArray qualityDetails = (JArray)quality.SelectToken("details");
foreach (var qualityDetail in qualityDetails)
{
JObject lObject = (JObject)qualityDetail;
float aestheticsRate = lObject.GetValue("aestheticsRate").ToObject<float>();
float sharpnessRate = lObject.GetValue("sharpnessRate").ToObject<float>();
JObject metaInfo = lObject.GetValue("metaInfo").ToObject<JObject>();
JObject boarderInfo = lObject.GetValue("boarderInfo").ToObject<JObject>();
JObject backgroundInfo = lObject.GetValue("backgroundInfo").ToObject<JObject>();
Console.WriteLine(String.Format("图片美观度分数:{0}, 图片清晰度分数:{1}, 图片基本信息:{2}, 图片边框信息:{3}, 图片背景信息:{4}", aestheticsRate, sharpnessRate, metaInfo, boarderInfo, backgroundInfo));
}
}
// 图片logo结果
if(null!=tmp.GetValue("logo")){
JObject logo = tmp.GetValue("logo").ToObject<JObject>();
JArray logoDetails = (JArray)logo.SelectToken("details");
foreach (var logoDetail in logoDetails)
{
JObject lObject = (JObject)logoDetail;
String logoName = lObject.GetValue("logoName").ToObject<String>();
float x1 = lObject.GetValue("x1").ToObject<float>();
float y1 = lObject.GetValue("y1").ToObject<float>();
float x2 = lObject.GetValue("x2").ToObject<float>();
float y2 = lObject.GetValue("y2").ToObject<float>();
Console.WriteLine(String.Format("logo信息:{0}, 左上角点x坐标:{1}, 左上角点y坐标:{2}, 右下角点x坐标:{3}, 右下角点y坐标:{4}", logoName, x1, y1, x2, y2));
}
}
// 图片识别结果
if(null!=tmp.GetValue("discern")){
JObject discern = tmp.GetValue("discern").ToObject<JObject>();
JArray discernDetails = (JArray)discern.SelectToken("details");
foreach (var discernDetail in discernDetails)
{
JObject lObject = (JObject)discernDetail;
int type = lObject.GetValue("type").ToObject<int>();
String discernName = lObject.GetValue("discernName").ToObject<String>();
float rate = lObject.GetValue("rate").ToObject<float>();
switch (type) {
case 1:
Console.WriteLine(String.Format("识别物体类型:场景识别, 识别名称:%s, 分数:%s", discern, rate));
break;
case 2:
Console.WriteLine(String.Format("识别物体类型:地标识别, 识别名称:%s, 分数:%s", discern, rate));
break;
case 3:
Console.WriteLine(String.Format("识别物体类型:百度识图, 识别名称:%s, 分数:%s", discern, rate));
break;
default:
break;
}
}
}
// 用户画像结果
if(null!=tmp.GetValue("userRisk")){
JObject userRisk = tmp.GetValue("userRisk").ToObject<JObject>();
JArray userRiskDetails = (JArray)userRisk.SelectToken("details");
foreach (var userRiskDetail in userRiskDetails)
{
JObject lObject = (JObject)userRiskDetail;
int accountLevel = lObject.GetValue("accountLevel").ToObject<int>();
String account = lObject.GetValue("account").ToObject<String>();
switch (accountLevel) {
case 0:
Console.WriteLine(String.Format("账号:{0}, 用户账号风险级别:正常", account));
break;
case 5:
Console.WriteLine(String.Format("账号:{0}, 用户账号风险级别:嫌疑", account));
break;
case 10:
Console.WriteLine(String.Format("账号:{0}, 用户账号风险级别:致命", account));
break;
default:
break;
}
}
}
}
}
else{
Console.WriteLine(String.Format("ERROR: code={0}, msg={1}", code, msg));
}
}else{
Console.WriteLine("Request failed!");
}
}
}
}