lumen-baidutongji
请参考百度统计文档使用,本项目适用lumen和laravel集成包
安装
- 安装包文件
composer require Bruin/baidu-tongji
配置
lumen 应用
- 注册
AppServiceProvider
:
$this->app->register(\Bruin\BaiduTongji\BaiduTongjiServiceProvider::class);
- 创建配置文件:
public function boot()
{
$this->app->configure('baidu_tongji');
}
- 复制应用根目录下的
config/baidu_tongji.php
;
laravel 应用
- 注册
ServiceProvider
:
Bruin\BaiduTongji\BaiduTongjiServiceProvider::class
- 创建配置文件:
php artisan vendor:publish
- 修改应用根目录下的
config/baidu_tongji.php
使用 lumen
<?php
namespace App\Http\Controllers;
use Bruin\BaiduTongji\BaiduTongji;
class SiteController extends Controller
{
public function index()
{
$today=date('Ymd');
$yesterday=date('Ymd',strtotime('yesterday'));
$baiduTongji = new BaiduTongji(config('baidu_tongji'));
$result=$baiduTongji->getData([
'method' => 'trend/time/a',
'start_date' => $today,
'end_date' => $today,
'start_date2' => $yesterday,
'end_date2' => $yesterday,
'metrics' => 'pv_count,visitor_count',
'max_results' => 0,
'gran' => 'day',
]);
dd($result);
}
}
使用 laravel
<?php
namespace App\Http\Controllers;
class SiteController extends Controller
{
public function index()
{
$today=date('Ymd');
$yesterday=date('Ymd',strtotime('yesterday'));
$baiduTongji = resolve('BaiduTongji');
$result=$baiduTongji->getData([
'method' => 'trend/time/a',
'start_date' => $today,
'end_date' => $today,
'start_date2' => $yesterday,
'end_date2' => $yesterday,
'metrics' => 'pv_count,visitor_count',
'max_results' => 0,
'gran' => 'day',
]);
dd($result);
}
}