Laravel Qcloud Content Security T-Sec 腾讯云内容安全(文字图片内容审核)服务

Related tags

Imagery laravel-qcs
Overview

Laravel Qcloud Content Security

CI Latest Stable Version Latest Unstable Version Total Downloads License

T-Sec 天御内容安全服务使用了深度学习技术,识别文本/图片中出现的可能令人反感、不安全或不适宜内容,支持用户配置词库/图片黑名单,识别自定义的识别类型。

Installing

$ composer require overtrue/laravel-qcs -vvv

Config

请在 config/services.php 中配置以下内容:

    //...
    // 文字识别服务
    'tms' => [
        'secret_id' => env('TMS_SECRET_ID'),
        'secret_key' => env('TMS_SECRET_KEY'),
        'endpoint' => env('TMS_ENDPOINT'),
    ],
    
    // 图片审核/识别服务
    'ims' => [
        'secret_id' => env('IMS_SECRET_ID'),
        'secret_key' => env('IMS_SECRET_KEY'),
        'endpoint' => env('IMS_ENDPOINT'),
    ],

API

获取检查结果

调用对应 API 返回数组结果,返回值结构请参考官方 API 文档。

文本

接口请求频率限制:1000次/秒。

use Overtrue\LaravelQcs\Tms;

array Tms::check(string $input);

图片

  • 接口请求频率限制:100次/秒。
  • 图片检测接口为图片文件内容,大小不能超过5M
  • 图片将会缩放成 300*300 后检查
use Overtrue\LaravelQcs\Ims;

array Ims::check(string $contents);

💡 $contents 可以为:图片内容、图片本地路径或 URL。

检查并返回是否通过

use Overtrue\LaravelQcs\Tms;
use Overtrue\LaravelQcs\Ims;

bool Tms::validate(string $contents, string $strategy = 'strict')
bool Ims::validate(string $contents, string $strategy = 'strict')

直接替换敏感文本内容

直接将检测到的敏感词替换为 *

use Overtrue\LaravelQcs\Tms;

string Tms::mask(string $input, string $char = '*', string $strategy = 'strict');

// 示例:
echo Tms::mask('这是敏感内容哦'); 
// "这是**哦"

在模型中使用

文本校验(CheckTextWithTms)

use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelQcs\Traits\CheckTextWithTms;

class Post extends Model 
{
    // 文本校验
    use CheckTextWithTms;
    
    protected array $tmsCheckable = ['name', 'description'];
    protected string $tmsCheckStrategy = 'strict'; // 可选,默认使用最严格模式
    
    //...
}

文本打码(MaskTextWithTms)

检测到敏感内容时不抛出异常,而是替换为 * 号。

use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelQcs\Traits\MaskTextWithTms;

class Post extends Model 
{
    use MaskTextWithTms;
    
    protected $tmsMaskable = ['name', 'description'];
    protected $tmsMaskStrategy = 'review'; // 开启打码的策略情况,可选,默认使用最严格模式
    
    //...
}

使用表单校验规则

$this->validate($request, [
	'name' => 'required|tms',
	'avatar' => 'required|url|ims',
	'description' => 'required|tms:strict',
	'logo_url' => 'required|url|ims:logo',
]);

配置策略

你可以通过以下方式注册一个或多个自定义校验规则,决定是否通过校验:

// 文字
Tms::setStrategy('strict', function($result) {
	return $result['Suggestion'] === 'Pass';
});

// 图片
Ims::setStrategy('logo', function($result) {
	return $result['Suggestion'] === 'Pass';
});

Events

Event Description
Overtrue\LaravelQcs\Events\ModelAttributeTextMasked 模型属性值打码后触发. 可获取 $model$attribute

异常处理

验证失败将抛出以下异常:

  • Overtrue\LaravelQcs\InvalidTextException
    • $contents - (string) 被检测的文本内容
    • $response - (array) API 原始返回值
  • Overtrue\LaravelQcs\InvalidImageException
    • $response - (array) API 原始返回值

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

You might also like...
This is an image manipulation REST API written in PHP Laravel Framework

Laravel Image Manipulation REST API Demo Here is fully working Demo: https://www.lobiimages.com/ You have to register first in order to generate acces

A Laravel Gravatar package for retrieving gravatar image URLs or checking the existance of an image.

Gravatar for Laravel 5.x, 6, 7 and 8 Installation First, pull in the package through Composer via the command line: composer require creativeorange/gr

Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing

Laravel ZATCA E-invoicing Introduction Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing Installation To get the la

🤹‍♀️Very simple to use Gravatar implementation for Laravel
🤹‍♀️Very simple to use Gravatar implementation for Laravel

Very simple to use Gravatar implementation for Laravel. Install, Include the Facade and then generate, simple! Installation You can install the packag

QCloud COS FederationToken generator for Laravel.

Laravel 腾讯云联合身份临时访问凭证生成器 Laravel 腾讯云联合身份临时访问凭证 生成器,主要用于下发腾讯云联合身份临时访问凭证,比如前端直传等场景。 开始之前,请您仔细阅读并理解一下官方文档: 获取联合身份临时访问凭证 COS API 授权策略使用指引 条件键说明及使用示例 CAM 策

Laravel Security was created by, and is maintained by Graham Campbell, and is a voku/anti-xss wrapper for Laravel, using graham-campbell/security-core
Laravel Security was created by, and is maintained by Graham Campbell, and is a voku/anti-xss wrapper for Laravel, using graham-campbell/security-core

Laravel Security Laravel Security was created by, and is maintained by Graham Campbell, and is a voku/anti-xss wrapper for Laravel, using graham-campb

A multitool library offering access to recommended security related libraries, standardised implementations of security defences, and secure implementations of commonly performed tasks.

SecurityMultiTool A multitool library offering access to recommended security related libraries, standardised implementations of security defences, an

SecLists is the security tester's companion. It's a collection of multiple types of lists used during security assessments, collected in one place. List types include usernames, passwords, URLs, sensitive data patterns, fuzzing payloads, web shells, and many more.
Exploiting and fixing security vulnerabilities of an old version of E-Class. Project implemented as part of the class YS13 Cyber-Security.

Open eClass 2.3 Development of XSS, CSRF, SQLi, RFI attacks/defences of an older,vulnerable version of eclass. Project implemented as part of the clas

phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in PHP code

phpcs-security-audit v3 About phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in

phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in PHP code

phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in PHP code.

SecLists is the security tester's companion. It's a collection of multiple types of lists used during security assessments
SecLists is the security tester's companion. It's a collection of multiple types of lists used during security assessments

SecLists is the security tester's companion. It's a collection of multiple types of lists used during security assessments, collected in one place. List types include usernames, passwords, URLs, sensitive data patterns, fuzzing payloads, web shells, and many more. The goal is to enable a security tester to pull this repository onto a new testing box and have access to every type of list that may be needed.

A multitool library offering access to recommended security related libraries, standardised implementations of security defences, and secure implementations of commonly performed tasks.

SecurityMultiTool A multitool library offering access to recommended security related libraries, standardised implementations of security defences, an

The Security component provides a complete security system for your web application.

Security Component The Security component provides a complete security system for your web application. It ships with facilities for authenticating us

Collection of scripts, thoughts about CSP (Content Security Policy)

CSP useful, a collection of scripts, thoughts about CSP I'm testing and using CSP (Content Security Policy), and here are some thoughts, resources, sc

Best FlexForm based content elements since 2012. With TCA mapping feature, simple backend view and much more features which makes it super easy to create own content element types.
Best FlexForm based content elements since 2012. With TCA mapping feature, simple backend view and much more features which makes it super easy to create own content element types.

DCE-Extension for TYPO3 What is DCE? DCE is an extension for TYPO3 CMS, which creates easily and fast dynamic content elements. Based on Extbase, Flui

A Concrete CMS package to add interfaces to translate multilingual content. You can translate content manually, or use cloud API.

Concrete CMS add-on: Macareux Content Translator Concrete CMS has powerful features to manage multilingual content by its default. You can add languag

Laravel Security Notifications

This package adds security notifications to warn your users when significant security events occur so that they aren't the next victim of an attacker.

Releases(3.4.0)
  • 3.4.0(Jun 10, 2022)

  • 3.3.0(Jun 10, 2022)

    What's Changed

    • feat: 增加 BizType 参数 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/8
    • feat: 增加切片功能 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/9

    Full Changelog: https://github.com/overtrue/laravel-qcloud-content-audit/compare/3.2.1...3.3.0

    Source code(tar.gz)
    Source code(zip)
  • 3.2.1(Jun 9, 2022)

    What's Changed

    • fix: 增加字符串长度预判断 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/7

    Full Changelog: https://github.com/overtrue/laravel-qcloud-content-audit/compare/3.2.0...3.2.1

    Source code(tar.gz)
    Source code(zip)
  • 3.2.0(Jun 9, 2022)

    What's Changed

    • refactor: mask 方法返回对应长度的替换值 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/5
    • feat: 兼容数组类型变量 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/6

    Full Changelog: https://github.com/overtrue/laravel-qcloud-content-audit/compare/3.1.0...3.2.0

    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Jun 9, 2022)

    What's Changed

    • feat: 增加 fake 方法 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/4
    • fix: 增加字符串类型预判断 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/3

    Full Changelog: https://github.com/overtrue/laravel-qcloud-content-audit/compare/3.0.2...3.1.0

    Source code(tar.gz)
    Source code(zip)
  • 3.0.2(Jun 9, 2022)

    What's Changed

    • refactor: 减少重复校验 by @ranpro in https://github.com/overtrue/laravel-qcloud-content-audit/pull/2

    New Contributors

    • @ranpro made their first contribution in https://github.com/overtrue/laravel-qcloud-content-audit/pull/2

    Full Changelog: https://github.com/overtrue/laravel-qcloud-content-audit/compare/3.0.1...3.0.2

    Source code(tar.gz)
    Source code(zip)
  • 3.0.1(Jun 8, 2022)

  • 3.0.0(Jun 8, 2022)

    改名laravel-qcslaravel-qcloud-content-audit

    Full Changelog: https://github.com/overtrue/laravel-qcloud-content-audit/compare/2.0.0...3.0.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Jun 8, 2021)

  • 1.0.1(Jun 8, 2021)

Owner
安正超
Keep calm and coding.
安正超
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

QCode.in 708 Dec 22, 2022
Laragram is a simple instagram "clone" built with Laravel and Tailwind CSS

Laragram is a simple instagram "clone" built with Laravel and Tailwind CSS that gives to the users the ability to create or edit their own profiles (including profile image and description), upload images and share them among friends

null 0 Jul 24, 2021
An open source image hosting service powered by Laravel

Limg An open source image hosting service powered by Laravel Features Upload your image via file, url or ShareX ! Manage your image (custom title, pub

Thomas 56 Dec 16, 2022
An easy-to-use PHP QrCode generator with first-party support for Laravel.

An easy-to-use PHP QrCode generator with first-party support for Laravel.

Simple Software LLC 2.2k Jan 5, 2023
get nearby location by coordinate from eloquent laravel

LARAVEL-COORDINATE get nearby location data from database with eloquent laravel Installation composer require bagusindrayana/laravel-coordinate In M

Bagus Indrayana 26 Sep 9, 2022
Optimize your images on the fly with Glide for Laravel.

Glide for Laravel Optimize your images on the fly with Glide for Laravel. Support us Like our work? You can support us by purchasing one of our produc

Flowframe 53 Oct 17, 2022
Laravel Package for making thumbnails instantly

Laravel Thumbnail Generator Package for uploading the image and saving that image along with it's thumbnail. What does it do ? Uploads Image Make its

DRH2SO4 50 Dec 5, 2022
Laravel Optical Character Reader(OCR) package using ocr engines like Tesseract

LaraOCR Laravel Optical Character Reader(OCR) package using ocr engines like Tesseract under the hood. Features Read text from image using WebUI/Progr

Al Imran Ahmed 100 Jan 4, 2023
Laravel Favicon - Create dynamic favicons based on your environment settings.

Laravel Favicon Create dynamic favicons based on your environment settings. Laravel Package Development If you want to learn how to create reusable PH

Beyond Code 320 Dec 12, 2022
Picasso is a Laravel Image Management and Optimization Package

Picasso is a Laravel Image Management and Optimization Package. Define image dimensions and options, store uploaded image in multiple dimensions with or without a watermark and retrieve optimized images on your website when needed.

Laravelista 82 Nov 24, 2022