The practice of obtaining the reading number of articles on the WeChat public account (the request parameter does not support the article ID)
1. The new requirements are: the display of the number of articles that needs to realize the WeChat channel. as shown in Figure 1
2. In fact, the most ideal situation should be able to obtain the number of readings of this article based on the article ID, just like Douyin. View Douyin Open Platform Documents – Resource Center – Open API – Video Management – Douyin – Query Video – Query video data for specific videos. Request parameters support article ID. as shown in Figure 2
3. Check the official WeChat document – public account – data statistics – graphic analysis – interface call request description. It does not support the article ID, only the date range of the data is supported. BEGIN_DATE, the starting date of the data is obtained, the difference between BEGIN_DATE and END_DATE should be less than “Maximum time span (For example, when the maximum time span is 1, the difference between BEGIN_DATE and END_DATE can only be 0, it can be less than 1), otherwise an error will be reported. END_DATE, get the end date of the data, the maximum value that END_DATE allows to set is yesterday. as shown in Figure 3
4. Check the official WeChat document – public account – data statistics – graphic analysis – return parameter description. Please note: the msgid here is actually composed of msgid (graphic message id, which is the msg_data_id returned after the group interface call) and index (message order index), such as 12003_3, Among them, 12003 is msgid, that is, the ID of a mass message; 3 is index, assuming that there are 5 articles in the graphic and text messages sent this time (because it may be multi-graphics), 3 represents the third of the five. as shown in Figure 4
5. When the WeChat article is successfully mass posted, store the ID of the message sending task and the data ID of the message to the table. Its field type is: BIGINT. Because the maximum value of int is: 2147483647. Values less than msg_data_id: 2247483783. as shown in Figure 5
6. Post https://api.weixin.qq.com/datacube/GetArticleTotal?access_token={access_token} , the response is as follows, as shown in Figure 6
{
"begin_date": "2020-11-13",
"end_date": "2020-11-13"
}
{
"list":[
{
"ref_date": "2020-11-13",
"msgid": "2247483782_1",
"title": "33333r",
"user_source": 0,
"details": [
{
"stat_date": "2020-11-13",
"target_user": 356,
"int_page_read_user": 51,
"int_page_read_count": 68,
"ori_page_read_user": 4,
"ori_page_read_count": 6,
"share_user": 1,
"share_count": 1,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 51,
"int_page_from_session_read_count": 68,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-14",
"target_user": 356,
"int_page_read_user": 64,
"int_page_read_count": 82,
"ori_page_read_user": 5,
"ori_page_read_count": 7,
"share_user": 1,
"share_count": 1,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 64,
"int_page_from_session_read_count": 82,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-15",
"target_user": 356,
"int_page_read_user": 64,
"int_page_read_count": 84,
"ori_page_read_user": 6,
"ori_page_read_count": 8,
"share_user": 1,
"share_count": 1,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 64,
"int_page_from_session_read_count": 84,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-16",
"target_user": 356,
"int_page_read_user": 64,
"int_page_read_count": 84,
"ori_page_read_user": 6,
"ori_page_read_count": 8,
"share_user": 1,
"share_count": 1,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 64,
"int_page_from_session_read_count": 84,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-17",
"target_user": 356,
"int_page_read_user": 65,
"int_page_read_count": 86,
"ori_page_read_user": 6,
"ori_page_read_count": 8,
"share_user": 1,
"share_count": 1,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 65,
"int_page_from_session_read_count": 86,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
}
]#ATFP_CLOSE_Translate_span#,
"url": "https://mp.weixin.qq.com/s?__biz=mzixnjcymzkZoq==&mid=22 47483782&idx=1&sn=06aa625b6f4b908a91776bf2e9a8c00e#rd"
},
{
"ref_date": "2020-11-13",
"msgid": "2247483782_2",
"title": "22222",
"user_source": 0,
"details":[
{
"stat_date": "2020-11-13",
"target_user": 356,
"int_page_read_user": 21,
"int_page_read_count": 25,
"ori_page_read_user": 0,
"ori_page_read_count": 0,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 21,
"int_page_from_session_read_count": 25,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-14",
"target_user": 356,
"int_page_read_user": 30,
"int_page_read_count": 37,
"ori_page_read_user": 0,
"ori_page_read_count": 0,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 30,
"int_page_from_session_read_count": 37,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-15",
"target_user": 356,
"int_page_read_user": 31,
"int_page_read_count": 39,
"ori_page_read_user": 0,
"ori_page_read_count": 0,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 31,
"int_page_from_session_read_count": 39,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-16",
"target_user": 356,
"int_page_read_user": 31,
"int_page_read_count": 39,
"ori_page_read_user": 0,
"ori_page_read_count": 0,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 31,
"int_page_from_session_read_count": 39,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-17",
"target_user": 356,
"int_page_read_user": 32,
"int_page_read_count": 40,
"ori_page_read_user": 0,
"ori_page_read_count": 0,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 32,
"int_page_from_session_read_count": 40,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 0,
"int_page_from_other_read_count": 0,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
}
]#ATFP_CLOSE_Translate_span#,
"url": "https://mp.weixin.qq.com/s?__biz=mzixnjcymzkZoq==&mid=22 47483782&IDX=2&SN=AD6130AFFC4EBFFF8D7A95D89F8B6C7#RD"
},
{
"ref_date": "2020-11-13",
"msgid": "2247483783_1",
"title": "Happy Weekend No. 3",
"user_source": 0,
"details":[
{
"stat_date": "2020-11-13",
"target_user": 356,
"int_page_read_user": 98,
"int_page_read_count": 121,
"ori_page_read_user": 9,
"ori_page_read_count": 11,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 97,
"int_page_from_session_read_count": 120,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 1,
"int_page_from_other_read_count": 1,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-14",
"target_user": 356,
"int_page_read_user": 118,
"int_page_read_count": 147,
"ori_page_read_user": 10,
"ori_page_read_count": 12,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 117,
"int_page_from_session_read_count": 146,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 1,
"int_page_from_other_read_count": 1,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-15",
"target_user": 356,
"int_page_read_user": 119,
"int_page_read_count": 150,
"ori_page_read_user": 10,
"ori_page_read_count": 12,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 118,
"int_page_from_session_read_count": 149,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 1,
"int_page_from_other_read_count": 1,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-16",
"target_user": 356,
"int_page_read_user": 119,
"int_page_read_count": 150,
"ori_page_read_user": 10,
"ori_page_read_count": 12,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 118,
"int_page_from_session_read_count": 149,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 1,
"int_page_from_other_read_count": 1,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
},
{
"stat_date": "2020-11-17",
"target_user": 356,
"int_page_read_user": 120,
"int_page_read_count": 151,
"ori_page_read_user": 10,
"ori_page_read_count": 12,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0,
"int_page_from_session_read_user": 119,
"int_page_from_session_read_count": 150,
"int_page_from_hist_msg_read_user": 0,
"int_page_from_hist_msg_count": 0,
"int_page_from_feed_read_user": 0,
"int_page_from_feed_read_count": 0,
"int_page_from_friends_read_user": 0,
"int_page_from_friends_read_count": 0,
"int_page_from_other_read_user": 1,
"int_page_from_other_read_count": 1,
"feed_share_from_session_user": 0,
"feed_share_from_session_cnt": 0,
"feed_share_from_feed_user": 0,
"feed_share_from_feed_cnt": 0,
"feed_share_from_other_user": 0,
"feed_share_from_other_cnt": 0
}
]#ATFP_CLOSE_Translate_span#,
"url": "https://mp.weixin.qq.com/s?__biz=mzixnjcymzkZoq==&mid=22 47483783&idx=1&sn=4946a8fb35caa4c29aa2232eb51f8bb1#rd"
}
]
}
7. Statistics of the first article of the task of obtaining the application of WeChat public account. In the end, you can try to simulate the effect similar to Douyin (although you can’t get the latest reading count, you can only get the number of readings after the release at most 7 days). The maximum time span refers to the time range of the maximum data that can be obtained when an interface is called. Get the number of readings based on the article ID. The problem may be that the date range is not accurate enough, because the value of the record is the time of the creation of this record, and the time that should be published on the WeChat platform should be taken. subsequent optimizations. The code is as follows
<?php
namespace console\services;
use yii;
use yii\helpers\arrayHelper;
Use Yii\Web\ServerErrorHttpException;
Class WXAppTaskService extends \Common\Services\WxAppTaskService
{
/**
* Statistics of the first article in the first article of the task of obtaining the application of WeChat public account
* @param object $wxapptask The task of the application of WeChat public account
* @param string $accesstoken access token
;
* @return array
* The format is as follows:
;
;[ // 最后一个统计日期
;STAT_DATE:2020-05-29, // Statistical date, in the getArticleTotal interface, ref_date refers to the date of the article group is issued, and stat_date is the data statistics date
;target_user: 387, // The number of people delivered, generally equal to the total number of fans
;int_page_read_user: 86, // The number of readers of the picture page (click the page to enter the group posting picture and text card)
;int_page_read_count: 111, // Reading times for pictures and text pages
;ORI_PAGE_READ_USER: 11, // The number of readers of the original page (click the page "read the original text" to enter the text page), if there is no original page, the data here is 0
;ori_page_read_count: 12, // Reading times of the original page
;share_user: 1, // Number of people to share
;share_count: 1, // The number of times to share
;ADD_TO_FAV_USER: 0, // The number of people to collect
;add_to_fav_count: 0, // the number of favorites
;int_page_from_session_read_user: 85, // The number of readers of the public account conversation
;int_page_from_session_read_count: 109, // The number of reading times of the public account conversation
;int_page_from_hist_msg_read_user: 0, // The number of readers of the historical message page
;int_page_from_hist_msg_read_count: 0, // The number of readings of the historical message page
;int_page_from_feed_read_user: 0, // The number of readers in the circle of friends
;int_page_from_feed_read_count: 0, // The number of readings of the circle of friends
;int_page_from_friends_read_user: 0, // Friends forward the number of readers
;int_page_from_friends_read_count: 0, // Friends retweeted the number of reading times
;int_page_from_other_read_user: 1, // Number of readers in other scenarios
;int_page_from_other_read_count: 1, // Reading times for other scenes
;feed_share_from_session_user: 0, // The public account conversation forwards the number of people in the circle of friends
;feed_share_from_session_cnt: 0, // The number of public account conversations forwarded to the circle of friends
;feed_share_from_feed_user: 0, // The number of people forwarded to the circle of friends
;feed_share_from_feed_cnt: 0, // The number of times forwarded to the circle of friends
;feed_share_from_other_user: 0, // Forward the number of people in the circle of friends in other scenarios
;feed_share_from_other_cnt: 0, // For other scenarios, the number of times forwarded to the circle of friends
* ]#atfp_close_translate_span#
;
* @Throws ServerErrorHttpException
*/
public static function getCounts($wxAppTask, $accessToken)
{
$date = date(Y-M-D, $wxapptask->created_at);
// http request, get the total data of graphic and text mass sending
$HttpGetArticleTotalData =[
accessToken=> $accessToken,
begindate=> $date,
enddate=> $date,
]#atfp_close_translate_span#;
$ArticleTotal = wxDataCubService::HttpGetArticleTotal($HttpGetArticleTotalData);
// Rebuild the array index, the key name: msgid
$list = arrayHelper::index($articletotal['list'],msgid);
$msgid = $wxapptask->msg_data_id ._1;
$counts =[];
if (isset($list)[$msgid])) {
// get the last key value of an array
$lastkey = array_key_last($list[$msgid]['details']);
$counts = $list[$msgid]['details'][$lastKey];
}
return $counts;
}
}





