GithubHelp home page GithubHelp logo

aliyun-green's Introduction

阿里云内容安全检测

Installing

$ composer require lmdfx/aliyun-green

Service Provider

//file app.php in array providers :
Lmdfx\AliyunGreen\AliyunGreenServiceProvider::class,

Aliases

//file app.php in array aliases :
'AliyunGreen' => \Lmdfx\AliyunGreen\AliyunGreenFacade::class,

config

//复制配置文件到config目录下
php artisan vendor:publish --provider=Lmdfx\AliyunGreen\AliyunGreenServiceProvider
<?php
return [
    //是否开启检测
    'enable' => true,

    'debug' => false,

    'timeout' => 6,

    'connect_timeout' => 10,

    'access_key_id' => '',

    'access_key_secret' => '',

    'region_id' => 'cn-beijing',

    //图片检测,需要的场景
    'image_scan_scenes' => [
        'porn',//色情
        'terrorism',//暴恐涉政
        'ad',//广告
        'qrcode',//二维码
        'live',//不良场景
        'logo',//logo
    ],

    //视频检测,需要的场景
    'video_scan_scenes' => [
        'porn',//色情
        'terrorism',//暴恐涉政
        'ad',//广告
        'live',//不良场景
        'logo',//logo
    ], 

    'audio_scenes' => false, //true- 检测视频里面的语音是否违规,false-不检测视频里面的语音。
];

Usage

<?php
use Illuminate\Support\Facades\Route;

//文本检查
Route::get('test', function() {
    return AliyunGreen::greenTextScan('test');
});
//会直接返回阿里云检查结果
{
    "code": 200,
    "data": [
        {
            "code": 200,
            "content": "test",
            "msg": "OK",
            "results": [
                {
                    "label": "normal",
                    "rate": 99.91,
                    "scene": "antispam",
                    "suggestion": "pass"
                }
            ],
            "taskId": "txt4wP0KSIBQpj5rV7E9FiQd1-1v6R5I"
        }
    ],
    "msg": "OK",
    "requestId": "C4E1EC85-C773-5833-85EA-EDE3CFCC9282"
}
-------
//图片检查
Route::get('test', function() {
    // return AliyunGreen::greenTextScan('test');
    $url = 'https://images.pexels.com/photos/57440/cherry-blossom-blossom-bloom-spring-57440.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500';
    return AliyunGreen::greenImageScan($url);
});
{
    "code": 200,
    "data": [
        {
            "code": 200,
            "extras": {},
            "msg": "OK",
            "results": [
                {
                    "label": "normal",
                    "rate": 99.9,
                    "scene": "porn",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 100.0,
                    "scene": "terrorism",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.91,
                    "scene": "ad",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.91,
                    "scene": "qrcode",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.91,
                    "scene": "live",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.9,
                    "scene": "logo",
                    "suggestion": "pass"
                }
            ],
            "taskId": "img7f0eyk7rH3R4ij3wtoW6n7-1v6Rbu",
            "url": "https://images.pexels.com/photos/57440/cherry-blossom-blossom-bloom-spring-57440.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
        }
    ],
    "msg": "OK",
    "requestId": "FEEF2A57-092F-57CA-804A-CA0FE8EE3E94"
}

//视频检测,仅支持异步检测,拿到taskId去获取检查结果
Route::get('test', function() {
    // return AliyunGreen::greenTextScan('test');
    // $url = 'https://images.pexels.com/photos/57440/cherry-blossom-blossom-bloom-spring-57440.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500';
    // return AliyunGreen::greenImageScan($url);
    $videurl='https://look.thinksns.com/storage/public:MjAyMS8xMC8xMS94MzhCVnZiejJhUk02MG9Sa1hWdTlHM2ZuQmVUb2x6WWJ6QXlYYkdzQ0VJMmhtVENNTlBTMW9pOUhBZ0RRMnVPLm1wNA==';
    return AliyunGreen::greenVideoScan($videurl);
});
{
    "code": 200,
    "data": [
        {
            "code": 200,
            "msg": "OK",
            "taskId": "vi76GKuEkUkfu7P5nK0YgXKq-1v6Rfr",
            "url": "https://look.thinksns.com/storage/public:MjAyMS8xMC8xMS94MzhCVnZiejJhUk02MG9Sa1hWdTlHM2ZuQmVUb2x6WWJ6QXlYYkdzQ0VJMmhtVENNTlBTMW9pOUhBZ0RRMnVPLm1wNA=="
        }
    ],
    "msg": "OK",
    "requestId": "25492596-3A71-5601-B362-16CA2003B3C6"
}


//通过taskId获取视频检测结果
Route::get('test', function() {
    // return AliyunGreen::greenTextScan('test');
    // $url = 'https://images.pexels.com/photos/57440/cherry-blossom-blossom-bloom-spring-57440.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500';
    // return AliyunGreen::greenImageScan($url);
    // $videurl='https://look.thinksns.com/storage/public:MjAyMS8xMC8xMS94MzhCVnZiejJhUk02MG9Sa1hWdTlHM2ZuQmVUb2x6WWJ6QXlYYkdzQ0VJMmhtVENNTlBTMW9pOUhBZ0RRMnVPLm1wNA==';
    // return AliyunGreen::greenVideoScan($videurl);
    return AliyunGreen::getVideAsyncScanResult('vi76GKuEkUkfu7P5nK0YgXKq-1v6Rfr');
});

{
    "code": 200,
    "data": [
        {
            "code": 200,
            "extras": {
                "frameCount": "9",
                "framePrefix": "http://aligreen-beijing.oss-cn-beijing-internal.aliyuncs.com/prod/hammal/111222906/29877421_public3AMjAyMS8xMC8xMS94MzhCVnZiejJhUk02MG9Sa1hWdTlHM2ZuQmVUb2x6WWJ6QXlYYkdzQ0VJMmhtVENNTlBTMW9pOUhBZ0RRMnVPLm1wNA3D3D-frames/f0000"
            },
            "msg": "OK",
            "results": [
                {
                    "label": "normal",
                    "rate": 99.9,
                    "scene": "porn",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.9,
                    "scene": "terrorism",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.9,
                    "scene": "ad",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.9,
                    "scene": "live",
                    "suggestion": "pass"
                },
                {
                    "label": "normal",
                    "rate": 99.9,
                    "scene": "logo",
                    "suggestion": "pass"
                }
            ],
            "taskId": "vi76GKuEkUkfu7P5nK0YgXKq-1v6Rfr",
            "url": "https://look.thinksns.com/storage/public:MjAyMS8xMC8xMS94MzhCVnZiejJhUk02MG9Sa1hWdTlHM2ZuQmVUb2x6WWJ6QXlYYkdzQ0VJMmhtVENNTlBTMW9pOUhBZ0RRMnVPLm1wNA=="
        }
    ],
    "msg": "OK",
    "requestId": "5ABB0CF1-D439-528A-A90B-F1BDBEE851FD"
}

License

MIT

aliyun-green's People

Contributors

liumingdfx avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.