PHP code example of larva / think-qcs

1. Go to this page and download the library: Download larva/think-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/ */

    

larva / think-qcs example snippets


    //...
    // 文字识别服务
    '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'),
    ],

use Larva\ThinkQcs\Tms;

array Tms::check(string $input);

use Larva\ThinkQcs\Ims;

array Ims::check(string $contents);

use Larva\LaravelQcs\Tms;
use Larva\LaravelQcs\Ims;

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

use Larva\ThinkQcs\Tms;

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

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

use think\Model;
use Larva\ThinkQcs\Traits\CheckTextWithTms;

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

use think\Model;
use Larva\ThinkQcs\Traits\MaskTextWithTms;

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

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

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