Usage example of the WeChat data statistics interface for php, and data statistics example

Source: Internet
Author: User

Php version data statistics Interface Usage example, data statistics example

This example describes the usage of the php Data Statistics interface. We will share this with you for your reference. The details are as follows:

The php version of the data statistics interface is actually very easy to use. The previous version does not have this function, but later versions are added. The following is an example of the php version of the data statistics interface:

In January 6, a new data analysis interface portal was released:

Note:

1. The database of public account data on the Interface side only stores data after January 1, December 1, 2014. The data before this date cannot be queried. Even if it is found, it is untrusted dirty data;

2. Ask the developer to save the data in their own database after calling the interface to get the data, that is, to speed up the next user access and reduce the unnecessary consumption of the side interface call.

The user analysis data interface is used to obtain the user analysis data in the data statistics module of the official website of the public platform. The specific interface list is as follows (there is no user attribute data interface currently ):

The maximum time span refers to the time range in which data can be obtained during an API call. For example, if the maximum time span is 7, the data can be obtained for up to seven days at a time. You can use "Get access_token" to obtain the actual value of access_token.

API call request description

The user analysis data interface (including all interfaces in the interface list) needs to POST the following sample data packet to the corresponding interface call address:

{  "begin_date": "2014-12-02",  "end_date": "2014-12-07"}

Call parameter description:

After a rough look, it is still in the internal test phase. However, because it is a new interface, we need to improve the class of the advanced interface used on this site. Modify as follows:

Add a new interface constant to the class:

API_DATA_CUBE_URL = 'https://api.weixin.qq.com/datacube',API_TYPE_DATA = 'datacube'

Modify the call method: because it requires that the URL parameter is only an access token, so it is the same as the previous JSON, but the datacube judgment should be added to the judgment (Note: The comment has already been described ):

Public function call ($ api_name, $ params = array (), $ type = self: GET, $ api_type = self: API_TYPE_CGI) {// After datacube is added, use switch to group interface URL switch (true) {case $ api_type = self: API_TYPE_PAY: $ url = self: PAY_URL. $ api_name; break; case $ api_type = self: API_TYPE_DATA: $ url = self: API_DATA_CUBE_URL. $ api_name; break; default: $ url = self: API_URL_PREFIX. $ api_name;} if (in_array ($ api_name, self: $ _ no_n Eed_token_apis) {$ res = $ this-> request ($ url, $ params, $ type); if ($ res) {return $ res ;}} $ this-> _ access_token = $ this-> getAccessToken (); if ($ this-> _ access_token) {// Add multiple or conditions with access_token if ($ type = self: JSON | $ api_type = self: API_TYPE_DATA) {$ url = $ url. '? Access_token = '. $ this-> _ access_token;} else {$ params ['Access _ token'] = $ this-> _ access_token;} $ res = $ this-> request ($ url, $ params, $ type); if ($ res) {return $ res ;}} return false ;}

Finally, call a getinterfacesummary interface in the CLI method call document (note: the interface is POST ):

if (isset($argc) && $argc >= 1 && $argv[0] == __FILE__) {  $client = new WechatJSON(array(    WechatJSON::APP_ID => 'wx78sfsd023744d51',    WechatJSON::APP_SECRET => '9ba3476db1fsfsff512esf2f630fb9',  ));  $res = $client->call('/getinterfacesummary', array(    'begin_date' => '2014-12-01',    'end_date' => '2014-12-31'  ), WechatJSON::POST, WechatJSON::API_TYPE_DATA);  if (!$res) {    var_dump($client->_error);  }  var_dump($res);}

The running result, although the API is not authorized (after all, the qualified partner in the internal test has the information, and the public account will wait ):

Note: in the future, we will create a linux task so that the backend can perform the task at intervals (one week or 30 days) because the data statistics interface has 7 days and 30 days. In this way, the data is retrieved and then written into the database table to generate graph reports, saving some statistics that have been officially provided to you by log!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.