如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
我这里使用的是easywechat
public function day(){
$this->open_ini();
$begin_date = date("Ymd",strtotime("-2 day"));//前天
$end_date = date("Ymd",strtotime("-1 day"));//昨天
// dd($end_date);
$url = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage?access_token=".$this->token['authorizer_access_token'];
$data = '{"begin_date":"'.$begin_date.'","end_date":'.$end_date.'"}';
$ret = object_to_array(json_decode(post_curl($url,$data))->list);
//判断是否存在
$is_save = Db::name('xcx_day_log')->where([['appid','=',session('pt_res')['appid']],['date','=',$end_date]])->find();
if(!$is_save){
foreach($ret as $k=>$vo){
$save_data = $vo;
$save_data['appid'] =session('pt_res')['appid'];
$save_data['date'] = $end_date;
Db::name('xcx_day_log')->insert($save_data);
}
}else{
dd('已创建');
}
}
private function open_ini(){
$data = session('pt_res');
$this->pt_res = $data;
$openPlatform = Facade::openPlatform(); // 开放平台
$this->app = $openPlatform->miniProgram( $this->pt_res['appid'], $this->pt_res['refreshToken']);
$accessToken = $this->app->access_token; // 获取 access token 实例
$token = $accessToken->getToken();
$this->token = $token;
}
王明昌博客
