PHP code example of overtrue / laravel-qcs

1. Go to this page and download the library: Download overtrue/laravel-qcs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

overtrue / laravel-qcs example snippets


    //...
    // 文字识别服务
    'tms' => [
        'secret_id' => env('TMS_SECRET_ID'),
        'secret_key' => env('TMS_SECRET_KEY'),
        'endpoint' => env('TMS_ENDPOINT'),
        
        // 可选,默认使用腾讯云默认策略
        'biz_type' => env('TMS_BIZ_TYPE'), 
        // 可选,开启后跳过 tms 识别/打码功能
        'dry' => env('TMS_DRY', false),
    ],
    
    // 图片审核/识别服务
    'ims' => [
        'secret_id' => env('IMS_SECRET_ID'),
        'secret_key' => env('IMS_SECRET_KEY'),
        'endpoint' => env('IMS_ENDPOINT'),
        
        // 可选,默认使用腾讯云默认策略
        'biz_type' => env('IMS_BIZ_TYPE'),
        // 可选,开启后跳过 ims 识别功能
        'dry' => env('IMS_DRY', false),
    ],

use Overtrue\LaravelQcloudContentAudit\Tms;

array Tms::check(string $input);

use Overtrue\LaravelQcloudContentAudit\Ims;

array Ims::check(string $contents);

use Overtrue\LaravelQcloudContentAudit\Tms;
use Overtrue\LaravelQcloudContentAudit\Ims;

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

use Overtrue\LaravelQcloudContentAudit\Tms;

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

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

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

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

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

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

$this->validate($request, [
	'name' => 'ription' => '

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

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