<?php $appid = "xxxxxxxxxx"; $secret = "xxxxxxxxxxxxxxxxxxxxxxxxx"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret; function https_request($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); return $jsoninfo; } $code = https_request($url); function curlExec($url,$data=null){ $postJosnData = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postJosnData); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $sourceInfo = json_decode(curl_exec($ch)); echo "<pre>"; print_r($sourceInfo);exit; curl_close($ch); } //获取所有素材列表 $customer_url = 'https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token='.$code['access_token'];//地址 $post_fields = array(); //以下两项不需要修改 $post_fields['type'] = 'news'; $post_fields['offset'] = '0'; $post_fields['count'] = '2'; // $buildingList = curlExec($customer_url,$post_fields); //获取单一素材详情 $row_url = 'https://api.weixin.qq.com/cgi-bin/material/get_material?access_token='.$code['access_token'];//地址 $row = array(); //以下两项不需要修改 $row['access_token'] = $code['access_token']; $row['media_id'] = 'njxothwKIB9tCEpdP4V-5yne0cSJ84QHo91Jr1NBc2A'; // $buildingList = curlExec($row_url,$row); //获取公众号粉丝分析 unset($row); $data_url = 'https://api.weixin.qq.com/datacube/getusersummary?access_token='.$code['access_token'];//地址 $row = array(); //以下两项不需要修改 $row['access_token'] = $code['access_token']; $row['begin_date'] = '2016-05-23'; $row['end_date'] = '2016-05-24'; // $buildingList = curlExec($data_url,$row); //获取公众号粉丝分析 unset($row); $data_url = 'https://api.weixin.qq.com/datacube/getarticlesummary?access_token='.$code['access_token'];//地址 $row = array(); //以下两项不需要修改 $row['access_token'] = $code['access_token']; $row['begin_date'] = '2016-05-24'; $row['end_date'] = '2016-05-24'; $buildingList = curlExec($data_url,$row); ?>