コード例 #1
0
ファイル: Images.php プロジェクト: jiatower/php
 /**
  * 图谱科技的相关数据插入到数据库中
  * 色情+人物类型:
  */
 public static function addImagesRecord($data, $item)
 {
     $ok = 0;
     // 内容为空
     $date_empty = 1;
     // 内容为空
     $log = new FLogger("images_log");
     $data = json_decode($data, true);
     if ($data && $data["code"] == 0) {
         // 检测成功
         $images = array();
         if ($item == Service_TupuTech::$SEXY_AND_AD) {
             //“通用广告”的返回值,“5588dba4c7ee53a04b5fad7d”是“通用广告”的识别任务的TaskID
             $ad_data = $data["5588dba4c7ee53a04b5fad7d"];
             if ($ad_data) {
                 $file_list = $ad_data["fileList"];
                 foreach ($file_list as $file) {
                     $name = CommonUtil::getOriginImg($file["name"]);
                     $arr = array();
                     if (array_key_exists($name, $images)) {
                         $arr = $images[$name];
                     }
                     $arr["ad_rate"] = 100 * $file["rate"];
                     $arr["ad_flag"] = $file["label"];
                     $review = 1;
                     if (!$file["review"]) {
                         $review = 0;
                     }
                     $arr["ad_review"] = $review;
                     $arr["human_review"] = 0;
                     $images[$name] = $arr;
                 }
             }
         }
         if ($item == Service_TupuTech::$SEXY_AND_HUMAN) {
             //“任务识别”的返回值,“dbd1d2c23705e7102070e6”是“色情+人物”的识别任务的TaskID
             $ad_data = $data["554202c4b01bd8ee3b6c005c"];
             if ($ad_data) {
                 $file_list = $ad_data["fileList"];
                 foreach ($file_list as $file) {
                     $name = CommonUtil::getOriginImg($file["name"]);
                     $arr = array();
                     if (array_key_exists($name, $images)) {
                         $arr = $images[$name];
                     }
                     $arr["human_rate"] = 100 * $file["rate"];
                     $arr["human_flag"] = $file["label"];
                     $review = 1;
                     if (!$file["review"]) {
                         $review = 0;
                     }
                     $arr["human_review"] = $review;
                     $arr["ad_review"] = 0;
                     $images[$name] = $arr;
                 }
             }
         }
         // “是否色情”的返回值,“54bcfc6c329af61034f7c2fc”是“是否色情”的识别任务的TaskID
         $sexy_data = $data["54bcfc6c329af61034f7c2fc"];
         if ($sexy_data) {
             $file_list = $sexy_data["fileList"];
             foreach ($file_list as $file) {
                 $name = CommonUtil::getOriginImg($file["name"]);
                 $arr = array();
                 if (array_key_exists($name, $images)) {
                     $arr = $images[$name];
                 }
                 $arr["sexy_rate"] = 100 * $file["rate"];
                 $arr["sexy_flag"] = $file["label"];
                 $review = 1;
                 if (!$file["review"]) {
                     $review = 0;
                 }
                 $arr["sexy_review"] = $review;
                 $arr["item"] = $item;
                 $images[$name] = $arr;
             }
         }
         $db_data = self::doCheck($images, $item);
         self::addIntoDb($db_data);
         $res_data = array();
         foreach ($db_data as $img) {
             $item = array();
             $item["url"] = $img["url"];
             $item["status"] = $img["status"];
             array_push($res_data, $item);
         }
         $log->append("tuputech is ok " . json_encode($db_data));
         return CommonUtil::GetDefRes($ok, "success", $res_data);
     } else {
         $log->append("[ERROR] tuputech is error " . json_encode($data));
         return CommonUtil::GetDefRes($date_empty, " data is empty or code is not 0");
     }
 }