PHP-based Apple serial number query interface call code instance

Source: Internet
Author: User
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. Apple Serial number call sample code-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 requested
  8. $appkey = "*********************";
  9. 1. Apple serial number/imei query ************
  10. $url = "Http://apis.juhe.cn/appleinfo/index";
  11. $params = Array (
  12. "SN" and "" ",//serial number or IMEI number of the Apple product
  13. "Dtype" = "" ",///Return Data format: JSON or XML, default JSON
  14. "Key" = $appkey,//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 to return content
  31. * @param string $url [requested URL address]
  32. * @param string $params [parameter requested]
  33. * @param int $ipost [if post is used]
  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
  • 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.