mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-09 07:02:27 +08:00
Compare commits
4 Commits
v2.0.9-rc.
...
v2.0.9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c021336a3c | ||
|
|
9294950ab5 | ||
|
|
d776f5c400 | ||
|
|
bc9f483c8e |
@@ -216,6 +216,11 @@ func (o *Order) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
|||||||
p.NotifyURL = o.NotifyURL // 默认使用order.NotifyURL
|
p.NotifyURL = o.NotifyURL // 默认使用order.NotifyURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 签名类型
|
||||||
|
if p.SignType == "" {
|
||||||
|
p.SignType = util.SignTypeMD5
|
||||||
|
}
|
||||||
|
|
||||||
param := map[string]string{
|
param := map[string]string{
|
||||||
"appid": o.AppID,
|
"appid": o.AppID,
|
||||||
"body": p.Body,
|
"body": p.Body,
|
||||||
@@ -232,10 +237,6 @@ func (o *Order) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
|||||||
"goods_tag": p.GoodsTag,
|
"goods_tag": p.GoodsTag,
|
||||||
"notify_url": p.NotifyURL,
|
"notify_url": p.NotifyURL,
|
||||||
}
|
}
|
||||||
// 签名类型
|
|
||||||
if param["sign_type"] == "" {
|
|
||||||
param["sign_type"] = util.SignTypeMD5
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.TimeExpire != "" {
|
if p.TimeExpire != "" {
|
||||||
// 如果有传入交易结束时间
|
// 如果有传入交易结束时间
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ type Menu struct {
|
|||||||
MsgType string `json:"msgtype"` // 消息类型,此时固定为:msgmenu
|
MsgType string `json:"msgtype"` // 消息类型,此时固定为:msgmenu
|
||||||
MsgMenu struct {
|
MsgMenu struct {
|
||||||
HeadContent string `json:"head_content"` // 消息内容,不多于1024字节
|
HeadContent string `json:"head_content"` // 消息内容,不多于1024字节
|
||||||
List []interface{} `json:"list"` // 菜单项配置
|
List []interface{} `json:"list"` // 菜单项配置,不能多余10个
|
||||||
|
TailContent string `json:"tail_content"` // 结束文本, 不多于1024字
|
||||||
} `json:"msgmenu"`
|
} `json:"msgmenu"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
45
work/kf/sendmsgonevent.go
Normal file
45
work/kf/sendmsgonevent.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package kf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// 发送事件响应消息
|
||||||
|
sendMsgOnEventAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg_on_event?access_token=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SendMsgOnEventSchema 发送事件响应消息
|
||||||
|
type SendMsgOnEventSchema struct {
|
||||||
|
util.CommonError
|
||||||
|
MsgID string `json:"msgid"` // 消息ID。如果请求参数指定了msgid,则原样返回,否则系统自动生成并返回。不多于32字节, 字符串取值范围(正则表达式):[0-9a-zA-Z_-]*
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMsgOnEvent 发送事件响应消息
|
||||||
|
//「进入会话事件」响应消息:
|
||||||
|
// 如果满足通过API下发欢迎语条件(条件为:1. 企业没有在管理端配置了原生欢迎语;2. 用户在过去48小时里未收过欢迎语,且未向该用户发过消息),则用户进入会话事件会额外返回一个welcome_code,开发者以此为凭据调用接口(填到该接口code参数),即可向客户发送客服欢迎语。
|
||||||
|
// 为了保证用户体验以及避免滥用,开发者仅可在收到相关事件后20秒内调用,且只可调用一次。
|
||||||
|
func (r *Client) SendMsgOnEvent(options interface{}) (info SendMsgOnEventSchema, err error) {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
data []byte
|
||||||
|
)
|
||||||
|
accessToken, err = r.ctx.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, 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
|
||||||
|
}
|
||||||
55
work/kf/sendmsgonevent/message.go
Normal file
55
work/kf/sendmsgonevent/message.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package sendmsgonevent
|
||||||
|
|
||||||
|
// Message 发送事件响应消息
|
||||||
|
type Message struct {
|
||||||
|
Code string `json:"code"` // 事件响应消息对应的code。通过事件回调下发,仅可使用一次。
|
||||||
|
MsgID string `json:"msgid"` // 消息ID。如果请求参数指定了msgid,则原样返回,否则系统自动生成并返回。不多于32字节,不多于32字节
|
||||||
|
}
|
||||||
|
|
||||||
|
// Text 文本消息
|
||||||
|
type Text struct {
|
||||||
|
Message
|
||||||
|
MsgType string `json:"msgtype"` // 消息类型,此时固定为:text
|
||||||
|
Text struct {
|
||||||
|
Content string `json:"content"` // 消息内容,最长不超过2048个字节
|
||||||
|
} `json:"text"` // 文本消息
|
||||||
|
}
|
||||||
|
|
||||||
|
// Menu 发送菜单消息
|
||||||
|
type Menu struct {
|
||||||
|
Message
|
||||||
|
MsgType string `json:"msgtype"` // 消息类型,此时固定为:msgmenu
|
||||||
|
MsgMenu struct {
|
||||||
|
HeadContent string `json:"head_content"` // 消息内容,不多于1024字节
|
||||||
|
List []interface{} `json:"list"` // 菜单项配置,不能多余10个
|
||||||
|
TailContent string `json:"tail_content"` // 结束文本, 不多于1024字
|
||||||
|
} `json:"msgmenu"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MenuClick 回复菜单
|
||||||
|
type MenuClick struct {
|
||||||
|
Type string `json:"type"` // 菜单类型: click 回复菜单
|
||||||
|
Click struct {
|
||||||
|
ID string `json:"id"` // 菜单ID, 不少于1字节, 不多于64字节
|
||||||
|
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于128字节
|
||||||
|
} `json:"click"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MenuView 超链接菜单
|
||||||
|
type MenuView struct {
|
||||||
|
Type string `json:"type"` // 菜单类型: view 超链接菜单
|
||||||
|
View struct {
|
||||||
|
URL string `json:"url"` // 点击后跳转的链接, 不少于1字节, 不多于2048字节
|
||||||
|
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于1024字节
|
||||||
|
} `json:"view"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MenuMiniProgram 小程序菜单
|
||||||
|
type MenuMiniProgram struct {
|
||||||
|
Type string `json:"type"` // 菜单类型: miniprogram 小程序菜单
|
||||||
|
MiniProgram struct {
|
||||||
|
AppID string `json:"appid"` // 小程序appid, 不少于1字节, 不多于32字节
|
||||||
|
PagePath string `json:"pagepath"` // 点击后进入的小程序页面, 不少于1字节, 不多于1024字节
|
||||||
|
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于1024字节
|
||||||
|
} `json:"miniprogram"`
|
||||||
|
}
|
||||||
@@ -120,6 +120,7 @@ type EnterSessionEvent struct {
|
|||||||
ExternalUserID string `json:"external_userid"` // 客户UserID
|
ExternalUserID string `json:"external_userid"` // 客户UserID
|
||||||
Scene string `json:"scene"` // 进入会话的场景值,获取客服帐号链接开发者自定义的场景值
|
Scene string `json:"scene"` // 进入会话的场景值,获取客服帐号链接开发者自定义的场景值
|
||||||
SceneParam string `json:"scene_param"` // 进入会话的自定义参数,获取客服帐号链接返回的url,开发者按规范拼接的scene_param参数
|
SceneParam string `json:"scene_param"` // 进入会话的自定义参数,获取客服帐号链接返回的url,开发者按规范拼接的scene_param参数
|
||||||
|
WelcomeCode string `json:"welcome_code"` // 如果满足发送欢迎语条件(条件为:1. 企业没有在管理端配置了原生欢迎语;2. 用户在过去48小时里未收过欢迎语,且未向该用户发过消息),会返回该字段。可用该welcome_code调用发送事件响应消息接口给客户发送欢迎语。
|
||||||
} `json:"event"` // 事件消息
|
} `json:"event"` // 事件消息
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user