https://developer.work.weixin.qq.com/document/path/90236
(ctx context.Context, userIDs []string, markdown *WebhookMarkdown)
| 173 | |
| 174 | // https://developer.work.weixin.qq.com/document/path/90236 |
| 175 | func (p *provider) sendMessage(ctx context.Context, userIDs []string, markdown *WebhookMarkdown) error { |
| 176 | url, err := url.Parse("https://qyapi.weixin.qq.com/cgi-bin/message/send") |
| 177 | if err != nil { |
| 178 | return errors.Wrapf(err, "failed to parse url") |
| 179 | } |
| 180 | |
| 181 | requestBody, err := json.Marshal(struct { |
| 182 | ToUser string `json:"touser"` |
| 183 | MsgType string `json:"msgtype"` |
| 184 | AgentID int `json:"agentid"` |
| 185 | Markdown *WebhookMarkdown `json:"markdown"` |
| 186 | }{ |
| 187 | ToUser: strings.Join(userIDs, "|"), |
| 188 | MsgType: "markdown", |
| 189 | AgentID: p.agentID, |
| 190 | Markdown: markdown, |
| 191 | }) |
| 192 | if err != nil { |
| 193 | return errors.Wrapf(err, "failed to marshal request body") |
| 194 | } |
| 195 | |
| 196 | if _, err := p.do(ctx, http.MethodPost, url, requestBody); err != nil { |
| 197 | return errors.Wrapf(err, "failed to send message") |
| 198 | } |
| 199 | return nil |
| 200 | } |
| 201 | |
| 202 | func (p *provider) do(ctx context.Context, method string, url *url.URL, data []byte) ([]byte, error) { |
| 203 | if p.token == "" { |