mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
1
This commit is contained in:
@@ -20,6 +20,7 @@ const (
|
||||
_getSubscribe = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="
|
||||
_getTempMsg = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
|
||||
_createMenu = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="
|
||||
_sendCustom = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="
|
||||
_cacheToken = "wx_access_token"
|
||||
_cacheTicket = "weixin_card_ticket"
|
||||
)
|
||||
@@ -214,3 +215,22 @@ func (_wx *wxTools) CreateMenu(menu WxMenu) error { // 创建自定义菜单
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendCustomMsg 发送客服消息
|
||||
func (_wx *wxTools) SendCustomMsg(msg CustomMsg) error {
|
||||
accessToken, err := _wx.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bo, _ := json.Marshal(msg)
|
||||
resb, _ := myhttp.OnPostJSON(_sendCustom+accessToken, string(bo))
|
||||
|
||||
var res ResTempMsg
|
||||
json.Unmarshal(resb, &res)
|
||||
b := res.Errcode == 0
|
||||
if !b {
|
||||
return fmt.Errorf("SendWebTemplateMsg error: res:%v", res)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -119,3 +119,28 @@ type SubButton struct {
|
||||
Key string `json:"key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
}
|
||||
|
||||
// CustomMsg 客服消息头
|
||||
type CustomMsg struct {
|
||||
Touser string `json:"touser"` // 是 接收者(用户)的 openid
|
||||
Msgtype string `json:"msgtype"` // 是 所需下发的模板消息的id
|
||||
Text *CustomText `json:"text,omitempty"` // 文本类容
|
||||
Voice *CustomVoice `json:"voice,omitempty"` // 语音
|
||||
Music *CustomMusic `json:"music,omitempty"` // 音乐消息
|
||||
}
|
||||
|
||||
type CustomText struct {
|
||||
Content string `json:"content"` // 文本类容
|
||||
}
|
||||
|
||||
type CustomVoice struct {
|
||||
MediaId string `json:"media_id"` // 语音
|
||||
}
|
||||
|
||||
type CustomMusic struct {
|
||||
Title string `json:"title"` // 标题
|
||||
Description string `json:"description"` // 描述
|
||||
MusicUrl string `json:"musicurl"` // 链接
|
||||
HQMusicUrl string `json:"hqmusicurl"` // 链接
|
||||
ThumbMediaId string `json:"thumb_media_id"` // 缩略图
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ type WxTools interface {
|
||||
GetWebUserinfo(openid, accessToken string) (*WxUserinfo, error) // 获取用户信息
|
||||
SendWebTemplateMsg(msg TempWebMsg) bool // 发送公众号模板消息
|
||||
CreateMenu(menu WxMenu) error // 创建自定义菜单
|
||||
|
||||
SendCustomMsg(msg CustomMsg) error // 发送客服消息
|
||||
// ----------------------------------------------------
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user