1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-08 22:52:27 +08:00

添加微信客服SDK (#436)

* 添加微信客服SDK

* polish:优化签名函数

* polish:优化注释内容

* polish:复用已有的Token以及CommonError,移除无用的输出

* polish:复用已有的消息加解密

* fix:修复错误信息被覆盖的问题

* polish:go fmt 文件
This commit is contained in:
Afeyer
2021-08-17 10:19:01 +08:00
committed by GitHub
parent fc1fc7e84e
commit 8ceabc2d0b
17 changed files with 1299 additions and 1 deletions

42
work/kf/sendmsg.go Normal file
View File

@@ -0,0 +1,42 @@
package kf
import (
"encoding/json"
"fmt"
"github.com/silenceper/wechat/v2/util"
)
const (
//发送消息
sendMsgAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg?access_token=%s"
)
// SendMsgSchema 发送消息响应内容
type SendMsgSchema struct {
util.CommonError
MsgID string `json:"msgid"` // 消息ID。如果请求参数指定了msgid则原样返回否则系统自动生成并返回。不多于32字节, 字符串取值范围(正则表达式)[0-9a-zA-Z_-]*
}
// SendMsg 获取消息
func (r *Client) SendMsg(options interface{}) (info SendMsgSchema, err error) {
var (
accessToken string
data []byte
)
accessToken, err = r.ctx.GetAccessToken()
if err != nil {
return
}
data, err = util.PostJSON(fmt.Sprintf(sendMsgAddr, accessToken), options)
if err != nil {
return
}
if err = json.Unmarshal(data, &info); err != nil {
return
}
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}