1:参考官方文档 http://mp.weixin.qq.com/wiki/8/30ed81ae38cf4f977194bf1a5db73668.html
/**
* 微信接口统计
*/
public function wx_interface(){
$begin_date = '2015-08-16';
$end_date = '2015-09-14';
$count = $this->count_day($begin_date,$end_date);
if($count>30){
$array = array(
"msg_status" => "no",
"msg_info" => "查询时间不能超过30天",
"msg_time"=> date("Y-m-d H:i:s",time())
);
echo $this->json_array($array);
}else if($count<0){
$array = array(
"msg_status" => "no",
"msg_info" => "查询时间不能超当前时间",
"msg_time"=> date("Y-m-d H:i:s",time())
);
echo $this->json_array($array);
}else{
$arr = $this->WechatAuth->getAccessToken();
$access_token = $arr["access_token"];
$data = array(
'begin_date' => $begin_date,
'end_date' => $end_date
);
$url = C("WX_FENXI_URL")."?access_token=".$access_token;
$res = $this->WechatAuth->https_request($url,json_encode($data));
var_dump($res);
}
}
/**
* 模拟POST提交数据
* @param string $url 链接地址
* @param array $data 数组
*/
public function https_request($url,$data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return json_decode($output,true);
}
/**
* 计算时间天数
*/
public function count_day($begin_date,$end_date){
$day1 = strtotime($begin_date);
$day2 = strtotime($end_date);
return round(($day2-$day1)/3600/24);
}
打印出来的结果如下:
array (size=1)
'list' =>
array (size=10)
0 =>
array (size=5)
'ref_date' => string '2015-08-16' (length=10)
'callback_count' => int 2
'fail_count' => int 0
'total_time_cost' => int 186
'max_time_cost' => int 99
1 =>
array (size=5)
'ref_date' => string '2015-08-17' (length=10)
'callback_count' => int 6
'fail_count' => int 0
'total_time_cost' => int 560
'max_time_cost' => int 98
2 =>
array (size=5)
'ref_date' => string '2015-08-18' (length=10)
'callback_count' => int 2
'fail_count' => int 0
'total_time_cost' => int 188
'max_time_cost' => int 95
3 =>
array (size=5)
'ref_date' => string '2015-08-19' (length=10)
'callback_count' => int 1
'fail_count' => int 0
'total_time_cost' => int 97
'max_time_cost' => int 97
4 =>
array (size=5)
'ref_date' => string '2015-08-20' (length=10)
'callback_count' => int 1
'fail_count' => int 0
'total_time_cost' => int 92
'max_time_cost' => int 92
5 =>
array (size=5)
'ref_date' => string '2015-08-21' (length=10)
'callback_count' => int 3
'fail_count' => int 0
'total_time_cost' => int 280
'max_time_cost' => int 99
6 =>
array (size=5)
'ref_date' => string '2015-08-26' (length=10)
'callback_count' => int 5
'fail_count' => int 0
'total_time_cost' => int 476
'max_time_cost' => int 101
7 =>
array (size=5)
'ref_date' => string '2015-08-30' (length=10)
'callback_count' => int 3
'fail_count' => int 0
'total_time_cost' => int 280
'max_time_cost' => int 101
8 =>
array (size=5)
'ref_date' => string '2015-08-31' (length=10)
'callback_count' => int 6
'fail_count' => int 0
'total_time_cost' => int 560
'max_time_cost' => int 100
9 =>
array (size=5)
'ref_date' => string '2015-09-07' (length=10)
'callback_count' => int 1
'fail_count' => int 0
'total_time_cost' => int 92
'max_time_cost' => int 92