1 Star 0 Fork 0

h79/gothird

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
request.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-07-28 16:16 . 还是把 token 放在这里
package customer
import (
"encoding/json"
"fmt"
"gitee.com/h79/gothird/token"
"gitee.com/h79/gothird/weixin/consts"
"gitee.com/h79/gothird/weixin/response"
"gitee.com/h79/goutils/common/http"
)
// 发送小程序客服消息
// POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
func Send(api *token.Api, req Customer) error {
buf, err := json.Marshal(req)
if err != nil {
return err
}
return SendWithBytes(api, buf)
}
func SendWithBytes(api *token.Api, buf []byte) error {
uri := fmt.Sprintf("%s/cgi-bin/message/custom/send?", consts.ApiPrefixUrl)
res := msgResult{}
return api.Request("POST", uri, buf, func(hp *http.Http, body []byte) error {
if err := json.Unmarshal(body, &res); err != nil {
return err
}
return res.ReturnIf(api)
})
}
// 客服输入状态
// POST https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN
func SendTyping(api *token.Api, req *Typing) error {
uri := fmt.Sprintf("%s/cgi-bin/message/custom/typing?", consts.ApiPrefixUrl)
buf, err := json.Marshal(req)
if err != nil {
return err
}
res := msgResult{}
return api.Request("POST", uri, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
}
type msgResult struct {
response.Response
MsgId int64 `json:"msgid"`
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/h79/gothird.git
git@gitee.com:h79/gothird.git
h79
gothird
gothird
v1.8.132

搜索帮助