This article contains text and a photo detector
// received text to be detected and the detection method calls public function textCheck (the Request $ Request ) { // content security identification $ data [ 'content'] is to be detected text $ Data [ 'Content'] = htmlspecialchars ( $ Request -> POST ( 'Content' )); $ Content = $ Data [ 'Content' ]; $ Output = $ the this -> curlText ( $ Content ); // only when $ output-> errcode == 0 when reviewing by IF ( $ Output -!> The errcode = 0 ) { return JSON ([ 'code' => 500, 'MSG' => 'Content containing illegal content, please be revised and resubmitted ']); the ; } } // received to detected image detection method and call public function imgCheck (the Request $ Request ) { // Get form to upload files uploaded e.g. 001.jpg $ File = Request () -> File ( 'File' ); $ upload_path = 'uploads' ; $ info = $ File -> Move ( $ upload_path ); $ path = $ info -> getSaveName (); // micro communication interface verify whether the violation image $ Output = $ the this -> curlImages ( $ path ); IF ( $ the Output! [ 'The errcode'] = 0 ) { return JSON ([ 'code' => 500, 'MSG' => 'image irregularities' ]); } } // Get access_token, it can not be used to obtain user information token public function getAccessToken () { $ token_file = of json_decode ( file_get_contents ( 'token.json' )); // outer reacquire valid only IF ( $ token_file -> expires_time < Time ()) { $ AppID = $ the this -> the APPID; // your applet AppID $ appsecret = $ the this -> APPSERRET; // your applet appsecret $ URL = 'HTTPS: //api.weixin.qq. COM / cgi-bin / token? grant_type = client_credential & AppID = '. $ AppID .' & Secret = '.$appsecret; $token_json = file_get_contents($url); $token_json = json_decode($token_json); $token_file->access_token = $token_json->access_token; $token_file->expires_time = time()+7200; $access_token = $token_json->access_token; file_put_contents('token.json', json_encode($token_file)); }else{ $access_token = $token_file->access_token; } return $access_token; } // detect whether the text contains prohibited content (frequency limit: the upper limit of a single call appId 1000 times / min, 100,000 / day) Private function curlText ( $ Content ) { $ ACCESS_TOKEN = $ the this -> getAccessToken (); $ URL = " . "https://api.weixin.qq.com/wxa/msg_sec_check?access_token= $ ACCESS_TOKEN ; $ file_data = '{." Content ":"' $ Content . ' "}'; // $ Content (to be detected text content, maximum 520KB) $ CH = curl_init (); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch , CURLOPT_POST, 1); curl_setopt ( $ CH , CURLOPT_POSTFIELDS, $ file_data ); $ Output = the curl_exec ( $ CH ); // send a request acquisition result $ Output = of json_decode ( $ Output , to false ); curl_close ( $ CH ); // Close session return $ Output ; // return result } // detect whether the image contains prohibited content Private function curlImages ( $ path ) { $ ACCESS_TOKEN = $ the this -> getAccessToken (); // their acquisition the access_token $ url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=." $ ACCESS_TOKEN ; $ file_path = 'uploads /'. $ path ; // accept the form files locally saved file address $ file_data = Array ( "Media" => new new \CURLFile($file_path)); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch , CURLOPT_POST, 1); curl_setopt ( $ CH , CURLOPT_POSTFIELDS, $ file_data ); $ Output = the curl_exec ( $ CH ); // send a request acquisition result curl_close ( $ CH ); // Close session $ Output = of json_decode ( $ Output , to true ); return $ Output ; }