github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/shakearound/statistics/device.go (about)

     1  package statistics
     2  
     3  import (
     4  	"github.com/chanxuehong/wechat/mp/core"
     5  	"github.com/chanxuehong/wechat/mp/shakearound/device"
     6  )
     7  
     8  // 以设备为维度的数据统计接口
     9  func Device(clt *core.Client, deviceIdentifier *device.DeviceIdentifier, beginDate, endDate int64) (data []StatisticsBase, err error) {
    10  	request := struct {
    11  		DeviceIdentifier *device.DeviceIdentifier `json:"device_identifier,omitempty"`
    12  		BeginDate        int64                    `json:"begin_date"`
    13  		EndDate          int64                    `json:"end_date"`
    14  	}{
    15  		DeviceIdentifier: deviceIdentifier,
    16  		BeginDate:        beginDate,
    17  		EndDate:          endDate,
    18  	}
    19  
    20  	var result struct {
    21  		core.Error
    22  		Data []StatisticsBase `json:"data"`
    23  	}
    24  
    25  	incompleteURL := "https://api.weixin.qq.com/shakearound/statistics/device?access_token="
    26  	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
    27  		return
    28  	}
    29  
    30  	if result.ErrCode != core.ErrCodeOK {
    31  		err = &result.Error
    32  		return
    33  	}
    34  	data = result.Data
    35  	return
    36  }