PHP code example of bruin / baidu-tongji
1. Go to this page and download the library: Download bruin/baidu-tongji library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bruin / baidu-tongji example snippets
$this->app->register(\Bruin\BaiduTongji\BaiduTongjiServiceProvider::class);
public function boot()
{
$this->app->configure('baidu_tongji');
}
Bruin\BaiduTongji\BaiduTongjiServiceProvider::class
php artisan vendor:publish
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);
}
}
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);
}
}