github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/material/video.go (about)

     1  package material
     2  
     3  import (
     4  	"github.com/chanxuehong/wechat/mp/core"
     5  )
     6  
     7  type Video struct {
     8  	Title       string `json:"title"`
     9  	Description string `json:"description"`
    10  	DownloadURL string `json:"down_url"`
    11  }
    12  
    13  // 获取视频消息素材信息.
    14  func GetVideo(clt *core.Client, mediaId string) (info *Video, err error) {
    15  	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token="
    16  
    17  	var request = struct {
    18  		MediaId string `json:"media_id"`
    19  	}{
    20  		MediaId: mediaId,
    21  	}
    22  	var result struct {
    23  		core.Error
    24  		Video
    25  	}
    26  	if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
    27  		return
    28  	}
    29  	if result.ErrCode != core.ErrCodeOK {
    30  		err = &result.Error
    31  		return
    32  	}
    33  	info = &result.Video
    34  	return
    35  }