Php-based Apple serial number query interface call code instance

Source: Internet
Author: User
Php-based Apple serial number query interface call code instance
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

  1. // + ----------------------------------------------------------------------
  2. //----------------------------------
  3. // Sample code for calling the Apple serial number-aggregate 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
  8. $ Appkey = "*********************";
  9. // ************ 1. query the Apple serial number/IMEI number ************
  10. $ Url = "http://apis.juhe.cn/appleinfo/index ";
  11. $ Params = array (
  12. "Sn" => "", // serial number or IMEI number of the Apple product
  13. "Dtype" => "", // the returned data format is json or xml. the default format is json.
  14. "Key" => $ appkey, // key you applied
  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. * Content returned by the request interface
  31. * @ Param string $ url [requested URL]
  32. * @ Param string $ params [request parameters]
  33. * @ Param int $ ipost [whether to use the 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. }

Php

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.