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

42 lines
1.3 KiB

2 years ago
package wechatqy
import (
2 years ago
"context"
2 years ago
"fmt"
1 year ago
"github.com/dtapps/go-library/utils/gojson"
2 years ago
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
2 years ago
)
2 years ago
type WebhookSendResponse struct {
2 years ago
Errcode int64 `json:"errcode"`
Errmsg string `json:"errmsg"`
Type string `json:"type"`
MediaId string `json:"media_id"`
CreatedAt string `json:"created_at"`
}
2 years ago
type WebhookSendResult struct {
Result WebhookSendResponse // 结果
Body []byte // 内容
2 years ago
Http gorequest.Response // 请求
2 years ago
Err error // 错误
}
func newWebhookSendResult(result WebhookSendResponse, body []byte, http gorequest.Response, err error) *WebhookSendResult {
return &WebhookSendResult{Result: result, Body: body, Http: http, Err: err}
2 years ago
}
2 years ago
// WebhookSend 发送应用消息
// https://developer.work.weixin.qq.com/document/path/90372
2 years ago
func (c *Client) WebhookSend(ctx context.Context, notMustParams ...gorequest.Params) *WebhookSendResult {
2 years ago
// 参数
2 years ago
params := gorequest.NewParamsWith(notMustParams...)
2 years ago
// 请求
2 years ago
request, err := c.request(ctx, apiUrl+fmt.Sprintf("/cgi-bin/webhook/send?key=%s&type=%s", c.GetKey(), "text"), params, http.MethodPost)
2 years ago
// 定义
var response WebhookSendResponse
1 year ago
err = gojson.Unmarshal(request.ResponseBody, &response)
return newWebhookSendResult(response, request.ResponseBody, request, err)
2 years ago
}