Code description: php-based Apple serial number query interface call code instance Associated Data: Apple serial number Interface address: http://www.juhe.cn/docs/api/id/37
-
- // + ----------------------------------------------------------------------
-
- //----------------------------------
- // Sample code for calling the Apple serial number-aggregate data
- // Online interface documentation: http://www.juhe.cn/docs/37
- //----------------------------------
-
- Header ('content-type: text/html; charset = utf-8 ');
-
-
- // Configure the appkey you applied
- $ Appkey = "*********************";
-
-
-
-
- // ************ 1. query the Apple serial number/IMEI number ************
- $ Url = "http://apis.juhe.cn/appleinfo/index ";
- $ Params = array (
- "Sn" => "", // serial number or IMEI number of the Apple product
- "Dtype" => "", // the returned data format is json or xml. the default format is json.
- "Key" => $ appkey, // key you applied
- );
- $ Paramstring = http_build_query ($ params );
- $ Content = juhecurl ($ url, $ paramstring );
- $ Result = json_decode ($ content, true );
- If ($ result ){
- If ($ result ['error _ Code'] = '0 '){
- Print_r ($ result );
- } Else {
- Echo $ result ['error _ Code']. ":". $ result ['reason '];
- }
- } Else {
- Echo "request failed ";
- }
- //************************************** ************
-
-
-
-
-
- /**
- * Content returned by the request interface
- * @ Param string $ url [requested URL]
- * @ Param string $ params [request parameters]
- * @ Param int $ ipost [whether to use the POST form]
- * @ Return string
- */
- Function juhecurl ($ url, $ params = false, $ ispost = 0 ){
- $ HttpInfo = array ();
- $ Ch = curl_init ();
-
- Curl_setopt ($ ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
- Curl_setopt ($ ch, CURLOPT_USERAGENT, 'juhedata ');
- Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 60 );
- Curl_setopt ($ ch, CURLOPT_TIMEOUT, 60 );
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
- Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true );
- If ($ ispost)
- {
- Curl_setopt ($ ch, CURLOPT_POST, true );
- Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ params );
- Curl_setopt ($ ch, CURLOPT_URL, $ url );
- }
- Else
- {
- If ($ params ){
- Curl_setopt ($ ch, CURLOPT_URL, $ url .'? '. $ Params );
- } Else {
- Curl_setopt ($ ch, CURLOPT_URL, $ url );
- }
- }
- $ Response = curl_exec ($ ch );
- If ($ response = FALSE ){
- // Echo "cURL Error:". curl_error ($ ch );
- Return false;
- }
- $ HttpCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE );
- $ HttpInfo = array_merge ($ httpInfo, curl_getinfo ($ ch ));
- Curl_close ($ ch );
- Return $ response;
- }
|