|
|
|
@@ -9,6 +9,8 @@ import (
|
|
|
|
|
"sort"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
|
|
|
|
|
"github.com/silenceper/wechat/v2/miniprogram/context"
|
|
|
|
|
"github.com/silenceper/wechat/v2/miniprogram/security"
|
|
|
|
|
"github.com/silenceper/wechat/v2/util"
|
|
|
|
@@ -39,12 +41,25 @@ const (
|
|
|
|
|
EventTypeXpayGoodsDeliverNotify EventType = "xpay_goods_deliver_notify"
|
|
|
|
|
// EventTypeXpayCoinPayNotify 代币支付推送事件
|
|
|
|
|
EventTypeXpayCoinPayNotify EventType = "xpay_coin_pay_notify"
|
|
|
|
|
// EventSubscribePopup 用户操作订阅通知弹窗事件推送,用户在图文等场景内订阅通知的操作
|
|
|
|
|
EventSubscribePopup EventType = "subscribe_msg_popup_event"
|
|
|
|
|
// EventSubscribeMsgChange 用户管理订阅通知,用户在服务通知管理页面做通知管理时的操作
|
|
|
|
|
EventSubscribeMsgChange EventType = "subscribe_msg_change_event"
|
|
|
|
|
// EventSubscribeMsgSent 发送订阅通知,调用 bizsend 接口发送通知
|
|
|
|
|
EventSubscribeMsgSent EventType = "subscribe_msg_sent_event"
|
|
|
|
|
// ConfirmReceiveMethodAuto 自动确认收货
|
|
|
|
|
ConfirmReceiveMethodAuto ConfirmReceiveMethod = 1
|
|
|
|
|
// ConfirmReceiveMethodManual 手动确认收货
|
|
|
|
|
ConfirmReceiveMethodManual ConfirmReceiveMethod = 2
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// InfoTypeAcceptSubscribeMessage 接受订阅通知
|
|
|
|
|
InfoTypeAcceptSubscribeMessage InfoType = "accept"
|
|
|
|
|
// InfoTypeRejectSubscribeMessage 拒绝订阅通知
|
|
|
|
|
InfoTypeRejectSubscribeMessage InfoType = "reject"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// PushReceiver 接收消息推送
|
|
|
|
|
// 暂仅支付 Aes 加密方式
|
|
|
|
|
type PushReceiver struct {
|
|
|
|
@@ -188,19 +203,98 @@ func (receiver *PushReceiver) getEvent(dataType string, eventType EventType, dec
|
|
|
|
|
var pushData PushDataXpayCoinPayNotify
|
|
|
|
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
|
|
|
|
return &pushData, err
|
|
|
|
|
case EventSubscribePopup:
|
|
|
|
|
// 用户操作订阅通知弹窗事件推送
|
|
|
|
|
return receiver.unmarshalSubscribePopup(dataType, decryptMsg)
|
|
|
|
|
case EventSubscribeMsgChange:
|
|
|
|
|
// 用户管理订阅通知事件推送
|
|
|
|
|
return receiver.unmarshalSubscribeMsgChange(dataType, decryptMsg)
|
|
|
|
|
case EventSubscribeMsgSent:
|
|
|
|
|
// 用户发送订阅通知事件推送
|
|
|
|
|
return receiver.unmarshalSubscribeMsgSent(dataType, decryptMsg)
|
|
|
|
|
}
|
|
|
|
|
// 暂不支持其他事件类型,直接返回解密后的数据,由调用方处理
|
|
|
|
|
return decryptMsg, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unmarshal 解析推送的数据
|
|
|
|
|
func (receiver *PushReceiver) unmarshal(dateType string, decryptMsg []byte, pushData interface{}) error {
|
|
|
|
|
if dateType == DataTypeXML {
|
|
|
|
|
func (receiver *PushReceiver) unmarshal(dataType string, decryptMsg []byte, pushData interface{}) error {
|
|
|
|
|
if dataType == DataTypeXML {
|
|
|
|
|
return xml.Unmarshal(decryptMsg, pushData)
|
|
|
|
|
}
|
|
|
|
|
return json.Unmarshal(decryptMsg, pushData)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unmarshalSubscribePopup
|
|
|
|
|
func (receiver *PushReceiver) unmarshalSubscribePopup(dataType string, decryptMsg []byte) (PushData, error) {
|
|
|
|
|
var pushData PushDataSubscribePopup
|
|
|
|
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
|
|
|
|
if err == nil {
|
|
|
|
|
listData := gjson.Get(string(decryptMsg), "List")
|
|
|
|
|
if listData.IsObject() {
|
|
|
|
|
listItem := SubscribeMsgPopupEventList{}
|
|
|
|
|
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
|
|
|
|
|
return &pushData, parseErr
|
|
|
|
|
}
|
|
|
|
|
pushData.SetSubscribeMsgPopupEvents([]SubscribeMsgPopupEventList{listItem})
|
|
|
|
|
} else if listData.IsArray() {
|
|
|
|
|
listItems := make([]SubscribeMsgPopupEventList, 0)
|
|
|
|
|
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
|
|
|
|
|
return &pushData, parseErr
|
|
|
|
|
}
|
|
|
|
|
pushData.SetSubscribeMsgPopupEvents(listItems)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &pushData, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unmarshalSubscribeMsgChange 解析用户管理订阅通知事件推送
|
|
|
|
|
func (receiver *PushReceiver) unmarshalSubscribeMsgChange(dataType string, decryptMsg []byte) (PushData, error) {
|
|
|
|
|
var pushData PushDataSubscribeMsgChange
|
|
|
|
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
|
|
|
|
if err == nil {
|
|
|
|
|
listData := gjson.Get(string(decryptMsg), "List")
|
|
|
|
|
if listData.IsObject() {
|
|
|
|
|
listItem := SubscribeMsgChangeList{}
|
|
|
|
|
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
|
|
|
|
|
return &pushData, parseErr
|
|
|
|
|
}
|
|
|
|
|
pushData.SetSubscribeMsgChangeEvents([]SubscribeMsgChangeList{listItem})
|
|
|
|
|
} else if listData.IsArray() {
|
|
|
|
|
listItems := make([]SubscribeMsgChangeList, 0)
|
|
|
|
|
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
|
|
|
|
|
return &pushData, parseErr
|
|
|
|
|
}
|
|
|
|
|
pushData.SetSubscribeMsgChangeEvents(listItems)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return &pushData, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unmarshalSubscribeMsgSent 解析用户发送订阅通知事件推送
|
|
|
|
|
func (receiver *PushReceiver) unmarshalSubscribeMsgSent(dataType string, decryptMsg []byte) (PushData, error) {
|
|
|
|
|
var pushData PushDataSubscribeMsgSent
|
|
|
|
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
|
|
|
|
if err == nil {
|
|
|
|
|
listData := gjson.Get(string(decryptMsg), "List")
|
|
|
|
|
if listData.IsObject() {
|
|
|
|
|
listItem := SubscribeMsgSentList{}
|
|
|
|
|
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
|
|
|
|
|
return &pushData, parseErr
|
|
|
|
|
}
|
|
|
|
|
pushData.SetSubscribeMsgSentEvents([]SubscribeMsgSentList{listItem})
|
|
|
|
|
} else if listData.IsArray() {
|
|
|
|
|
listItems := make([]SubscribeMsgSentList, 0)
|
|
|
|
|
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
|
|
|
|
|
return &pushData, parseErr
|
|
|
|
|
}
|
|
|
|
|
pushData.SetSubscribeMsgSentEvents(listItems)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return &pushData, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DataReceived 接收到的数据
|
|
|
|
|
type DataReceived struct {
|
|
|
|
|
Encrypt string `json:"Encrypt" xml:"Encrypt"` // 加密的消息体
|
|
|
|
@@ -306,8 +400,8 @@ type PushDataSecVodUpload struct {
|
|
|
|
|
type SecVodUploadEvent struct {
|
|
|
|
|
MediaID string `json:"media_id" xml:"media_id"` // 媒资 id
|
|
|
|
|
SourceContext string `json:"source_context" xml:"source_context"` // 透传上传接口中开发者设置的值。
|
|
|
|
|
Errcode int `json:"errcode" xml:"errcode"` // 错误码,上传失败时该值非
|
|
|
|
|
Errmsg string `json:"errmsg" xml:"errmsg"` // 错误提示
|
|
|
|
|
ErrCode int `json:"errcode" xml:"errcode"` // 错误码,上传失败时该值非
|
|
|
|
|
ErrMsg string `json:"errmsg" xml:"errmsg"` // 错误提示
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PushDataSecVodAudit 短剧媒资审核状态
|
|
|
|
@@ -373,3 +467,113 @@ type CoinInfo struct {
|
|
|
|
|
ActualPrice int64 `json:"ActualPrice" xml:"ActualPrice"` // 物品实际支付价格(单位:分)
|
|
|
|
|
Attach string `json:"Attach" xml:"Attach"` // 透传信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PushDataSubscribePopup 用户操作订阅通知弹窗事件推送
|
|
|
|
|
type PushDataSubscribePopup struct {
|
|
|
|
|
CommonPushData
|
|
|
|
|
subscribeMsgPopupEventList []SubscribeMsgPopupEventList `json:"-"`
|
|
|
|
|
SubscribeMsgPopupEvent SubscribeMsgPopupEvent `xml:"SubscribeMsgPopupEvent"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubscribeMsgPopupEvent 用户操作订阅通知弹窗消息回调
|
|
|
|
|
type SubscribeMsgPopupEvent struct {
|
|
|
|
|
List []SubscribeMsgPopupEventList `xml:"List"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubscribeMsgPopupEventList 订阅消息事件列表
|
|
|
|
|
type SubscribeMsgPopupEventList struct {
|
|
|
|
|
TemplateID string `xml:"TemplateId" json:"TemplateId"`
|
|
|
|
|
SubscribeStatusString string `xml:"SubscribeStatusString" json:"SubscribeStatusString"`
|
|
|
|
|
PopupScene string `xml:"PopupScene" json:"PopupScene"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetSubscribeMsgPopupEvents 设置订阅消息事件
|
|
|
|
|
func (s *PushDataSubscribePopup) SetSubscribeMsgPopupEvents(list []SubscribeMsgPopupEventList) {
|
|
|
|
|
s.subscribeMsgPopupEventList = list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetSubscribeMsgPopupEvents 获取订阅消息事件数据
|
|
|
|
|
func (s *PushDataSubscribePopup) GetSubscribeMsgPopupEvents() []SubscribeMsgPopupEventList {
|
|
|
|
|
if s.subscribeMsgPopupEventList != nil {
|
|
|
|
|
return s.subscribeMsgPopupEventList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if s.SubscribeMsgPopupEvent.List == nil || len(s.SubscribeMsgPopupEvent.List) < 1 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return s.SubscribeMsgPopupEvent.List
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PushDataSubscribeMsgChange 用户管理订阅通知事件推送
|
|
|
|
|
type PushDataSubscribeMsgChange struct {
|
|
|
|
|
CommonPushData
|
|
|
|
|
SubscribeMsgChangeEvent SubscribeMsgChangeEvent `xml:"SubscribeMsgChangeEvent"`
|
|
|
|
|
subscribeMsgChangeList []SubscribeMsgChangeList `json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubscribeMsgChangeEvent 用户管理订阅通知回调
|
|
|
|
|
type SubscribeMsgChangeEvent struct {
|
|
|
|
|
List []SubscribeMsgChangeList `xml:"List" json:"List"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubscribeMsgChangeList 订阅消息事件列表
|
|
|
|
|
type SubscribeMsgChangeList struct {
|
|
|
|
|
TemplateID string `xml:"TemplateId" json:"TemplateId"`
|
|
|
|
|
SubscribeStatusString string `xml:"SubscribeStatusString" json:"SubscribeStatusString"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetSubscribeMsgChangeEvents 设置订阅消息事件
|
|
|
|
|
func (s *PushDataSubscribeMsgChange) SetSubscribeMsgChangeEvents(list []SubscribeMsgChangeList) {
|
|
|
|
|
s.subscribeMsgChangeList = list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetSubscribeMsgChangeEvents 获取订阅消息事件数据
|
|
|
|
|
func (s *PushDataSubscribeMsgChange) GetSubscribeMsgChangeEvents() []SubscribeMsgChangeList {
|
|
|
|
|
if s.subscribeMsgChangeList != nil {
|
|
|
|
|
return s.subscribeMsgChangeList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if s.SubscribeMsgChangeEvent.List == nil || len(s.SubscribeMsgChangeEvent.List) < 1 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s.SubscribeMsgChangeEvent.List
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PushDataSubscribeMsgSent 用户发送订阅通知事件推送
|
|
|
|
|
type PushDataSubscribeMsgSent struct {
|
|
|
|
|
CommonPushData
|
|
|
|
|
SubscribeMsgSentEvent SubscribeMsgSentEvent `xml:"SubscribeMsgSentEvent"`
|
|
|
|
|
subscribeMsgSentEventList []SubscribeMsgSentList `json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubscribeMsgSentEvent 用户发送订阅通知回调
|
|
|
|
|
type SubscribeMsgSentEvent struct {
|
|
|
|
|
List []SubscribeMsgSentList `xml:"List" json:"List"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubscribeMsgSentList 订阅消息事件列表
|
|
|
|
|
type SubscribeMsgSentList struct {
|
|
|
|
|
TemplateID string `xml:"TemplateId" json:"TemplateId"`
|
|
|
|
|
MsgID string `xml:"MsgID" json:"MsgID"`
|
|
|
|
|
ErrorCode int `xml:"ErrorCode" json:"ErrorCode"`
|
|
|
|
|
ErrorStatus string `xml:"ErrorStatus" json:"ErrorStatus"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetSubscribeMsgSentEvents 设置订阅消息事件
|
|
|
|
|
func (s *PushDataSubscribeMsgSent) SetSubscribeMsgSentEvents(list []SubscribeMsgSentList) {
|
|
|
|
|
s.subscribeMsgSentEventList = list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetSubscribeMsgSentEvents 获取订阅消息事件数据
|
|
|
|
|
func (s *PushDataSubscribeMsgSent) GetSubscribeMsgSentEvents() []SubscribeMsgSentList {
|
|
|
|
|
if s.subscribeMsgSentEventList != nil {
|
|
|
|
|
return s.subscribeMsgSentEventList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if s.SubscribeMsgSentEvent.List == nil || len(s.SubscribeMsgSentEvent.List) < 1 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s.SubscribeMsgSentEvent.List
|
|
|
|
|
}
|
|
|
|
|