PHP monitors whether the Apple Store has "2014-09-15" (server side)

Source: Internet
Author: User
Tags curl api

The annual Apple new products just a few days after the release, September 12 on the official listing, in accordance with the Convention, farmers have to fight on the net, the Apple Store in Hong Kong after the official opening of the 12th 3 o'clock in the afternoon to buy, haven't had time to write a good script, through constant press F5 and enter, unremitting efforts under, robbed 1 units!

After harvest, deliberately write down this script, monitoring Apple online store whether there is goods, the first time the goods sent to notify me 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0061.gif "alt=" J _0061.gif "/>, there are similar online subscription services, leaving an email address can also receive relevant reminders, there are chrom or Firefox plug-ins can be in the browser to monitor the timing, the first time the goods issued a window notification or play a warning sound.

Most of the principles of such services use the same principle, that is, to send a GET request, get the Apple server response JSON string, determine the value inside, such as the isbuyable:true/ False. There are a lot of methods to get, such as the PHP I wrote this time, running on the server side, also can be written in JavaScript, in the browser timed to run, also can be made browser plug-in, receive the return information from the server and the corresponding response to the relevant trigger reminders.

As to how to get or how to know the apple server get URL, the development experience of children's shoes must have used Firefox firebug, open http://store.apple.com/hk-zh/buy-iphone/iphone6/ After buying the webpage, open Firebug, then follow the normal purchase process, such as "iphone 6 Plus", "Gold" and "64GB", note that these options are selected, in the Firebug network module can see the browser issued "http:/ /store.apple.com/hk-zh/buyflowselectionsummary/iphone6p?node=home/shop_iphone/family/iphone6&step=select &option.dimensionScreensize=5_5inch&option.dimensionColor=gold&option.dimensionCapacity=128gb& Option.carriermodel=unlocked%2fww&carrierpolicytype=unlocked "Such a request, and then open the response information for the request, the content is very long, basically as follows:

{"Head": {"status": "$", "data":{}},  "body": {"content": {"Pageurl": "5.5-inch screen -128gb-gold-Unlocked",  "selected": {"Productimage": "\n\ N</span>\n ",                     "Shippingprice": "\n<span class=\" freeshipping promo-text\ "> Free delivery </ Span> ",                     "Shippinglead": "\ n <b>:</b><br/>\n<span class=\" Customer_ Commit_display\ "> Temporary </span>\n\n",                     "Price": "\n<span class=\" current_price\ ">\n <span itemscope=\ "itemscope\"  itemprop=\ "offers\"  itemtype=\ "Http://schema.org/offer\" >\n \n<meta itemprop=\ "pricecurrency\"  content=\ "hkd\"/>\n<span itemprop=\ "price\" >\nHK $8,088\n</span>\n</sPan>\n</span>\n\n\n ",                     "isbuyable":false},  "PartNumber": "mgaf2zp/a"},  "pagetitle": " iphone 6 plus 128gb  Gold   Unlocked  - Apple Store  (Hong Kong) "}}}


The returned JSON contains the parameters of the isbuyable, an estimate that Apple is using this response to determine whether there is inventory and to control the operation of the page.


Knowing this principle, you can write the script, mainly using the Curl API to send the request, the returned JSON converted to an array, and determine the value of the field, false to no goods, true for the goods, the code has been completed, excerpt as follows:

<?php$recipient= "[email protected],[email protected],[email protected]"; $from = "From: [ Email protected]\r\n "; $subject =" iphone6 available "; $headers  =  $from." content-type: text/html\r\n "; $user _agent=" mozilla/5.0  (windows nt 6.1; rv:32.0)   gecko/20100101 firefox/32.0 "; $iphone 6=array (                 0=>array (' screensize ' = ' 4_7inch ', ' color ' = ' silver ', ' capacity ' = > ' 16GB '),                 1= >array (' screensize ' = ' 4_7inch ', ' color ' = ' space_gray ', ' capacity ' = ' 16gb '),                 2=>array (' screensize ' = ' 4_7inch ' , ' color ' = ' gold ', ' capacity ' = ' 16gb '),                 3=>arRay (' screensize ' = ' 4_7inch ', ' color ' = ' silver ', ' capacity ' = ' 64gb '),                 4=>array (' screensize ' = ' 4_7inch ', ' Color ' = ' space_gray ', ' capacity ' = ' 64gb '),                 5=>array (' screensize ' = ' 4_7inch ', ' color ' = ' gold ', ' capacity ' = ' 64GB '),                6=> Array (' screensize ' = ' 4_7inch ', ' color ' = ' silver ', ' capacity ' = ' 128GB '),                 7=>array (' screensize ' = ' 4_7inch ', ' Color ' = ' space_gray ', ' capacity ' = ' 128GB '),                 8=>array (' screensize ' = ' 4_7inch ', ' color ' = ' gold ', ' capacity ' = ' 128GB '),                 ); $iphone 6plus=array (                 0=>array (' screensize ' = > ' 5_5inch ', ' color ' = ' silver ', ' capacity ' = ' 16gb '),                 1=>array (' screensize ' = ' 5_5inch ', ' color ' = ' Space_gray ', ' capacity ' = ' 16gb '),                 2=>array (' screensize ' = ' 5_5inch ', ' color ' = ' gold ', ' capacity ' = ' 16gb '),                 3=>array (' screensize ' = > ' 5_5inch ', ' color ' = ' silver ', ' capacity ' = ' 64gb '),                 4=>array (' screensize ' = ' 5_5inch ', ' color ' = ' Space_gray ', ' capacity ' = ' 64gb '),                  5=>array (' ScreenSize ' = ' 5_5inch ', ' color ' = ' gold ', ' capacity ' and ' 64GB '),                 6=>array (' screensize ' = ' 5_5inch ', ' color ' = ' Silver ', ' capacity ' = ' 128GB '),                 7=>array (' screensize ' = ' 5_5inch ', ' color ' = ' space_gray ', ' capacity ' = ' 128GB '),                 8=>array (' ScreenSize ' = ' 5_5inch ', ' color ' = ' gold ', ' capacity ' and ' 128GB '),                 );// iphone 6 foreach  ($ iphone6 as  $model) {     $screensize = $model [' screensize '];     $color = $model [' Color '];     $capacity = $model [' Capacity '];     $json _url= "http://store.apple.com/hk/ buyflowselectionsummary/iphone6?node=home/shop_iphone/family/iphone6&step=select& Option.dimensionscreensize= ". $screensize." &option.dimensioncolor= ". $color." &option.dimensioncapacity= ". $capacity." &option.carriermodel=unlocked%2fww&carrierpolicytype=unlocked ";     $ch  =  curl_init ();     curl_setopt ($ch, curlopt_url,  $json _url);     curl_setopt ($ch,  curlopt_returntransfer, true);     curl_setopt ($ch,  CURLOPT_USERAGENT,  $user _agent)//disguised as browser      $str =curl_exec ($ch);      $str _array=json_decode ($str, True);     curl_close ($ch);     $available = $str _array[' body ' [' content '] [' selected '] [' purchaseoptions '] [' isbuyable '];    $ partnumber= $str _array[' body ' [' content '] ['Selected ' [' PartNumber '];    if  ($available!==false)          {            echo $ ScreenSize. " -". $color." -". $capacity.":  is available, please go to http://store.apple.com/hk-zh/ Buy-iphone/iphone6?cppart=unlocked/ww&product= ". $partnumber." &step=accessories "." \ n ";             $iphone 6msg.=" <p> ". $ ScreenSize. "   ". $color."   ". $capacity."  is available, <a target=_blank href=\ "http://store.apple.com/hk-zh/buy-iphone/ Iphone6?cppart=unlocked/ww&product= ". $partnumber." &step=accessories\ ">http://store.apple.com/hk-zh/buy-iphone/iphone6?cppart=unlocked/ww&product=". $ PartNumber. " &step=accessories</a></p> ";         }}// iphone  6 plusforeach  ($iphone 6plus as  $model) {     $screensize = $model [' screensize '];    $ color= $model [' color '];     $capacity = $model [' Capacity '];     $json _url= ' http://store.apple.com/hk/buyFlowSelectionSummary/IPHONE6P?node=home/shop_iphone/family/iphone6&step= Select&option.dimensionscreensize= ". $screensize." &option.dimensioncolor= ". $color." &option.dimensioncapacity= ". $capacity." &option.carriermodel=unlocked%2fww&carrierpolicytype=unlocked ";     $ch  =  curl_init ();     curl_setopt ($ch, curlopt_url,  $json _url);     curl_setopt ($ch,  curlopt_returntransfer, true);     curl_setopt ($ch,  CURLOPT_USERAGENT,  $user _agent);     $str =curl_exec ($ch);      $str _array=json_decode ($str, True);     curl_close ($ch);     $ Available= $str _array[' body ' [' content '] [' selected '] [' purchaseoptions '] [' isbuyable '];     $partnumber = $str _ array[' body ' [' content '] [' selected '] [' PartNumber '];    if  ($available!==false)          {             echo  $screensize. " -". $color." -". $capacity.":  is available, please go to http://store.apple.com/hk-zh/ Buy-iphone/iphone6?cppart=unlocked/ww&product= ". $partnumber." &step=accessories "." \ n ";             $iphone 6msg.=" <p> ". $ ScreenSize. "   ". $color."   ". $capacity."  is available, <a target=_blank href=\ "http://store.apple.com/hk-zh/buy-iphone/ Iphone6?cppart=unlocked/ww&product= ". $partnumber." &step=accessories\ ">http://store.apple.com/hk-zh/buy-iphone/iphone6?cppart=unlocked/ww&product=". $ PartNumber. " &step=Accessories</a></p> ";        }}         if  (!empty ($iphone 6msg))              {                 mail ($recipient, $subject, $iphone 6msg, $headers);             }    //$json _url= "http://store.apple.com/hk/buyFlowSelectionSummary/ Iphone6p?node=home/shop_iphone/family/iphone6&step=select&option.dimensionscreensize= ". $screensize." &option.dimensioncolor= ". $color." &option.dimensioncapacity= ". $capacity." &option.carriermodel=unlocked%2fww&carrierpolicytype=unlocked ";//var_dump ($i 6);? >

As to whether the monitoring is accurate, to be verified, only wait for Apple to have good news, hope that the delay will not exceed 10 minutes (if the mail can be sent successfully).

This article is from the "Home Circle Exchange Study" blog, please be sure to keep this source http://brucetam.blog.51cto.com/1863614/1553079

PHP monitors whether the Apple Store has "2014-09-15" (server side)

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.