Browse Source

优化getDatacube方法

dodgepudding 10 years ago
parent
commit
a14f26bd78
2 changed files with 43 additions and 42 deletions
  1. 19 19
      README.md
  2. 24 23
      wechat.class.php

+ 19 - 19
README.md

@@ -206,28 +206,28 @@ const EVENT_CARD_USER_DEL = 'user_del_card';        //卡券 - 用户删除卡
  *  deleteKFAccount($account) 删除客服账号
  *  setKFHeadImg($account,$imgfile) 上传客服头像
  *  querySemantic($uid,$query,$category,$latitude=0,$longitude=0,$city="",$region="") 语义理解接口 参数含义及返回的json内容请查看 **[微信语义理解接口](http://mp.weixin.qq.com/wiki/index.php?title=语义理解)**
- *  getDatacube($type,$num,$begin_date,$end_date='') 获取统计数据 参数需注意$type与$num的定义
+ *  getDatacube($type,$subtype,$begin_date,$end_date='') 获取统计数据 参数需注意$type与$subtype的定义
 > 获取统计数据方法 参数定义
 > 
-| 数据分类 | $type值(字符串)  | 数据子分类 | $num值(整数型) | 时间跨度(天) |
+| 数据分类 | $type值(字符串)  | 数据子分类 | $subtype值(字符串) | 时间跨度(天) |
 | --------- | :-------:  | --------- | :------: | ----: |
-| 用户分析 | 'user' | 获取用户增减数据 | 1 | 7 |
-| 用户分析 | 'user' | 获取累计用户数据 | 2 | 7 |
-| 图文分析 | 'article' | 获取图文群发每日数据 | 1 | 1 |
-| 图文分析 | 'article' | 获取图文群发总数据 | 2 | 1 |
-| 图文分析 | 'article' | 获取图文统计数据 | 3 | 3 |
-| 图文分析 | 'article' | 获取图文统计分时数据 | 4 | 1 |
-| 图文分析 | 'article' | 获取图文分享转发数据 | 5 | 7 |
-| 图文分析 | 'article' | 获取图文分享转发分时数据 | 6 | 1 |
-| 消息分析 | 'upstreammsg' | 获取消息发送概况数据 | 1 | 7 |
-| 消息分析 | 'upstreammsg' | 获取消息分送分时数据 | 2 | 1 |
-| 消息分析 | 'upstreammsg' | 获取消息发送周数据 | 3 | 30 |
-| 消息分析 | 'upstreammsg' | 获取消息发送月数据 | 4 | 30 |
-| 消息分析 | 'upstreammsg' | 获取消息发送分布数据 | 5 | 15 |
-| 消息分析 | 'upstreammsg' | 获取消息发送分布周数据 | 6 | 30 |
-| 消息分析 | 'upstreammsg' | 获取消息发送分布月数据 | 7 | 30 |
-| 接口分析 | 'interface' | 获取接口分析数据 | 1 | 30 |
-| 接口分析 | 'interface' | 获取接口分析分时数据 | 2 | 1 |
+| 用户分析 | 'user' | 获取用户增减数据 | 'summary' | 7 |
+| 用户分析 | 'user' | 获取累计用户数据 | 'cumulate' | 7 |
+| 图文分析 | 'article' | 获取图文群发每日数据 | 'summary' | 1 |
+| 图文分析 | 'article' | 获取图文群发总数据 | 'total' | 1 |
+| 图文分析 | 'article' | 获取图文统计数据 | 'read' | 3 |
+| 图文分析 | 'article' | 获取图文统计分时数据 | 'readhour' | 1 |
+| 图文分析 | 'article' | 获取图文分享转发数据 | 'share' | 7 |
+| 图文分析 | 'article' | 获取图文分享转发分时数据 | 'sharehour' | 1 |
+| 消息分析 | 'upstreammsg' | 获取消息发送概况数据 | 'summary' | 7 |
+| 消息分析 | 'upstreammsg' | 获取消息分送分时数据 | 'hour' | 1 |
+| 消息分析 | 'upstreammsg' | 获取消息发送周数据 | 'week' | 30 |
+| 消息分析 | 'upstreammsg' | 获取消息发送月数据 | 'month' | 30 |
+| 消息分析 | 'upstreammsg' | 获取消息发送分布数据 | 'dist' | 15 |
+| 消息分析 | 'upstreammsg' | 获取消息发送分布周数据 | 'distweek' | 30 |
+| 消息分析 | 'upstreammsg' | 获取消息发送分布月数据 | 'distmonth' | 30 |
+| 接口分析 | 'interface' | 获取接口分析数据 | 'summary' | 30 |
+| 接口分析 | 'interface' | 获取接口分析分时数据 | 'summaryhour' | 1 |
 需要注意 `begin_date`和`end_date`的差值需小于“最大时间跨度”(比如最大时间跨度为1时,`begin_date`和`end_date`的差值只能为0,才能小于1)
 
  *  createCard($data) 创建卡券

+ 24 - 23
wechat.class.php

@@ -150,35 +150,36 @@ class Wechat
 	const CARD_MOVIETICKET_UPDATEUSER     = '/card/movieticket/updateuser?';   //更新电影票(未加方法)
 	const CARD_BOARDINGPASS_CHECKIN       = '/card/boardingpass/checkin?';     //飞机票-在线选座(未加方法)
 	const CARD_LUCKYMONEY_UPDATE          = '/card/luckymoney/updateuserbalance?';     //更新红包金额
+	const SEMANTIC_API_URL = '/semantic/semproxy/search?'; //语义理解
 	///数据分析接口
-	const DATACUBE_URL_ARR = array(        //用户分析
+	static $DATACUBE_URL_ARR = array(        //用户分析
 	        'user' => array(
-	                1 => '/datacube/getusersummary?',		//获取用户增减数据(getusersummary)
-	                2 => '/datacube/getusercumulate?',		//获取累计用户数据(getusercumulate)
+	                'summary' => '/datacube/getusersummary?',		//获取用户增减数据(getusersummary)
+	                'cumulate' => '/datacube/getusercumulate?',		//获取累计用户数据(getusercumulate)
 	        ),
 	        'article' => array(            //图文分析
-	                1 => '/datacube/getarticlesummary?',		//获取图文群发每日数据(getarticlesummary)
-	                2 => '/datacube/getarticletotal?',		//获取图文群发总数据(getarticletotal)
-	                3 => '/datacube/getuserread?',			//获取图文统计数据(getuserread)
-	                4 => '/datacube/getuserreadhour?',		//获取图文统计分时数据(getuserreadhour)
-	                5 => '/datacube/getusershare?',			//获取图文分享转发数据(getusershare)
-	                6 => '/datacube/getusersharehour?',		//获取图文分享转发分时数据(getusersharehour)
+	                'summary' => '/datacube/getarticlesummary?',		//获取图文群发每日数据(getarticlesummary)
+	                'total' => '/datacube/getarticletotal?',		//获取图文群发总数据(getarticletotal)
+	                'read' => '/datacube/getuserread?',			//获取图文统计数据(getuserread)
+	                'readhour' => '/datacube/getuserreadhour?',		//获取图文统计分时数据(getuserreadhour)
+	                'share' => '/datacube/getusershare?',			//获取图文分享转发数据(getusershare)
+	                'sharehour' => '/datacube/getusersharehour?',		//获取图文分享转发分时数据(getusersharehour)
 	        ),
 	        'upstreammsg' => array(        //消息分析
-	                1 => '/datacube/getupstreammsg?',		//获取消息发送概况数据(getupstreammsg)
-					2 => '/datacube/getupstreammsghour?',	//获取消息分送分时数据(getupstreammsghour)
-	                3 => '/datacube/getupstreammsgweek?',	//获取消息发送周数据(getupstreammsgweek)
-	                4 => '/datacube/getupstreammsgmonth?',	//获取消息发送月数据(getupstreammsgmonth)
-	                5 => '/datacube/getupstreammsgdist?',	//获取消息发送分布数据(getupstreammsgdist)
-	                6 => '/datacube/getupstreammsgdistweek?',	//获取消息发送分布周数据(getupstreammsgdistweek)
-	                7 => '/datacube/getupstreammsgdistmonth?',	//获取消息发送分布月数据(getupstreammsgdistmonth)
+	                'summary' => '/datacube/getupstreammsg?',		//获取消息发送概况数据(getupstreammsg)
+					'hour' => '/datacube/getupstreammsghour?',	//获取消息分送分时数据(getupstreammsghour)
+	                'week' => '/datacube/getupstreammsgweek?',	//获取消息发送周数据(getupstreammsgweek)
+	                'month' => '/datacube/getupstreammsgmonth?',	//获取消息发送月数据(getupstreammsgmonth)
+	                'dist' => '/datacube/getupstreammsgdist?',	//获取消息发送分布数据(getupstreammsgdist)
+	                'distweek' => '/datacube/getupstreammsgdistweek?',	//获取消息发送分布周数据(getupstreammsgdistweek)
+	               	'distmonth' => '/datacube/getupstreammsgdistmonth?',	//获取消息发送分布月数据(getupstreammsgdistmonth)
 	        ),
 	        'interface' => array(        //接口分析
-	                1 => '/datacube/getinterfacesummary?',	//获取接口分析数据(getinterfacesummary)
-	                2 => '/datacube/getinterfacesummaryhour?',	//获取接口分析分时数据(getinterfacesummaryhour)
+	                'summary' => '/datacube/getinterfacesummary?',	//获取接口分析数据(getinterfacesummary)
+	                'summaryhour' => '/datacube/getinterfacesummaryhour?',	//获取接口分析分时数据(getinterfacesummaryhour)
 	        )
 	);
-	const SEMANTIC_API_URL= '/semantic/semproxy/search?';
+	
 
 	private $token;
 	private $encodingAesKey;
@@ -1786,20 +1787,20 @@ class Wechat
 	/**
 	 * 获取统计数据
 	 * @param string $type  数据分类(user|article|upstreammsg|interface)分别为(用户分析|图文分析|消息分析|接口分析)
-	 * @param string $num   数据子分类,参考 DATACUBE_URL_ARR 常量定义部分 或者README.md说明文档
+	 * @param string $subtype   数据子分类,参考 DATACUBE_URL_ARR 常量定义部分 或者README.md说明文档
 	 * @param string $begin_date 开始时间
 	 * @param string $end_date   结束时间
 	 * @return boolean|array 成功返回查询结果数组,其定义请看官方文档
 	 */
-	public function getDatacube($type,$num,$begin_date,$end_date=''){
+	public function getDatacube($type,$subtype,$begin_date,$end_date=''){
 	    if (!$this->access_token && !$this->checkAuth()) return false;
-		if (!isset(self::DATACUBE_URL_ARR[$type]) || !isset(self::DATACUBE_URL_ARR[$type][$num]))
+		if (!isset(self::$DATACUBE_URL_ARR[$type]) || !isset(self::$DATACUBE_URL_ARR[$type][$subtype]))
 			return false;
 	    $data = array(
             'begin_date'=>$begin_date,
             'end_date'=>$end_date?$end_date:$begin_date
 	    );
-	    $result = $this->http_post(self::API_URL_PREFIX.self::DATACUBE_URL_ARR[$type][$num].'access_token='.$this->access_token,self::json_encode($data));
+	    $result = $this->http_post(self::API_URL_PREFIX.self::$DATACUBE_URL_ARR[$type][$subtype].'access_token='.$this->access_token,self::json_encode($data));
 	    if ($result)
 	    {
 	        $json = json_decode($result,true);