tm_pagereq.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 15/12/4
  6. * Time: 上午11:07
  7. */
  8. class tm_pagereq
  9. {
  10. private $appkey;
  11. private $secretKey;
  12. private $sessionKey;
  13. private $total_items;
  14. private $num_iids;
  15. private $leftcount;
  16. public function __construct($appKey,$sercetCode,$sessionKey)
  17. {
  18. $this->appkey = $appKey;
  19. $this->secretKey = $sercetCode;
  20. $this->sessionKey = $sessionKey;
  21. $this->total_items = 0;
  22. $this->leftcount = -1;
  23. $this->num_iids = array();
  24. }
  25. public function proc()
  26. {
  27. $page_no = 1;
  28. do
  29. {
  30. if($this->get_onsale($page_no) == false) {
  31. Log::record("error request.",Log::ERR);
  32. return NULL;
  33. }
  34. $page_no++;
  35. } while($this->leftcount > 0);
  36. return $this->num_iids;
  37. }
  38. public function get_onsale($page_no)
  39. {
  40. $page_size = 200;
  41. $c = new TopClient;
  42. $c->appkey = $this->appkey;
  43. $c->secretKey = $this->secretKey;
  44. $req = new ItemsOnsaleGetRequest;
  45. $req->setFields('approve_status,num_iid');
  46. $req->setPageSize($page_size);
  47. $req->setPageNo($page_no);
  48. $resp = $c->execute($req,$body,$this->sessionKey);
  49. if(!empty($resp))
  50. {
  51. $this->total_items = $resp->total_results;
  52. Log::record("total={$this->total_items}\r\n",Log::DEBUG);
  53. $items = $resp->items->item;
  54. if($items == NULL) {
  55. Log::record("total={$this->total_items}\r\n",Log::DEBUG);
  56. echo "total={$this->total_items}\r\n";
  57. flush();
  58. return NULL;
  59. }
  60. if($this->leftcount < 0) {
  61. $this->leftcount = $this->total_items;
  62. }
  63. $this->leftcount -= count($items);
  64. foreach($items as $item) {
  65. array_push($this->num_iids,$item);
  66. }
  67. return true;
  68. } else {
  69. return NULL;
  70. }
  71. }
  72. }