hedeqiang/green

阿里云内容安全 PHP SDK

v1.0.2 2020-09-08 09:24 UTC

This package is auto-updated.

Last update: 2024-09-08 18:13:11 UTC


README

阿里云内容安全 PHP SDK.

请先阅读 阿里云内容安全文档

安装

$ composer require hedeqiang/green -vvv

用法

require __DIR__ .'/vendor/autoload.php';

use Hedeqiang\Green\Green;

$config = [
    'accessKeyId' => '',
    'accessKeySecret' => '',
    //'regionId' => '',
    //timeout => 6
    //'connectTimeout' => 6,
    //debug' => false,
];

$green = new Green($config);

文本内容检测

$green->textScan(['文本1','文本2']); # 支持数组、字符串

文本检测内容反馈

$green->textFeedback($taskId); # 支持数组、字符串

图片同步检测

$green->imageSyncScan($url, $scenes = ['porn', 'terrorism','ad']); # url 支持数组、字符串

图片异步检测

$green->imageAsyncScan($url, $scenes = ['porn', 'terrorism','ad']); # url 支持数组、字符串

图片异步检测结果

$green->imageAsyncScanResults($taskIds);

图片检测结果反馈

$green->imageScanFeedback($taskId);

更多...

在 Laravel 中使用

发布配置文件

php artisan vendor:publish --tag=green
编写 .env 文件
GREEN_ACCESS_KEY_ID=
GREEN_ACCESS_KEY_SECRET=
GREEN_REGION_ID=cn-beijing
GREEN_TIMEOUT=6
GREEN_CONNECT_TIMEOUT=6
GREEN_DEBUG=false

方法参数注入

参数和上面一样

public function index(Green $green)
{
    $response = $green->textScan(['文本1','文本2']); # 支持数组、字符串
}

服务名访问

public function index()
{
    $response = app('green')->textScan(['文本1','文本2']); # 支持数组、字符串
}

Facades 门面使用(可以提示)

use Hedeqiang\Green\Facades\Green;
$response = Green::green()->textScan(['文本1','文本2']);

返回格式示例

{
    "code":200,
    "data":[
        {
            "code":200,
            "content":"文本1",
            "dataId":"5f508a2dec2a6",
            "msg":"OK",
            "results":[
                {
                    "label":"normal",
                    "rate":99.91,
                    "scene":"antispam",
                    "suggestion":"pass"
                }
            ],
            "taskId":"txt5iHPuCGHb024i2AWj92PTK-1t5arO"
        },
        {
            "code":200,
            "content":"文本2",
            "dataId":"5f508a2dec2a8",
            "msg":"OK",
            "results":[
                {
                    "label":"normal",
                    "rate":99.91,
                    "scene":"antispam",
                    "suggestion":"pass"
                }
            ],
            "taskId":"txt1KDW04MfrTP5ijNpdjokAe-1t5arO"
        }
    ],
    "msg":"OK",
    "requestId":"F07776F3-E584-4A8C-B4CB-B7AA954823C1"
}

待办事项

贡献

您可以通过以下三种方式之一进行贡献

  1. 使用 问题跟踪器 提交错误报告。
  2. 问题跟踪器 上回答问题或修复错误。
  3. 贡献新功能或更新 wiki。

代码贡献流程不是很正式。您只需确保遵循 PSR-0、PSR-1 和 PSR-2 编码规范。任何新的代码贡献都必须附有相应的单元测试(如果适用)。

许可证

MIT