github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/dkf/record/record.go (about) 1 // 客服聊天记录接口 2 package record 3 4 import ( 5 "fmt" 6 7 "github.com/chanxuehong/wechat/mp/core" 8 ) 9 10 type Record struct { 11 Worker string `json:"worker"` // 客服账号 12 OpenId string `json:"openid"` // 用户的标识, 对当前公众号唯一 13 OperCode int `json:"opercode"` // 操作ID(会话状态) 14 Timestamp int64 `json:"time"` // 操作时间, UNIX时间戳 15 Text string `json:"text"` // 聊天记录 16 } 17 18 type GetRequest struct { 19 StartTime int64 `json:"starttime"` // 查询开始时间, UNIX时间戳 20 EndTime int64 `json:"endtime"` // 查询结束时间, UNIX时间戳, 每次查询不能跨日查询 21 PageIndex int `json:"pageindex"` // 查询第几页, 从1开始 22 PageSize int `json:"pagesize"` // 每页大小, 每页最多拉取50条 23 OpenId string `json:"openid,omitempty"` // 普通用户的标识, 对当前公众号唯一 24 } 25 26 // Get 获取客服聊天记录 27 func Get(clt *core.Client, request *GetRequest) (list []Record, err error) { 28 const incompleteURL = "https://api.weixin.qq.com/customservice/msgrecord/getrecord?access_token=" 29 30 if request.PageIndex < 1 { 31 err = fmt.Errorf("Incorrect request.PageIndex: %d", request.PageIndex) 32 return 33 } 34 if request.PageSize <= 0 { 35 err = fmt.Errorf("Incorrect request.PageSize: %d", request.PageSize) 36 return 37 } 38 39 var result struct { 40 core.Error 41 RecordList []Record `json:"recordlist"` 42 } 43 if err = clt.PostJSON(incompleteURL, &request, &result); err != nil { 44 return 45 } 46 if result.ErrCode != core.ErrCodeOK { 47 err = &result.Error 48 return 49 } 50 list = result.RecordList 51 return 52 }