You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/service/wechatqy/webhook.send.go

41 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package wechatqy
import (
"encoding/json"
"fmt"
)
// WebhookSendText 文本类型
type WebhookSendText struct {
Msgtype string `json:"msgtype"` // 消息类型此时固定为text
Text struct {
Content string `json:"content"` // 文本内容最长不超过2048个字节必须是utf8编码
MentionedList []string `json:"mentioned_list"` // userid的列表提醒群中的指定成员(@某个成员)@all表示提醒所有人如果开发者获取不到userid可以使用mentioned_mobile_list
MentionedMobileList []string `json:"mentioned_mobile_list"` // 手机号列表,提醒手机号对应的群成员(@某个成员)@all表示提醒所有人
} `json:"text"`
}
type WebhookSendResult struct {
Errcode int64 `json:"errcode"`
Errmsg string `json:"errmsg"`
Type string `json:"type"`
MediaId string `json:"media_id"`
CreatedAt string `json:"created_at"`
}
// WebhookSend https://work.weixin.qq.com/api/doc/90000/90136/91770
func (app *App) WebhookSend(notMustParams ...Params) (result WebhookSendResult, err error) {
// 参数
params := app.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=%s&type=%s", app.Key, "text"), params)
if err != nil {
return WebhookSendResult{}, err
}
err = json.Unmarshal(request, &result)
if err != nil {
return WebhookSendResult{}, err
}
return result, err
}