Mobile Adapter identifies mobile phones and computers-Baidu terminal adapter encapsulation-PHP source code

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.