Ai
2 Star 1 Fork 0

李光春/Golang QyWechat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
qywechat.go 923 Bytes
一键复制 编辑 原始数据 按行查看 历史
李光春 提交于 2021-07-19 17:32 +08:00 . update *
package qywechat
import (
"encoding/json"
"fmt"
"gitee.com/dtapps/go-qywechat/qywechat/message"
"io/ioutil"
"net/http"
"strings"
)
const api = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send"
type QyBot struct {
Key string
}
type response struct {
Errcode int64 `json:"errcode"`
Errmsg string `json:"errmsg"`
Type string `json:"type"`
MediaId string `json:"media_id"`
CreatedAt string `json:"created_at"`
}
func (bot *QyBot) Send(msg message.Message) (response, error) {
var response response
qyUrl := fmt.Sprintf("%s?key=%s", api, bot.Key)
j, e := json.Marshal(msg)
if e != nil {
return response, e
}
resp, e := http.Post(qyUrl, "application/json", strings.NewReader(string(j)))
if e != nil {
return response, e
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
e = json.Unmarshal(body, &response)
if e != nil {
return response, e
}
return response, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dtapps/go-qywechat.git
git@gitee.com:dtapps/go-qywechat.git
dtapps
go-qywechat
Golang QyWechat
v1.0.2

搜索帮助