diff --git a/src/Bean/OfficialAccount/DataCubeRequest.php b/src/Bean/OfficialAccount/DataCubeRequest.php new file mode 100644 index 0000000..14a04ef --- /dev/null +++ b/src/Bean/OfficialAccount/DataCubeRequest.php @@ -0,0 +1,158 @@ +toArray(null, SplBean::FILTER_NOT_NULL); + + return new SplArray($data); + } + + public function setAdSlot($adSlot) + { + $this->ad_slot = $adSlot; + } + + public function getAdSlot() + { + return $this->ad_slot; + } + + public function setTotalNum($totalNum) + { + $this->total_num = $totalNum; + } + + public function getTotalNum() + { + return $this->total_num; + } + + public function setSummary($summary) + { + $this->summary = $summary; + } + + public function getSummary() + { + return $this->summary; + } + + public function setBaseResp($baseResp) + { + $this->base_resp = $baseResp; + } + + public function getBaseResp() + { + return $this->base_resp; + } + + /** + * @param string $beginDate + */ + public function setBeginDate(string $beginDate) :void + { + $this->begin_date = $beginDate; + } + + /** + * @return null|string + */ + public function getBeginDate() : ?string + { + return $this->begin_date; + } + /** + * @param string $endDate + */ + public function setEndDate(string $endDate) :void + { + $this->end_date = $endDate; + } + + /** + * @return null|string + */ + public function getEndDate() : ?string + { + return $this->end_date; + } + + /** + * @param $list + */ + public function setList($list) + { + $this->list = $list; + } + + public function getList() + { + return $this->list; + } + + public function setPage($page) + { + $this->page = $page; + } + + public function getPage() + { + return $this->page; + } + + public function setPageSize($pageSize) + { + $this->page_size = $pageSize; + } + + public function getPageSize() + { + return $this->page_size; + } + + public function setStartDate($startDate) + { + $this->start_date= $startDate; + } + + public function getStartDate() + { + return $this->start_date; + } + + + + +} \ No newline at end of file diff --git a/src/OfficialAccount/ApiUrl.php b/src/OfficialAccount/ApiUrl.php index 4d20b68..ebd0e97 100644 --- a/src/OfficialAccount/ApiUrl.php +++ b/src/OfficialAccount/ApiUrl.php @@ -508,6 +508,106 @@ class ApiUrl */ const JSAPI_GET_TICKET = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi'; + /** + * 获取用户增减数据 + */ + const GET_USER_SUMMARY = 'https://api.weixin.qq.com/datacube/getusersummary?access_token=ACCESS_TOKEN'; + + /** + * 获取累计用户数据 + */ + const GET_USER_CUMULATE = 'https://api.weixin.qq.com/datacube/getusercumulate?access_token=ACCESS_TOKEN'; + + /** + * 获取图文群发每日数据 + */ + const GET_ARTICLE_SUMMARY = 'https://api.weixin.qq.com/datacube/getarticlesummary?access_token=ACCESS_TOKEN'; + + /** + * 获取图文群发总数据 + */ + const GET_ARTICLE_TOTAL = 'https://api.weixin.qq.com/datacube/getarticletotal?access_token=ACCESS_TOKEN'; + + /** + * 获取图文统计数据 + */ + const GET_USER_READ = 'https://api.weixin.qq.com/datacube/getuserread?access_token=ACCESS_TOKEN'; + + /** + * 获取图文统计分时数据 + */ + const GET_USER_READ_HOUR = 'https://api.weixin.qq.com/datacube/getuserreadhour?access_token=ACCESS_TOKEN'; + + /** + * 获取图文分享转发数据 + */ + const GET_USER_SHARE = 'https://api.weixin.qq.com/datacube/getusershare?access_token=ACCESS_TOKEN'; + + /** + * 获取图文分享转发分时数据 + */ + const GET_USER_SHARE_HOUR = 'https://api.weixin.qq.com/datacube/getusersharehour?access_token=ACCESS_TOKEN'; + + /** + * 获取消息发送概况数据 + */ + const GET_UP_STREAM_MSG = 'https://api.weixin.qq.com/datacube/getupstreammsg?access_token=ACCESS_TOKEN'; + + /** + * 获取消息分送分时数据 + */ + const GET_UP_STREAM_MSG_HOUR = 'https://api.weixin.qq.com/datacube/getupstreammsghour?access_token=ACCESS_TOKEN'; + + /** + * 获取消息发送周数据 + */ + const GET_UP_STREAM_MSG_WEEK = 'https://api.weixin.qq.com/datacube/getupstreammsgweek?access_token=ACCESS_TOKEN'; + + /** + * 获取消息发送月数据 + */ + const GET_UP_STREAM_MSG_MONTH = 'https://api.weixin.qq.com/datacube/getupstreammsgmonth?access_token=ACCESS_TOKEN'; + + /** + * 获取消息发送分布数据 + */ + const GET_UP_STREAM_MSG_DIST = 'https://api.weixin.qq.com/datacube/getupstreammsgdist?access_token=ACCESS_TOKEN'; + + /** + * 获取消息发送分布周数据 + */ + const GET_UP_STREAM_MSG_DIST_WEEK = 'https://api.weixin.qq.com/datacube/getupstreammsgdistweek?access_token=ACCESS_TOKEN'; + + /** + * 获取消息发送分布月数据 + */ + const GET_UP_STREAM_MSG_DIST_MONTH = 'https://api.weixin.qq.com/datacube/getupstreammsgdistmonth?access_token=ACCESS_TOKEN'; + + /** + * 获取公众号分广告位数据 + */ + const PUBLISHER_ADPOS_GENERAL = 'https://api.weixin.qq.com/publisher/stat?action=publisher_adpos_general&access_token=ACCESS_TOKEN'; + + /** + * 获取公众号返佣商品数据 + */ + const PUBLISHER_CPS_GENERAL = 'https://api.weixin.qq.com/publisher/stat?action=publisher_cps_general&access_token=ACCESS_TOKEN'; + + /** + * 获取公众号结算收入数据及结算主体信息 + */ + const PUBLISHER_SETTLEMENT = 'https://api.weixin.qq.com/publisher/stat?action=publisher_settlement&access_token=ACCESS_TOKEN'; + + /** + * 获取接口分析数据 + */ + const GET_INTERFACE_SUMMARY = 'https://api.weixin.qq.com/datacube/getinterfacesummary?access_token=ACCESS_TOKEN'; + + /** + * 获取接口分析分时数据 + */ + const GET_INTERFACE_SUMMARY_HOUR = 'https://api.weixin.qq.com/datacube/getinterfacesummaryhour?access_token=ACCESS_TOKEN'; + /** * @param string $baseUrl * @param array $data diff --git a/src/OfficialAccount/DataCube.php b/src/OfficialAccount/DataCube.php new file mode 100644 index 0000000..fe3fad0 --- /dev/null +++ b/src/OfficialAccount/DataCube.php @@ -0,0 +1,334 @@ +send($dataCubeRequest, ApiUrl::GET_INTERFACE_SUMMARY_HOUR); + } + + /** + * 获取接口分析数据(最大时间跨度30) + * + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getInterfaceSummary(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_INTERFACE_SUMMARY); + } + + /** + * 获取公众号结算收入数据及结算主体信息 + * + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function publisherSettlement(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::PUBLISHER_SETTLEMENT); + } + + /** + * 获取公众号返佣商品数据(最大时间跨度60) + * + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function publisherCpsGeneral(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::PUBLISHER_CPS_GENERAL); + } + + /** + * 获取公众号分广告位数据(最大时间跨度90) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function publisherAdposGeneral(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::PUBLISHER_ADPOS_GENERAL); + } + + /** + * 获取消息发送分布月数据(最大时间跨度30) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUpStreamMsgDistMonth(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_UP_STREAM_MSG_DIST_MONTH); + } + + /** + * 获取消息发送分布周数据(最大时间跨度30) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUpStreamMsgDistWeek(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_UP_STREAM_MSG_DIST_WEEK); + } + + /** + * 获取消息发送分布数据(最大时间跨度15) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUpStreamMsgDist(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_UP_STREAM_MSG_DIST); + } + + /** + * 获取消息发送月数据(最大时间跨度30) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUpStreamMsgMonth(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_UP_STREAM_MSG_MONTH); + } + + /** + * 获取消息发送周数据(最大时间跨度30) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUpStreamMsgWeek(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_UP_STREAM_MSG_WEEK); + } + + /** + * 获取消息发送分时数据(最大时间跨度1) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUpStreamMsgHour(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_UP_STREAM_MSG_HOUR); + } + + /** + * 获取消息发送概况数据(最大时间跨度7) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUpStreamMsg(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_UP_STREAM_MSG); + } + + /** + * 获取图文分享转发分时数据(最大时间跨度1) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUserShareHour(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_USER_SHARE_HOUR); + } + + /** + * 获取图文分享转发数据(最大时间跨度7) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUserShare(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_USER_SHARE); + } + + /** + * 获取图文统计分时数据(最大时间跨度1) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUserReadHour(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_USER_READ_HOUR); + } + + /** + * 获取图文统计数据(最大时间跨度3) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUserRead(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_USER_READ); + } + + /** + * 获取图文群发总数据(最大时间跨度1) + * + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getArticleTotal(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_ARTICLE_TOTAL); + } + + /** + * 获取图文群发每日数据(最大时间跨度1) + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getArticleSummary(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_ARTICLE_SUMMARY); + } + + /** + * 获取累计用户数据(最大时间跨度7) + * + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUserCumulate(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_USER_CUMULATE); + } + + /** + * 获取永不增减数据(最大时间跨度7) + * + * @param DataCubeRequest $dataCubeRequest + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + public function getUserSummary(DataCubeRequest $dataCubeRequest) + { + return $this->send($dataCubeRequest, ApiUrl::GET_USER_SUMMARY); + } + + /** + * @param DataCubeRequest $dataCubeRequest + * @param string $url + * + * @return DataCubeRequest + * @throws OfficialAccountError + * @throws \EasySwoole\HttpClient\Exception\InvalidUrl + * @throws \EasySwoole\WeChat\Exception\RequestError + */ + private function send(DataCubeRequest $dataCubeRequest, string $url) + { + $url = ApiUrl::generateURL($url, [ + 'ACCESS_TOKEN' => $this->getOfficialAccount()->accessToken()->getToken() + ]); + + $data = $dataCubeRequest->buildRequest()->getArrayCopy(); + + $response = NetWork::postJsonForJson($url, $data); + + $ex = OfficialAccountError::hasException($response); + + if ($ex) { + throw $ex; + } else { + return new DataCubeRequest($response); + } + } +} \ No newline at end of file diff --git a/src/OfficialAccount/OfficialAccount.php b/src/OfficialAccount/OfficialAccount.php index fbd1b65..9a84f5d 100644 --- a/src/OfficialAccount/OfficialAccount.php +++ b/src/OfficialAccount/OfficialAccount.php @@ -30,6 +30,7 @@ class OfficialAccount private $service; private $groupSending; private $comment; + private $dataCube; public function onError(callable $onError) { @@ -162,6 +163,14 @@ public function comment(): Comment return $this->comment; } + public function dataCube(): DataCube + { + if (!isset($this->dataCube)) { + $this->dataCube = new DataCube($this); + } + return $this->dataCube; + } + public function getConfig(): OfficialAccountConfig { return $this->config;