-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mini-program datacube. * stats testcase. * service provider.
- Loading branch information
Showing
4 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
/** | ||
* Stats.php. | ||
* | ||
* Part of Overtrue\WeChat. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author mingyoung <[email protected]> | ||
* @copyright 2017 | ||
* | ||
* @see https://github.com/overtrue | ||
* @see http://overtrue.me | ||
*/ | ||
|
||
namespace EasyWeChat\MiniProgram\Stats; | ||
|
||
use EasyWeChat\MiniProgram\Core\AbstractMiniProgram; | ||
|
||
class Stats extends AbstractMiniProgram | ||
{ | ||
const SUMMARY_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend'; | ||
const DAILY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend'; | ||
const WEEKLY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend'; | ||
const MONTHLY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend'; | ||
const VISIT_DISTRIBUTION = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution'; | ||
const DAILY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo'; | ||
const WEEKLY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo'; | ||
const MONTHLY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyretaininfo'; | ||
const VISIT_PAGE = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage'; | ||
|
||
/** | ||
* Get summary trend. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function summaryTrend($from, $to) | ||
{ | ||
return $this->query(self::SUMMARY_TREND, $from, $to); | ||
} | ||
|
||
/** | ||
* Get daily visit trend. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function dailyVisitTrend($from, $to) | ||
{ | ||
return $this->query(self::DAILY_VISIT_TREND, $from, $to); | ||
} | ||
|
||
/** | ||
* Get weekly visit trend. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function weeklyVisitTrend($from, $to) | ||
{ | ||
return $this->query(self::WEEKLY_VISIT_TREND, $from, $to); | ||
} | ||
|
||
/** | ||
* Get monthly visit trend. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function monthlyVisitTrend($from, $to) | ||
{ | ||
return $this->query(self::MONTHLY_VISIT_TREND, $from, $to); | ||
} | ||
|
||
/** | ||
* Get visit distribution. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function visitDistribution($from, $to) | ||
{ | ||
return $this->query(self::VISIT_DISTRIBUTION, $from, $to); | ||
} | ||
|
||
/** | ||
* Get daily retain info. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function dailyRetainInfo($from, $to) | ||
{ | ||
return $this->query(self::DAILY_RETAIN_INFO, $from, $to); | ||
} | ||
|
||
/** | ||
* Get weekly retain info. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function weeklyRetainInfo($from, $to) | ||
{ | ||
return $this->query(self::WEEKLY_RETAIN_INFO, $from, $to); | ||
} | ||
|
||
/** | ||
* Get monthly retain info. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function montylyRetainInfo($from, $to) | ||
{ | ||
return $this->query(self::MONTHLY_RETAIN_INFO, $from, $to); | ||
} | ||
|
||
/** | ||
* Get visit page. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function visitPage($from, $to) | ||
{ | ||
return $this->query(self::VISIT_PAGE, $from, $to); | ||
} | ||
|
||
/** | ||
* Unify query. | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
protected function query($api, $from, $to) | ||
{ | ||
$params = [ | ||
'begin_date' => $from, | ||
'end_date' => $to, | ||
]; | ||
|
||
return $this->parseJSON('json', [$api, $params]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
namespace EasyWeChat\tests\MiniProgram\Stats; | ||
|
||
use EasyWeChat\Tests\TestCase; | ||
use Mockery as m; | ||
|
||
class StatsTest extends TestCase | ||
{ | ||
public function getStats() | ||
{ | ||
$stats = m::mock('EasyWeChat\MiniProgram\Stats\Stats[parseJSON]', [m::mock('EasyWeChat\MiniProgram\AccessToken'), []]); | ||
$stats->shouldReceive('parseJSON')->andReturnUsing(function ($method, $params) { | ||
return [ | ||
'api' => $params[0], | ||
'params' => empty($params[1]) ? null : $params[1], | ||
]; | ||
}); | ||
|
||
return $stats; | ||
} | ||
|
||
/** | ||
* Test summaryTrend(). | ||
*/ | ||
public function testSummaryTrend() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->summaryTrend('20170313', '20170313'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170313', 'end_date' => '20170313'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test dailyVisitTrend(). | ||
*/ | ||
public function testDailyVisitTrend() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->dailyVisitTrend('20170313', '20170313'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170313', 'end_date' => '20170313'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test weeklyVisitTrend(). | ||
*/ | ||
public function testWeeklyVisitTrend() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->weeklyVisitTrend('20170306', '20170312'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170306', 'end_date' => '20170312'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test monthlyVisitTrend(). | ||
*/ | ||
public function testMonthlyVisitTrend() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->monthlyVisitTrend('20170201', '20170228'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170201', 'end_date' => '20170228'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test visitDistribution(). | ||
*/ | ||
public function testVisitDistribution() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->visitDistribution('20170313', '20170313'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170313', 'end_date' => '20170313'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test dailyRetainInfo(). | ||
*/ | ||
public function testDailyRetainInfo() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->dailyRetainInfo('20170313', '20170313'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170313', 'end_date' => '20170313'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test weeklyRetainInfo(). | ||
*/ | ||
public function testWeeklyRetainInfo() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->weeklyRetainInfo('20170306', '20170312'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170306', 'end_date' => '20170312'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test montylyRetainInfo(). | ||
*/ | ||
public function testMontylyRetainInfo() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->montylyRetainInfo('20170201', '20170228'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyretaininfo', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170201', 'end_date' => '20170228'], $result['params']); | ||
} | ||
|
||
/** | ||
* Test visitPage(). | ||
*/ | ||
public function testVisitPage() | ||
{ | ||
$stats = $this->getStats(); | ||
$result = $stats->visitPage('20170313', '20170313'); | ||
|
||
$this->assertEquals('https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage', $result['api']); | ||
$this->assertEquals(['begin_date' => '20170313', 'end_date' => '20170313'], $result['params']); | ||
} | ||
} |