TP5 百度智能云 内容审核 SDK 调用

PHP SDK 官方下载地址

PHP SDK 官方文档

我把 PHP SDK 放到了TP5的 extend  了

在这里我根据 PHP SDK 再次封装了一下函数,代码示下

    /**
     * 百度云内容审核
     * @param  [type] $type    内容类型 image msg
     * @param  [type] $content 内容
     * @return [type]          [description]
     */
    public function checkRes($type,$content)
    {
        include  'extend/bdapi/AipContentCensor.php';
        $AppID = '21****46';
        $APIKey = 'dAX***************hLv';
        $SecretKey = 's5sl*******************8v90';
        $client = new \AipContentCensor($AppID, $APIKey, $SecretKey);
        if($type == 'image'){
            $isUrl = substr(trim($content), 0, 4) === 'http';
            if(!$isUrl){
                $content = file_get_contents($content);
            }
            $result = $client->imageCensorUserDefined($content);
        }else{
            $result = $client->textCensorUserDefined($content);
        }
        if (isset($result['conclusion']) && $result['conclusion'] == '合规') {
            $data = [
                'status'=>'success',
                'code'=>1,
                'msg'=>'合规'
            ];
        } else {
            $data = [
                'status'=>'error',
                'code'=>0,
                'msg'=>'不合规'
            ];
        }
        return $data
    }

 

posted @ 2020-12-20 21:48  孤陌  阅读(397)  评论(0编辑  收藏  举报