From ee85790123fb35774cb0cf325f98d9f34d1d4859 Mon Sep 17 00:00:00 2001 From: markwang Date: Tue, 1 Jul 2025 19:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F-?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E6=9E=90-=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=80=A7=E8=83=BD=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=20(#837)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 微信小程序-数据分析-性能数据 * feat: 微信小程序-数据分析-性能数据 * feat: 微信小程序-数据分析-性能数据 --- miniprogram/analysis/analysis.go | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/miniprogram/analysis/analysis.go b/miniprogram/analysis/analysis.go index 55cfdec..daceda0 100644 --- a/miniprogram/analysis/analysis.go +++ b/miniprogram/analysis/analysis.go @@ -30,6 +30,8 @@ const ( getAnalysisVisitDistributionURL = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution?access_token=%s" // 访问页面 getAnalysisVisitPageURL = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage?access_token=%s" + // 获取小程序性能数据 + getPerformanceDataURL = "https://api.weixin.qq.com/wxa/business/performance/boot?access_token=%s" ) // Analysis analyis 数据分析 @@ -315,3 +317,67 @@ func (analysis *Analysis) GetAnalysisVisitPage(beginDate, endDate string) (resul } return } + +// GetPerformanceDataRequest 获取小程序性能数据请求 +type GetPerformanceDataRequest struct { + Module string `json:"module"` + Time PerformanceDataTime `json:"time"` + Params []PerformanceDataParams `json:"params"` +} + +// PerformanceDataTime 获取小程序性能数据开始和结束日期 +type PerformanceDataTime struct { + BeginTimestamp int64 `json:"begin_timestamp"` + EndTimestamp int64 `json:"end_timestamp"` +} + +// PerformanceDataParams 获取小程序性能数据查询条件 +type PerformanceDataParams struct { + Field string `json:"field"` + Value string `json:"value"` +} + +// GetPerformanceDataResponse 获取小程序性能数据响应 +type GetPerformanceDataResponse struct { + util.CommonError + Body PerformanceDataBody `json:"body"` +} + +// PerformanceDataBody 性能数据 +type PerformanceDataBody struct { + Tables []PerformanceDataTable `json:"tables"` + Count int64 `json:"count"` +} + +// PerformanceDataTable 数据数组 +type PerformanceDataTable struct { + ID string `json:"id"` + Lines []PerformanceDataTableLine `json:"lines"` + Zh string `json:"zh"` +} + +// PerformanceDataTableLine 按时间排列的性能数据 +type PerformanceDataTableLine struct { + Fields []PerformanceDataTableLineField `json:"fields"` +} + +// PerformanceDataTableLineField 单天的性能数据 +type PerformanceDataTableLineField struct { + RefDate string `json:"refdate"` + Value string `json:"value"` +} + +// GetPerformanceData 获取小程序性能数据 +// see https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/data-analysis/others/getPerformanceData.html +func (analysis *Analysis) GetPerformanceData(req *GetPerformanceDataRequest) (res GetPerformanceDataResponse, err error) { + var accessToken string + if accessToken, err = analysis.GetAccessToken(); err != nil { + return + } + var response []byte + if response, err = util.PostJSON(fmt.Sprintf(getPerformanceDataURL, accessToken), req); err != nil { + return + } + err = util.DecodeWithError(response, &res, "GetPerformanceData") + return +}