TP5 百度智慧雲 內容稽核 SDK 呼叫
阿新 • • 發佈:2020-12-20
我把 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 }