robot.go 696 B

1234567891011121314151617181920212223242526272829
  1. package robot
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/silenceper/wechat/v2/util"
  6. )
  7. const (
  8. // webhookSendURL 机器人发送群组消息
  9. webhookSendURL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=%s"
  10. )
  11. // RobotBroadcast 群机器人消息发送
  12. // @see https://developer.work.weixin.qq.com/document/path/91770
  13. func (r *Client) RobotBroadcast(webhookKey string, options interface{}) (info util.CommonError, err error) {
  14. var data []byte
  15. if data, err = util.PostJSON(fmt.Sprintf(webhookSendURL, webhookKey), options); err != nil {
  16. return
  17. }
  18. if err = json.Unmarshal(data, &info); err != nil {
  19. return
  20. }
  21. if info.ErrCode != 0 {
  22. return info, err
  23. }
  24. return info, nil
  25. }