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

     1  package dkf
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/chanxuehong/wechat/mp/core"
     7  )
     8  
     9  // 客服基本信息
    10  type KfInfo struct {
    11  	Id           json.Number `json:"kf_id"`         // 客服工号
    12  	Account      string      `json:"kf_account"`    // 完整客服账号,格式为:账号前缀@公众号微信号
    13  	Nickname     string      `json:"kf_nick"`       // 客服昵称
    14  	HeadImageURL string      `json:"kf_headimgurl"` // 客服头像
    15  }
    16  
    17  // KfList 获取客服基本信息.
    18  func KfList(clt *core.Client) (list []KfInfo, err error) {
    19  	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token="
    20  
    21  	var result struct {
    22  		core.Error
    23  		KfList []KfInfo `json:"kf_list"`
    24  	}
    25  	if err = clt.GetJSON(incompleteURL, &result); err != nil {
    26  		return
    27  	}
    28  	if result.ErrCode != core.ErrCodeOK {
    29  		err = &result.Error
    30  		return
    31  	}
    32  	list = result.KfList
    33  	return
    34  }
    35  
    36  const (
    37  	OnlineKfInfoStatusPC          = 1
    38  	OnlineKfInfoStatusMobile      = 2
    39  	OnlineKfInfoStatusPCAndMobile = 3
    40  )
    41  
    42  // 在线客服接待信息
    43  type OnlineKfInfo struct {
    44  	Id               json.Number `json:"kf_id"`         // 客服工号
    45  	Account          string      `json:"kf_account"`    // 完整客服账号,格式为:账号前缀@公众号微信号
    46  	Status           int         `json:"status"`        // 客服在线状态 1:pc在线,2:手机在线。若pc和手机同时在线则为 1+2=3
    47  	AutoAcceptNumber int         `json:"auto_accept"`   // 客服设置的最大自动接入数
    48  	AcceptingNumber  int         `json:"accepted_case"` // 客服当前正在接待的会话数
    49  }
    50  
    51  // OnlineKfList 获取在线客服接待信息.
    52  func OnlineKfList(clt *core.Client) (list []OnlineKfInfo, err error) {
    53  	const incompleteURL = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token="
    54  
    55  	var result struct {
    56  		core.Error
    57  		OnlineKfInfoList []OnlineKfInfo `json:"kf_online_list"`
    58  	}
    59  	if err = clt.GetJSON(incompleteURL, &result); err != nil {
    60  		return
    61  	}
    62  	if result.ErrCode != core.ErrCodeOK {
    63  		err = &result.Error
    64  		return
    65  	}
    66  	list = result.OnlineKfInfoList
    67  	return
    68  }