sendvoice

This commit is contained in:
jiangyong 2026-06-11 21:30:15 +08:00
parent 3a9efa6ff7
commit a1dc360fac
1 changed files with 31 additions and 0 deletions

View File

@ -51,6 +51,10 @@ type MessageRequest struct {
MediaID string `json:"media_id"`
} `json:"image"`
Voice struct {
MediaID string `json:"media_id"`
} `json:"voice"`
Video struct {
MediaID string `json:"media_id"`
Title string `json:"title"`
@ -235,6 +239,33 @@ func (a *App) SendImage(receiver []string, meidiaId string) error {
return nil
}
func (a *App) SendVoice(receiver []string, meidiaId string) error {
url := fmt.Sprintf("%s?access_token=%s", urlQiyeSend, a.GetToken())
req := new(MessageRequest)
req.MstType = "voice"
req.AgentId = a.config.Agent
req.ToUser = strings.Join(receiver, "|")
req.Voice.MediaID = meidiaId
data, _ := json.Marshal(req)
result, err := util.HttpPostJson(url, nil, data)
if err != nil {
return err
}
var rsp BaseResponse
err = json.Unmarshal([]byte(result), &rsp)
if err != nil {
return err
}
if rsp.ErrCode != 0 {
return fmt.Errorf("%d:%s", rsp.ErrCode, rsp.ErrMsg)
}
return nil
}
func (a *App) SendVideo(receiver []string, meidiaId, title, desc string) error {
url := fmt.Sprintf("%s?access_token=%s", urlQiyeSend, a.GetToken())