首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >网站被腾讯安全拦截处理

网站被腾讯安全拦截处理

作者头像
kdyonly
发布2023-03-03 18:13:19
1.9K0
发布2023-03-03 18:13:19
举报
文章被收录于专栏:个人编程笔记个人编程笔记

浏览量 8

近期网站被腾讯安全拦截,微信,QQ也不能打开链接了,必须进行申诉,对网站进行解封,解封之前,我们必须要把可能违规的内容进行处理,处理之后才能解除限制。

如何查找违规内容

我们可以使用云厂商提供的内容安全接口,进行批量的内容检测,这里我使用腾讯云的内容安全进行处理,初次使用,有10000条免费检测条目,超过之后需要收费。

第一步,我们取出网站的所有内容,第二步,调用腾讯内容安全提供的接口,可以使用其提供的SDK,第三步,筛选出违规内容进行处理。这里使用.net构建内容检测程序,参考代码:

//ApiCheckController.cs
using ContentService.Infrastructure;
using Microsoft.AspNetCore.Mvc;
using TencentCloud.Common.Profile;
using TencentCloud.Common;
using TencentCloud.Tms.V20201229;
using TencentCloud.Tms.V20201229.Models;
using ContentService.Domain.Model;
using System.Text;
using System.Buffers.Text;
using TencentCloud.Mrs.V20200910.Models;
using System.Text.Json;
using System.Text.RegularExpressions;

namespace ContentService.WebApi.Controllers
{
    [Route("Api/[controller]/[action]")]
    [ApiController]
    public class ApiCheckController : Controller
    {
        private readonly ContentDbContext _contentDbContext;
        public ApiCheckController(ContentDbContext contentDbContext)
        {
            _contentDbContext = contentDbContext;
        }
        [HttpGet]
        public async Task<IActionResult> CheckContents()
        {
            Credential cred = new Credential
            {
                SecretId = TxConfig.SecretId,
                SecretKey = TxConfig.SecretKey
            };
            // 实例化一个client选项,可选的,没有特殊需求可以跳过
            ClientProfile clientProfile = new ClientProfile();
            // 实例化一个http选项,可选的,没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.Endpoint = ("tms.tencentcloudapi.com");
            clientProfile.HttpProfile = httpProfile;

            // 实例化要请求产品的client对象,clientProfile是可选的
            TmsClient client = new TmsClient(cred, "ap-beijing", clientProfile);
            // 实例化一个请求对象,每个接口都会对应一个request对象
            TextModerationRequest req = new TextModerationRequest();

            List<TextModerationResponse> resps = new List<TextModerationResponse>();
            List<PostModel> posts = _contentDbContext.Posts.Where(x => x.post_type == "post" && x.post_status == "publish").ToList();
            foreach (PostModel post in posts)
            {
                try
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(post.post_content);
                    req.Content = Convert.ToBase64String(bytes);
                    TextModerationResponse resp = client.TextModerationSync(req);
                    Console.WriteLine(AbstractModel.ToJsonString(resp));
                    resps.Add(resp);
                }
                catch (Exception ex)
                {
                    continue;
                }

            }
            return Json(resps);
        }

    }
}
//ContentDbContext.cs
using ContentService.Domain.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ContentService.Infrastructure
{
    public class ContentDbContext : DbContext
    {
        public DbSet<PostModel> Posts { get; set; }
        public DbSet<PostMetaModel> PostsMetas { get; set; }
        public DbSet<TermModel> Terms { get; set; }
        public DbSet<TermTaxonomyModel> TermTaxonomies { get; set; }
        public DbSet<TermRelationships> TermRelationships { get; set; }
        public ContentDbContext(DbContextOptions<ContentDbContext> options) : base(options)
        {

        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<PostModel>().ToTable("wp_posts");
            modelBuilder.Entity<PostMetaModel>().ToTable("wp_postmeta");
            modelBuilder.Entity<TermModel>().ToTable("wp_terms");
            modelBuilder.Entity<TermTaxonomyModel>().ToTable("wp_term_taxonomy");
            modelBuilder.Entity<TermRelationships>().ToTable("wp_term_relationships");
        }
    }
}
//数据库服务注册
//ModuleInitializer.cs
using Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ContentService.Infrastructure
{
    public static class ModuleInitializer
    {
        public static void Initialize(this IServiceCollection services, ConfigurationManager configurationManager)
        {
            //数据库服务
            IConfigurationSection configuration = configurationManager.GetSection("DataBase:ConnectStr");
            var connectStr = configuration.Value;
            services.AddDbContext<ContentDbContext>(oprions => oprions.UseMySql(connectStr, ServerVersion.AutoDetect(connectStr)));
        }
    }
}

统计结果

使用内容安全的默认策略,也可以自己设置,可根据明细查询,筛选违规内容,找到网站对应内容进行删除即可,这里的机器识别个人感觉没有那么智能,不能根据内容语义识别,只能识别词汇,所以处理并不需要全部进行删除处理。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-03-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 如何查找违规内容
  • 统计结果
相关产品与服务
应用安全开发
应用安全开发(Application Security Development,下文中也叫 Xcheck)为您提供优质的代码分析服务。Xcheck 凭借优秀的算法和工程实现,能在极低的误报率和漏报率前提下,以极快的速度发现代码中存在的安全漏洞。Xcheck 采用私有化部署的模式,所以产品使用的整个生命周期,源码都不会流出公司网络,杜绝源码泄露风险。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档