search
HomeBackend DevelopmentPHP TutorialDetailed explanation of usage examples of WeChat data statistics interface in PHP version

This article mainly introduces the usage of the PHP version of the WeChat data statistics interface, and analyzes the functions of the PHP WeChat data statistics interface and related usage skills in the form of examples. Friends in need can refer to the following

The examples in this article describe How to use the PHP version of WeChat data statistics interface. I share it with you for your reference. The details are as follows:

The php version of the WeChat data statistics interface is actually very easy to use. This function was not available in the previous version but was added in later versions. Let’s take a look at a php version. Example of WeChat data statistics interface:

WeChat released a new data analysis interface portal on January 6:

Please note :

1. The public account data database on the interface side only stores data after December 1, 2014, and the query will not be able to date before that. Even if it is found, it is untrustworthy dirty data;

2. Developers are asked to save the data in their own database after calling the interface to obtain the data, which will speed up the next user's access and also reduce the cost. Unnecessary loss of WeChat side interface calls.

The user analysis data interface refers to the interface used to obtain 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 yet):

Maximum time The span refers to the maximum time range that can obtain data during an interface call. For example, the maximum time span is 7, which means that up to 7 days of data can be obtained at one time. Please obtain the actual value of access_token through "Get access_token".

Interface 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"
}

Instructions for calling parameters:

After a rough look, it is still in the internal testing stage, but because it is a new interface, it needs to be improved. The class of WeChat advanced interface used by this site. Modify as follows:

Add new interface constants 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 the access token, it is the same as the previous JSON, but datacube must be added to the judgment. Judgment (Note: Comment has been explained):

public function call($api_name, $params = array(), $type = self::GET, $api_type = self::API_TYPE_CGI) {
    //加入datacube后,用switch来组接口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_need_token_apis)) {
      $res = $this->request($url, $params, $type);
      if ($res) {
        return $res;
      }
    }
    $this->_access_token = $this->getAccessToken();
    if ($this->_access_token) {
      //加多个or判断带上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, the CLI method calls a getinterfacesummary interface in the document Debugging (Note: It is the POST method to the interface):

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 is that although the API is not authorized (after all, the qualified partners of the internal test have the information, just wait for the public account):

Postscript, I will do a Linux task later. The background itself checks every period of time (a week or 30 days) because some data statistics interfaces are 7 days and some are 30 days. In this way, the data is obtained and then written into the database table to generate graphic reports, saving you the time of logging some statistics that the official has already logged for you!

The above is the detailed content of Detailed explanation of usage examples of WeChat data statistics interface in PHP version. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

使用MySQL创建数据统计表实现数据分析功能使用MySQL创建数据统计表实现数据分析功能Jul 01, 2023 pm 05:36 PM

使用MySQL创建数据统计表实现数据分析功能在大数据时代,数据分析成为了决策的重要依据。而MySQL作为一款常用的关系型数据库,也可以通过创建数据统计表来实现数据分析的功能。本文将介绍如何利用MySQL的特性创建数据统计表,并通过代码示例演示其使用方法。首先,我们需要定义数据统计表的结构。一般来说,数据统计表包含两部分:维度和度量。维度是描述数据的属性,如时

php怎么设置implode没有分隔符php怎么设置implode没有分隔符Apr 18, 2022 pm 05:39 PM

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

PHP快手API接口教程:如何实现用户数据的分析和统计PHP快手API接口教程:如何实现用户数据的分析和统计Jul 21, 2023 pm 04:53 PM

PHP快手API接口教程:如何实现用户数据的分析和统计随着社交媒体的兴起,快手成为了许多人分享和观看短视频的热门平台之一。作为一个开发者,我们可以利用快手的API接口来进行用户数据的分析和统计。本教程将介绍如何使用PHP编程语言通过快手API接口实现用户数据的获取、分析和统计。步骤1:获取API接口密钥首先,我们需要在快手开放平台申请一个API接口密钥。在申

如何利用Laravel实现数据统计和分析功能如何利用Laravel实现数据统计和分析功能Nov 04, 2023 pm 12:09 PM

如何利用Laravel实现数据统计和分析功能Laravel是一款流行的PHP框架,提供了丰富的功能和工具,方便开发者构建高效的Web应用程序。其中,数据统计和分析是许多应用程序中不可或缺的一部分。本文将介绍如何利用Laravel框架实现数据统计和分析功能,并提供一些具体的代码示例。一、安装和配置Laravel首先,我们需要安装和配置Laravel框架。可以通

学习JavaScript中的用户行为分析和数据统计学习JavaScript中的用户行为分析和数据统计Nov 03, 2023 am 09:39 AM

学习JavaScript中的用户行为分析和数据统计,需要具体代码示例随着互联网技术的发展,用户体验和数据统计对于网站和应用程序的开发变得越来越重要。用户行为分析和数据统计能够帮助开发者了解用户在网站或应用程序中的行为模式,进而优化产品的设计和功能。在用户行为分析和数据统计中,JavaScript是一种常用的编程语言。它可以通过在网页中插入一些JavaScr

PHP实时聊天系统中的数据统计和用户行为分析PHP实时聊天系统中的数据统计和用户行为分析Aug 13, 2023 am 10:16 AM

PHP实时聊天系统中的数据统计和用户行为分析概述:随着互联网的发展和智能手机的普及,实时聊天系统成为了人们日常生活中必不可少的一部分。无论是在社交媒体平台上还是在企业内部通信中,实时聊天系统都扮演着重要的角色。本文将针对PHP实时聊天系统中的数据统计和用户行为分析方面进行探讨,并提供相关的代码示例。数据统计:实时聊天系统中的数据统计可以帮助我们了解用户的活跃

快速入门:使用Go语言函数实现简单的数据统计功能快速入门:使用Go语言函数实现简单的数据统计功能Jul 31, 2023 pm 03:45 PM

快速入门:使用Go语言函数实现简单的数据统计功能引言:Go语言作为一种简单、高效、可靠的编程语言,广泛应用于软件开发领域。其中,函数作为Go语言的核心特性之一,为程序员提供了强大的工具来解决问题。本文将介绍如何使用Go语言的函数来实现简单的数据统计功能,帮助读者更好地理解和应用Go语言的函数。一、需求分析在开始编写代码之前,我们首先需要分析清楚我们的需求,即

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.