1 Star 0 Fork 0

网易易盾 / antispam-csharp-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DigitalBookQueryV2ApiDemo.cs 3.68 KB
一键复制 编辑 原始数据 按行查看 历史
longfan 提交于 2022-06-01 15:24 . C# demo补充
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
namespace Com.Netease.Is.Antispam.Demo
{
class DigitalBookQueryV2ApiDemo
{
public static void digitalBookQuery()
{
/** 产品密钥ID,产品标识 */
String secretId = "your_secret_id";
/** 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露 */
String secretKey = "your_secret_key";
/** 易盾反垃圾云服务举报解决方案离线结果获取接口地址 */
String apiUrl = "http://as.dun.163.com/v2/digital/callback/query";
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("version", "v2");
parameters.Add("timestamp", time);
parameters.Add("nonce", new Random().Next().ToString());
parameters.Add("taskIds", "['bz29tn9yu944hjzmdg57dg3g05009r28']");
// 2.生成签名信息
String signature = Utils.genSignature(secretKey, parameters);
parameters.Add("signature", signature);
// 3.发送HTTP请求
HttpClient client = Utils.makeHttpClient();
String resultResponse = Utils.doPost(client, apiUrl, parameters, 10000);
if(resultResponse != null)
{
JObject ret = JObject.Parse(resultResponse);
int code = ret.GetValue("code").ToObject<Int32>();
String msg = ret.GetValue("msg").ToObject<String>();
if (code == 200)
{
JArray array = (JArray)ret.SelectToken("result");
if(null == array){
Console.WriteLine("暂时没有结果需要获取,请稍后重试");
}else {
foreach (var item in array)
{
JObject tmp = (JObject)item;
if(null != tmp["antispam"]){
JObject antispam = tmp.GetValue("antispam").ToObject<JObject>();
Console.WriteLine(String.Format("机器检测结果: {0}", antispam));
}
if(null != tmp["valueAddService"]){
JObject valueAddService = tmp.GetValue("valueAddService").ToObject<JObject>();
Console.WriteLine(String.Format("增值服务结果: {0}", valueAddService));
}
if(null != tmp["anticheat"]){
JObject anticheat = tmp.GetValue("anticheat").ToObject<JObject>();
Console.WriteLine(String.Format("反作弊结果: {0}", anticheat));
}
if(null != tmp["censor"]){
JObject censor = tmp.GetValue("censor").ToObject<JObject>();
Console.WriteLine(String.Format("人工审核结果: {0}", censor));
}
}
}
}
else
{
Console.WriteLine(String.Format("ERROR: code={0}, msg={1}", code, msg));
}
}
else
{
Console.WriteLine("Request failed!");
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/netease_yidun/antispam-csharp-demo.git
git@gitee.com:netease_yidun/antispam-csharp-demo.git
netease_yidun
antispam-csharp-demo
antispam-csharp-demo
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891