zoukankan      html  css  js  c++  java
  • 微信接口分析数据接口 使用

    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
  • 相关阅读:
    《大话数据结构》第9章 排序 9.9 快速排序(下)
    [HTML5 DOM] dispatchEvent
    [AWS SAP] Exam Tips 2 Continues Improvement for Existing Solutions
    遇见C++ PPL:C++ 的并行和异步
    遇见C++ AMP:在GPU上做并行计算
    遇见C++ Lambda
    遇见C++ AMP:GPU的线程模型和内存模型
    服务器推技术
    转http状态码
    extjs同步与异步请求互换
  • 原文地址:https://www.cnblogs.com/hgj123/p/4810405.html
Copyright © 2011-2022 走看看