Stats.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /*
  3. * This file is part of the overtrue/wechat.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. /**
  11. * Stats.php.
  12. *
  13. * @author allen05ren <allen05ren@outlook.com>
  14. * @copyright 2016 overtrue <i@overtrue.me>
  15. *
  16. * @see https://github.com/overtrue
  17. * @see http://overtrue.me
  18. */
  19. namespace EasyWeChat\ShakeAround;
  20. use EasyWeChat\Core\AbstractAPI;
  21. /**
  22. * Class Stats.
  23. */
  24. class Stats extends AbstractAPI
  25. {
  26. const API_DEVICE = 'https://api.weixin.qq.com/shakearound/statistics/device';
  27. const API_DEVICE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/devicelist';
  28. const API_PAGE = 'https://api.weixin.qq.com/shakearound/statistics/page';
  29. const API_PAGE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/pagelist';
  30. /**
  31. * Fetch statistics data by deviceId.
  32. *
  33. * @param array $deviceIdentifier
  34. * @param int $beginDate (Unix timestamp)
  35. * @param int $endDate (Unix timestamp)
  36. *
  37. * @return \EasyWeChat\Support\Collection
  38. */
  39. public function deviceSummary(array $deviceIdentifier, $beginDate, $endDate)
  40. {
  41. $params = [
  42. 'device_identifier' => $deviceIdentifier,
  43. 'begin_date' => $beginDate,
  44. 'end_date' => $endDate,
  45. ];
  46. return $this->parseJSON('json', [self::API_DEVICE, $params]);
  47. }
  48. /**
  49. * Fetch all devices statistics data by date.
  50. *
  51. * @param int $timestamp
  52. * @param int $pageIndex
  53. *
  54. * @return \EasyWeChat\Support\Collection
  55. */
  56. public function batchDeviceSummary($timestamp, $pageIndex)
  57. {
  58. $params = [
  59. 'date' => $timestamp,
  60. 'page_index' => $pageIndex,
  61. ];
  62. return $this->parseJSON('json', [self::API_DEVICE_LIST, $params]);
  63. }
  64. /**
  65. * Fetch statistics data by pageId.
  66. *
  67. * @param int $pageId
  68. * @param int $beginDate (Unix timestamp)
  69. * @param int $endDate (Unix timestamp)
  70. *
  71. * @return \EasyWeChat\Support\Collection
  72. */
  73. public function pageSummary($pageId, $beginDate, $endDate)
  74. {
  75. $params = [
  76. 'page_id' => $pageId,
  77. 'begin_date' => $beginDate,
  78. 'end_date' => $endDate,
  79. ];
  80. return $this->parseJSON('json', [self::API_PAGE, $params]);
  81. }
  82. /**
  83. * Fetch all pages statistics data by date.
  84. *
  85. * @param int $timestamp
  86. * @param int $pageIndex
  87. *
  88. * @return \EasyWeChat\Support\Collection
  89. */
  90. public function batchPageSummary($timestamp, $pageIndex)
  91. {
  92. $params = [
  93. 'date' => $timestamp,
  94. 'page_index' => $pageIndex,
  95. ];
  96. return $this->parseJSON('json', [self::API_PAGE_LIST, $params]);
  97. }
  98. }