/** * 添加敏感词方法(设置敏感词后,App 中用户不会收到含有敏感词的消息内容,默认最多设置 50 个敏感词。) * * @param sensitiveword:敏感词 * @return ResponseResult **/ public async Task <ResponseResult> Add(SensitiveWordModel sensitiveword) { string errMsg = CommonUtil.CheckFiled(sensitiveword, PATH, CheckMethod.ADD); if (null != errMsg) { return(RongJsonUtil.JsonStringToObj <ResponseResult>(errMsg)); } StringBuilder sb = new StringBuilder(); sb.Append("&word=").Append(HttpUtility.UrlEncode(sensitiveword.Keyword, UTF8)); if (0 == sensitiveword.Type) { if (null == sensitiveword.Replace) { return(new ResponseResult(1002, "replace 参数为必传项")); } sb.Append("&replaceWord=").Append(HttpUtility.UrlEncode(sensitiveword.Replace, UTF8)); } string body = sb.ToString(); if (body.IndexOf("&", StringComparison.OrdinalIgnoreCase) == 0) { body = body.Substring(1, body.Length - 1); } string result = await RongHttpClient.ExecutePost(AppKey, AppSecret, body, RongCloud.ApiHostType.Type + "/sensitiveword/add.json", "application/x-www-form-urlencoded"); return(RongJsonUtil.JsonStringToObj <ResponseResult>( CommonUtil.GetResponseByCode(PATH, CheckMethod.ADD, result))); }
static void Main(String[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api 地址方式 // RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); SensitiveWord SensitiveWord = rongCloud.Sensitiveword; /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/sensitive/sensitive.html#add * * 添加替换敏感词方法 * * */ SensitiveWordModel sentiveWord = new SensitiveWordModel() { Type = 0, Keyword = "黄赌黄", Replace = "***" }; ResponseResult addesult = SensitiveWord.Add(sentiveWord); Console.WriteLine("sentiveWord add: " + addesult.ToString()); /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/sensitive/sensitive.html#add * * 添加替换敏感词方法 * * */ sentiveWord = new SensitiveWordModel() { Type = 1, Keyword = "黄赌黄" }; ResponseResult addersult = SensitiveWord.Add(sentiveWord); Console.WriteLine("sentiveWord add replace : " + addersult.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/sensitive/sensitive.html#getList * 查询敏感词列表方法 * * */ ListWordfilterResult result = SensitiveWord.GetList(1); Console.WriteLine("getList: " + result.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/sensitive/sensitive.html#remove * 移除敏感词方法(从敏感词列表中,移除某一敏感词。) * * */ ResponseResult removeesult = SensitiveWord.Remove("黄赌黄"); Console.WriteLine("SensitivewordDelete: " + removeesult.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/sensitive/sensitive.html#remove * 批量移除敏感词方法(从敏感词列表中,批量移除某一敏感词。) * * */ String[] words = { "黄赌毒" }; ResponseResult batchDeleteResult = SensitiveWord.BatchDelete(words); Console.WriteLine("SensitivewordbatchDelete: " + batchDeleteResult.ToString()); Console.ReadLine(); }