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
- // +----------------------------------------------------------------------
- //----------------------------------
- Apple Serial number call sample code-aggregate data
- Online interface Documentation: HTTP://WWW.JUHE.CN/DOCS/37
- //----------------------------------
- Header (' Content-type:text/html;charset=utf-8 ');
- Configure the Appkey you requested
- $appkey = "*********************";
- 1. Apple serial number/imei query ************
- $url = "Http://apis.juhe.cn/appleinfo/index";
- $params = Array (
- "SN" and "" ",//serial number or IMEI number of the Apple product
- "Dtype" = "" ",///Return Data format: JSON or XML, default JSON
- "Key" = $appkey,//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 to return content
- * @param string $url [requested URL address]
- * @param string $params [parameter requested]
- * @param int $ipost [if post is used]
- * @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 |