日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

之前做平臺(tái)內(nèi)容發(fā)布審核都是自己構(gòu)建一套違禁詞庫,在代碼中利用詞庫判斷用戶發(fā)布的內(nèi)容,現(xiàn)在可以使用百度ai api完成這個(gè)功能。接下來就簡單說下怎么做吧:

首先打開百度ai 開發(fā)平臺(tái) 注冊一個(gè)賬號

利用百度ai實(shí)現(xiàn)文本和圖片審核

 


利用百度ai實(shí)現(xiàn)文本和圖片審核

 

進(jìn)入控制臺(tái)

利用百度ai實(shí)現(xiàn)文本和圖片審核

 

創(chuàng)建自己的應(yīng)用,獲取apikey 和秘鑰

利用百度ai實(shí)現(xiàn)文本和圖片審核

 

進(jìn)入文檔頁 文本審核:

利用百度ai實(shí)現(xiàn)文本和圖片審核

 

圖像審核:

利用百度ai實(shí)現(xiàn)文本和圖片審核

 

文檔很詳細(xì),實(shí)現(xiàn)用戶發(fā)布內(nèi)容審核 圖片審核還是很方便簡單的。

我沒有使用官方的sdk,簡單的整合了一下作為練手,以下是我簡單使用php實(shí)現(xiàn)的代碼demo:

use NntControllerApplication;
class Sentive
{
 protected $accessTokenUrl = 'https://aip.baidubce.com/oauth/2.0/token';//獲取token url
 protected $textUrl = 'https://aip.baidubce.com/rest/2.0/antispam/v2/spam';//文本審核url
 protected $imgUrl = 'https://aip.baidubce.com/api/v1/solution/direct/img_censor';//圖片審核url
 protected $avatarUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/face_audit';//頭像審核url
 protected $grant_type;
 protected $client_id;
 protected $client_secret;
 function __construct()
{
 $this->grant_type = 'client_credentials';
 $this->client_id = 'xxx';//API Key
 $this->client_secret = 'xxx';//Secret Key
 }
 static function request($url = '', $param = '')
{
 if (empty($url) || empty($param)) {
 return false;
 }
 $postUrl = $url;
 $curlPost = $param;
 $curl = curl_init();//初始化curl
 curl_setopt($curl, CURLOPT_URL, $postUrl);//抓取指定網(wǎng)頁
 curl_setopt($curl, CURLOPT_HEADER, 0);//設(shè)置header
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//要求結(jié)果為字符串且輸出到屏幕上
 curl_setopt($curl, CURLOPT_POST, 1);//post提交方式
 curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
 $data = curl_exec($curl);//運(yùn)行curl
 curl_close($curl);
 return $data;
 }
 static function request_post($url = '', $param = array(), $type)
{
 if (empty($url) || empty($param)) {
 return false;
 }
 $postUrl = $url;
 $curlPost = $param;
 $curl = curl_init();
 curl_setopt($curl, CURLOPT_URL, $postUrl);
 curl_setopt($curl, CURLOPT_HEADER, 0);
 // 要求結(jié)果為字符串
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 // post方式
 curl_setopt($curl, CURLOPT_POST, 1);
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
 if ($type == "text") {
 curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
 } else {
 curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
 }
 curl_setopt($curl, CURLINFO_HEADER_OUT, true);
 $data = curl_exec($curl);
 $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
 if ($code === 0) {
 throw new Exception(curl_error($curl));
 }
 curl_close($curl);
 return $data;
 }
 //獲取token
 public function getToken()
{
 $redis = Application::$shared->di->getRedis();
 $post_data['grant_type'] = $this->grant_type;
 $post_data['client_id'] = $this->client_id;
 $post_data['client_secret'] = $this->client_secret;
 $o = "";
 foreach ($post_data as $k => $v) {
 $o .= "$k=" . urlencode($v) . "&";
 }
 $post_data = substr($o, 0, -1);
 $res = self::request($this->accessTokenUrl, $post_data);
 $redis->setkey("filterToken", json_decode($res, true)['access_token']);
 return json_decode($res, true)['access_token'];
 }
 //文本審核
 public function textVerify($data)
{
 $redis = Application::$shared->di->getRedis();
 $token = $redis->get("filterToken");
 if (empty($token)) {
 $token = $this->getToken();
 }
 $curl = $this->textUrl . "?access_token=" . $token;
 $result = self::request_post($curl, $data, "text");
 return json_decode($result, true);
 }
 //圖片審核
 public function imgVerify($img)
{
 $redis = Application::$shared->di->getRedis();
 $token = $redis->get("filterToken");
 if (empty($token)) {
 $token = $this->getToken();
 }
 $curl = $this->imgUrl . "?access_token=" . $token;
 $bodys = array(
 'image' => $img,
 'scenes' => array("ocr",
 "face", "public", "politician", "antiporn", "terror", "webimage", "disgust",
 'watermark')
 );
 $bodys = json_encode($bodys);
 $result = self::request_post($curl, $bodys, "img");
 return json_decode($result, true);
 }
 //頭像審核
 public function avatarVerify($img)
{
 $redis = Application::$shared->di->getRedis();
 $token = $redis->get("filterToken");
 if (empty($token)) {
 $token = $this->getToken();
 }
 $curl = $this->avatarUrl . "?access_token=" . $token;
 $bodys = array(
 "configId" => "1",
 "images" => $img
 );
 $result = self::request_post($curl, $bodys, "text");
 return json_decode($result, true);
 }
}

分享到:
標(biāo)簽:ai
用戶無頭像

網(wǎng)友整理

注冊時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定