hedeqiang/antispam

网易易盾内容安全 PHP SDK

v1.1.0 2020-10-15 05:14 UTC

This package is auto-updated.

Last update: 2024-09-10 20:59:39 UTC


README

网易云 易盾 内容安全 PHP SDK

在使用本扩展之前,你需要去 网易易盾 获取 secretIdsecretKeybusinessId

安装

$ composer require hedeqiang/antispam -vvv

用法

require __DIR__ .'/vendor/autoload.php';
use Hedeqiang\Antispam\Antispam;

$config = [
    'account' => [
        'secretId' => '',
        'secretKey' => '',
    ],
    'text' => [
        'businessId' => '',
    ],
    'image' => [
        'businessId' => '',
    ],
    'audio' => [
        'businessId' => '',
    ],
    'video' => [
        'businessId' => '',
    ],
];
$antispam = new Antispam($config);

文本

单文本检测

$response = $antispam->textScan(['content' => 'XXX']);

or

$params = [
  'content' => 'XXX','title' => 'XXX','dataId' => 123 ...
]; // 可只传 content 字段。 dataId、version 本 SDK 已经做处理,可传可不传
$extras = [
    'ip' => '10.0.0.1',
    'account' => 'hedeqiang',
    ...
]; // 此参数可不传

$response = $antispam->textScan($params,$extras);

文本批量检测

$texts = [
    ['content' => 'XXX','title' => 'XXX',...],
    ['content' => 'XXX','title' => 'XXX',...]
];  // 可以只填 Y 的值 。dataId 可不传
$extras = [
    'ip' => '10.0.0.1',
    'account' => 'hedeqiang',
    ...
]; // 此参数可不传

$response = $antispam->textBatchScan($params,$extras);

文本离线结果获取

$response = $antispam->textCallback();

文本机器结果反馈接口

$feedback = [
    ['taskId' => 'e8e13a01024345db8e04c0dfaed2ec50','version' => 'v1','level' => 0,'label' => 100]
]; 
$response = $antispam->textFeedback($feedback);

自定义文本关键词-添加

$params = [
    'category' => '100',
    'keywords' => 'XXX,XXX,XXX,XXX,XXX,XXX,XXX'
];
$response  = $antispam->addKeyWorld($params);

自定义关键词-删除

$ids =['23234140','23234141'];
$response = $antispam->delKeyWorld($ids);

自定义关键词查询接口

$response = $antispam->textQuery();

// 也可传入制定参数
$params = [
    'id' => '23223254',
    'keyword' => 'XXX',
    'category' => 100,
    'orderType' => 1,
    'pageNum' => 100,
    'pageSize' => 10,
];

$response = $antispam->textQuery($params);

图片

图片在线检测

$images = [
    ['name' => '','type' => '','data' => '','callbackUrl' => ''],
    ['name' => '','type' => '','data' => '','callbackUrl' => ''],
    ['name' => '','type' => '','data' => '','callbackUrl' => ''],
    ['name' => '','type' => '','data' => '','callbackUrl' => ''],
];
// array $checkLabels = [],array $extras = []
$response = $antispam->imageScan($images);

更多...

更多...

Laravel 中使用

发布配置文件

php artisan vendor:publish --tag=antispam
编写 .env 文件
DUN_SECRET_ID=
DUN_SECRET_KEY=
DUN_TEXT_BUSINESS_ID=
DUN_IMAGE_BUSINESS_ID=
DUN_AUDIO_BUSINESS_ID=
DUN_VIDEO_BUSINESS_ID=

方法参数注入

参数和上面一样

use Hedeqiang\Antispam\Antispam;

public function index(Antispam $antispam)
{
    $response = $antispam->textScan();
}

服务名访问

public function index()
{
    $response = app('antispam')->textScan(); 
}

Facades 门面使用(可以提示)

use Hedeqiang\Antispam\Facades\Antispam;
$response = Antispam::green()->textScan();

贡献

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

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

代码贡献过程并不非常正式。你只需确保遵循PSR-0、PSR-1和PSR-2编码指南。任何新的代码贡献都必须附有适用的单元测试。

许可

MIT