<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Stats.php.
*
* @author overtrue <i@overtrue.me>
* @copyright 2015 overtrue <i@overtrue.me>
*
* @see https://github.com/overtrue
* @see http://overtrue.me
*/
namespace EasyWeChat\Stats;
use EasyWeChat\Core\AbstractAPI;
class Stats extends AbstractAPI
{
const API_USER_SUMMARY = 'https://api.weixin.qq.com/datacube/getusersummary';
const API_USER_CUMULATE = 'https://api.weixin.qq.com/datacube/getusercumulate';
const API_ARTICLE_SUMMARY = 'https://api.weixin.qq.com/datacube/getarticlesummary';
const API_ARTICLE_TOTAL = 'https://api.weixin.qq.com/datacube/getarticletotal';
const API_USER_READ_SUMMARY = 'https://api.weixin.qq.com/datacube/getuserread';
const API_USER_READ_HOURLY = 'https://api.weixin.qq.com/datacube/getuserreadhour';
const API_USER_SHARE_SUMMARY = 'https://api.weixin.qq.com/datacube/getusershare';
const API_USER_SHARE_HOURLY = 'https://api.weixin.qq.com/datacube/getusersharehour';
const API_UPSTREAM_MSG_SUMMARY = 'https://api.weixin.qq.com/datacube/getupstreammsg';
const API_UPSTREAM_MSG_HOURLY = 'https://api.weixin.qq.com/datacube/getupstreammsghour';
const API_UPSTREAM_MSG_WEEKLY = 'https://api.weixin.qq.com/datacube/getupstreammsgweek';
const API_UPSTREAM_MSG_MONTHLY = 'https://api.weixin.qq.com/datacube/getupstreammsgmonth';
const API_UPSTREAM_MSG_DIST_SUMMARY = 'https://api.weixin.qq.com/datacube/getupstreammsgdist';
const API_UPSTREAM_MSG_DIST_WEEKLY = 'https://api.weixin.qq.com/datacube/getupstreammsgdistweek';
const API_UPSTREAM_MSG_DIST_MONTHLY = 'https://api.weixin.qq.com/datacube/getupstreammsgdistmonth?';
const API_INTERFACE_SUMMARY = 'https://api.weixin.qq.com/datacube/getinterfacesummary';
const API_INTERFACE_SUMMARY_HOURLY = 'https://api.weixin.qq.com/datacube/getinterfacesummaryhour';
const API_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardbizuininfo';
const API_FREE_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardcardinfo';
const API_MEMBER_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardmembercardinfo';
public function userSummary($from, $to)
{
return $this->query(self::API_USER_SUMMARY, $from, $to);
}
public function userCumulate($from, $to)
{
return $this->query(self::API_USER_CUMULATE, $from, $to);
}
public function articleSummary($from, $to)
{
return $this->query(self::API_ARTICLE_SUMMARY, $from, $to);
}
public function articleTotal($from, $to)
{
return $this->query(self::API_ARTICLE_TOTAL, $from, $to);
}
public function userReadSummary($from, $to)
{
return $this->query(self::API_USER_READ_SUMMARY, $from, $to);
}
public function userReadHourly($from, $to)
{
return $this->query(self::API_USER_READ_HOURLY, $from, $to);
}
public function userShareSummary($from, $to)
{
return $this->query(self::API_USER_SHARE_SUMMARY, $from, $to);
}
public function userShareHourly($from, $to)
{
return $this->query(self::API_USER_SHARE_HOURLY, $from, $to);
}
public function upstreamMessageSummary($from, $to)
{
return $this->query(self::API_UPSTREAM_MSG_SUMMARY, $from, $to);
}
public function upstreamMessageHourly($from, $to)
{
return $this->query(self::API_UPSTREAM_MSG_HOURLY, $from, $to);
}
public function upstreamMessageWeekly($from, $to)
{
return $this->query(self::API_UPSTREAM_MSG_WEEKLY, $from, $to);
}
public function upstreamMessageMonthly($from, $to)
{
return $this->query(self::API_UPSTREAM_MSG_MONTHLY, $from, $to);
}
public function upstreamMessageDistSummary($from, $to)
{
return $this->query(self::API_UPSTREAM_MSG_DIST_SUMMARY, $from, $to);
}
public function upstreamMessageDistWeekly($from, $to)
{
return $this->query(self::API_UPSTREAM_MSG_DIST_WEEKLY, $from, $to);
}
public function upstreamMessageDistMonthly($from, $to)
{
return $this->query(self::API_UPSTREAM_MSG_DIST_MONTHLY, $from, $to);
}
public function interfaceSummary($from, $to)
{
return $this->query(self::API_INTERFACE_SUMMARY, $from, $to);
}
public function interfaceSummaryHourly($from, $to)
{
return $this->query(self::API_INTERFACE_SUMMARY_HOURLY, $from, $to);
}
public function cardSummary($from, $to, $condSource = 0)
{
$ext = [
'cond_source' => intval($condSource),
];
return $this->query(self::API_CARD_SUMMARY, $from, $to, $ext);
}
public function freeCardSummary($from, $to, $condSource = 0, $cardId = '')
{
$ext = [
'cond_source' => intval($condSource),
'card_id' => $cardId,
];
return $this->query(self::API_FREE_CARD_SUMMARY, $from, $to, $ext);
}
public function memberCardSummary($from, $to, $condSource = 0)
{
$ext = [
'cond_source' => intval($condSource),
];
return $this->query(self::API_MEMBER_CARD_SUMMARY, $from, $to, $ext);
}
protected function query($api, $from, $to, array $ext = [])
{
$params = [
'begin_date' => $from,
'end_date' => $to,
];
if (!empty($ext)) {
$params = array_merge($params, $ext);
}
return $this->parseJSON('json', [$api, $params]);
}
}