Home >Backend Development >PHP Tutorial >Apple serial number query interface calling code example based on PHP

Apple serial number query interface calling code example based on PHP

WBOY
WBOYOriginal
2016-07-25 08:44:021321browse
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
  1. // +------------- -------------------------------------------------- --------
  2. //----------------------------------
  3. // Apple Serial number calling sample code - aggregated data
  4. // Online interface documentation: http://www.juhe.cn/docs/37
  5. //------------------- ---------------
  6. header('Content-type:text/html;charset=utf-8');
  7. //Configure the appkey you applied for
  8. $appkey = "**********************";
  9. //************1. Apple serial number/IMEI number query************
  10. $url = "http://apis.juhe.cn/appleinfo/index" ;
  11. $params = array(
  12. "sn" => "",//Serial number or IMEI number of Apple product
  13. "dtype" => "",//Return data format: json or xml, default json
  14. "key" => $appkey,//The key you applied for
  15. );
  16. $paramstring = http_build_query($params);
  17. $content = juhecurl($url,$paramstring);
  18. $result = json_decode($content, true);
  19. if($result){
  20. if($result['error_code']=='0'){
  21. print_r($result);
  22. }else{
  23. echo $result['error_code'].": ".$result['reason'];
  24. }
  25. }else{
  26. echo "Request failed";
  27. }
  28. //********************** ******************************
  29. /**
  30. * Request interface return content
  31. * @param string $url [Requested URL address]
  32. * @param string $params [Requested parameters]
  33. * @param int $ipost [Whether to use POST form]
  34. * @return string
  35. */
  36. function juhecurl($url,$params=false, $ispost=0){
  37. $httpInfo = array();
  38. $ch = curl_init();
  39. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  40. curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
  41. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
  42. curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
  43. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  44. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  45. if( $ispost )
  46. {
  47. curl_setopt( $ch , CURLOPT_POST , true );
  48. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  49. curl_setopt( $ch , CURLOPT_URL , $url );
  50. }
  51. else
  52. {
  53. if($params){
  54. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  55. }else{
  56. curl_setopt( $ch , CURLOPT_URL , $url);
  57. }
  58. }
  59. $response = curl_exec( $ch );
  60. if ($ response === FALSE) {
  61. //echo "cURL Error: " . curl_error($ch);
  62. return false;
  63. }
  64. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  65. $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  66. curl_close( $ch );
  67. return $response;
  68. }
Copy code
php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn