Code description: PHP-based Apple serial number query interface calling code example Associated data: Apple serial number Interface address: http://www.juhe.cn/docs/api/id/37
- // +------------- -------------------------------------------------- --------
-
- //----------------------------------
- // Apple Serial number calling sample code - aggregated data
- // Online interface documentation: http://www.juhe.cn/docs/37
- //------------------- ---------------
-
- header('Content-type:text/html;charset=utf-8');
-
-
- //Configure the appkey you applied for
- $appkey = "**********************";
-
-
-
-
- //************1. Apple serial number/IMEI number query************
- $url = "http://apis.juhe.cn/appleinfo/index" ;
- $params = array(
- "sn" => "",//Serial number or IMEI number of Apple product
- "dtype" => "",//Return data format: json or xml, default json
- "key" => $appkey,//The key you applied for
- );
- $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";
- }
- //********************** ******************************
-
-
-
-
-
- /**
- * Request interface return content
- * @param string $url [Requested URL address]
- * @param string $params [Requested parameters]
- * @param int $ipost [Whether to use 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;
- }
Copy code
|