Stats.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. * Part of Overtrue\WeChat.
  14. *
  15. * For the full copyright and license information, please view the LICENSE
  16. * file that was distributed with this source code.
  17. *
  18. * @author mingyoung <mingyoungcheung@gmail.com>
  19. * @copyright 2017
  20. *
  21. * @see https://github.com/overtrue
  22. * @see http://overtrue.me
  23. */
  24. namespace EasyWeChat\MiniProgram\Stats;
  25. use EasyWeChat\MiniProgram\Core\AbstractMiniProgram;
  26. class Stats extends AbstractMiniProgram
  27. {
  28. const SUMMARY_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend';
  29. const DAILY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend';
  30. const WEEKLY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend';
  31. const MONTHLY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend';
  32. const VISIT_DISTRIBUTION = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution';
  33. const DAILY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo';
  34. const WEEKLY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo';
  35. const MONTHLY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyretaininfo';
  36. const VISIT_PAGE = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage';
  37. const USER_PORTRAIT = 'https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait';
  38. /**
  39. * Get summary trend.
  40. *
  41. * @param string $from
  42. * @param string $to
  43. *
  44. * @return \EasyWeChat\Support\Collection
  45. */
  46. public function summaryTrend($from, $to)
  47. {
  48. return $this->query(self::SUMMARY_TREND, $from, $to);
  49. }
  50. /**
  51. * Get daily visit trend.
  52. *
  53. * @param string $from
  54. * @param string $to
  55. *
  56. * @return \EasyWeChat\Support\Collection
  57. */
  58. public function dailyVisitTrend($from, $to)
  59. {
  60. return $this->query(self::DAILY_VISIT_TREND, $from, $to);
  61. }
  62. /**
  63. * Get weekly visit trend.
  64. *
  65. * @param string $from
  66. * @param string $to
  67. *
  68. * @return \EasyWeChat\Support\Collection
  69. */
  70. public function weeklyVisitTrend($from, $to)
  71. {
  72. return $this->query(self::WEEKLY_VISIT_TREND, $from, $to);
  73. }
  74. /**
  75. * Get monthly visit trend.
  76. *
  77. * @param string $from
  78. * @param string $to
  79. *
  80. * @return \EasyWeChat\Support\Collection
  81. */
  82. public function monthlyVisitTrend($from, $to)
  83. {
  84. return $this->query(self::MONTHLY_VISIT_TREND, $from, $to);
  85. }
  86. /**
  87. * Get visit distribution.
  88. *
  89. * @param string $from
  90. * @param string $to
  91. *
  92. * @return \EasyWeChat\Support\Collection
  93. */
  94. public function visitDistribution($from, $to)
  95. {
  96. return $this->query(self::VISIT_DISTRIBUTION, $from, $to);
  97. }
  98. /**
  99. * Get daily retain info.
  100. *
  101. * @param string $from
  102. * @param string $to
  103. *
  104. * @return \EasyWeChat\Support\Collection
  105. */
  106. public function dailyRetainInfo($from, $to)
  107. {
  108. return $this->query(self::DAILY_RETAIN_INFO, $from, $to);
  109. }
  110. /**
  111. * Get weekly retain info.
  112. *
  113. * @param string $from
  114. * @param string $to
  115. *
  116. * @return \EasyWeChat\Support\Collection
  117. */
  118. public function weeklyRetainInfo($from, $to)
  119. {
  120. return $this->query(self::WEEKLY_RETAIN_INFO, $from, $to);
  121. }
  122. /**
  123. * Get monthly retain info.
  124. *
  125. * @param string $from
  126. * @param string $to
  127. *
  128. * @return \EasyWeChat\Support\Collection
  129. */
  130. public function montylyRetainInfo($from, $to)
  131. {
  132. return $this->query(self::MONTHLY_RETAIN_INFO, $from, $to);
  133. }
  134. /**
  135. * Get visit page.
  136. *
  137. * @param string $from
  138. * @param string $to
  139. *
  140. * @return \EasyWeChat\Support\Collection
  141. */
  142. public function visitPage($from, $to)
  143. {
  144. return $this->query(self::VISIT_PAGE, $from, $to);
  145. }
  146. /**
  147. * Get user portrait.
  148. *
  149. * @param string $from
  150. * @param string $to
  151. *
  152. * @return \EasyWeChat\Support\Collection
  153. */
  154. public function userPortrait($from, $to)
  155. {
  156. return $this->query(self::USER_PORTRAIT, $from, $to);
  157. }
  158. /**
  159. * Unify query.
  160. *
  161. * @param string $from
  162. * @param string $to
  163. *
  164. * @return \EasyWeChat\Support\Collection
  165. */
  166. protected function query($api, $from, $to)
  167. {
  168. $params = [
  169. 'begin_date' => $from,
  170. 'end_date' => $to,
  171. ];
  172. return $this->parseJSON('json', [$api, $params]);
  173. }
  174. }