Mobile Adapter identifies mobile phones and computers-Baidu terminal adapter encapsulation php code:
Client_id = $ client_id; $ this-> client_secret = $ client_secret; $ this-> token = $ this-> gettoken ();} // Obtain the returned private function post ($ url, $ post, $ header = "Content-type: text/xml") by using the encapsulated https post method ") {$ ch = curl_init ($ url); curl_setopt ($ ch, CURLOPT_HEADER, $ header); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, expires, false); curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt ($ ch, success, true); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt ($ ch, success, success, 0); curl_setopt ($ ch, CURLOPT_POST, 1); if (is_array ($ post) {$ post = http_build_query ($ post ,'','&');} curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post); $ content = curl_exec ($ ch); curl_close ($ ch); return $ content ;} // method for obtaining token private function gettoken () {$ post = array ('grant _ type' => $ this-> grant_type, 'client _ id' => $ this-> client_id, 'Client _ secret' => $ this-> client_secret,); $ result = $ this-> post (' https://openapi.baidu.com/oauth/2.0/token ', $ Post); $ token = json_decode ($ result)-> access_token; return $ token ;} /*** identify the mobile phone and client ** @ param string $ the browser type obtained by useragent $ _ SERVER ['http _ USER_AGENT '] to obtain * @ return mobile phone and computer $ pc = 1 is mobile phone 2 is computer */public function Pcphone ($ useragent) {$ data = array ('Access _ token' => $ this-> token, 'lcid' => 'miad', 'User _ agent' => $ useragent ,); $ result = $ this-> post (' https://openapi.baidu.com/rest/2.0/wise/adapt ', $ Data); $ pc = json_decode ($ result)-> device_type; if ($ pc = 1) {return "mobile phone ";} else {return "" ;}}$ pc = new Baiapt ('wlndr8vddc1zciqfdg8twnoy', 'iddm8ifckk0ihqhstgkb3m9dkwzndttk '); // input the api and key of the Baidu application to echo $ pc-> Pcphone ($ _ SERVER ['http _ USER_AGENT ']); // 1 indicates that mobile phone 2 is a computer