1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-23 13:42:25 +08:00

Compare commits

...

10 Commits

Author SHA1 Message Date
houseme
f26a66ec9c Merge 356fe3df44 into 038037b89d 2023-10-13 17:11:50 +00:00
houseme
356fe3df44 fix 2023-10-14 01:11:35 +08:00
houseme
9e54a6a27b fix 2023-10-14 01:05:01 +08:00
houseme
ef4e3a0a3e test 2023-10-14 00:59:32 +08:00
houseme
12dfb7051a test 2023-10-14 00:54:18 +08:00
houseme
d214617446 feat: improve code for subscribe 2023-10-12 13:29:01 +08:00
houseme
b3e2d624d9 feat: add v1.21 and feature branch 2023-10-11 23:54:40 +08:00
houseme
7371d1649f feat: improve subscribe msg 2023-10-11 23:51:24 +08:00
Ralph Maas
b1f31feff6 feat(miniapp): 小程序订阅消息 (#429)
1. 用户订阅消息服务端回调处理
2. 用户订阅消息订阅通知事件推送

Co-authored-by: houseme <qzg40737@163.com>
2023-10-11 09:06:49 -05:00
houseme
b39be7fca2 fix 2023-10-11 22:04:23 +08:00
5 changed files with 133 additions and 36 deletions

View File

@@ -2,15 +2,15 @@ name: Go
on: on:
push: push:
branches: [ master,release-*,v2 ] branches: [ master,release-*,v2,feature/** ]
pull_request: pull_request:
branches: [ master,release-*,v2 ] branches: [ master,release-*,v2,feature/** ]
jobs: jobs:
golangci: golangci:
strategy: strategy:
matrix: matrix:
go-version: [ '1.16','1.17','1.18','1.19','1.20' ] go-version: [ '1.16','1.17','1.18','1.19','1.20','1.21' ]
name: golangci-lint name: golangci-lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -42,7 +42,7 @@ jobs:
# strategy set # strategy set
strategy: strategy:
matrix: matrix:
go: [ '1.16','1.17','1.18','1.19','1.20' ] go: [ '1.16','1.17','1.18','1.19','1.20','1.21' ]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@@ -39,12 +39,25 @@ const (
EventTypeXpayGoodsDeliverNotify EventType = "xpay_goods_deliver_notify" EventTypeXpayGoodsDeliverNotify EventType = "xpay_goods_deliver_notify"
// EventTypeXpayCoinPayNotify 代币支付推送事件 // EventTypeXpayCoinPayNotify 代币支付推送事件
EventTypeXpayCoinPayNotify EventType = "xpay_coin_pay_notify" 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 自动确认收货
ConfirmReceiveMethodAuto ConfirmReceiveMethod = 1 ConfirmReceiveMethodAuto ConfirmReceiveMethod = 1
// ConfirmReceiveMethodManual 手动确认收货 // ConfirmReceiveMethodManual 手动确认收货
ConfirmReceiveMethodManual ConfirmReceiveMethod = 2 ConfirmReceiveMethodManual ConfirmReceiveMethod = 2
) )
const (
// InfoTypeAcceptSubscribeMessage 接受订阅通知
InfoTypeAcceptSubscribeMessage InfoType = "accept"
// InfoTypeRejectSubscribeMessage 拒绝订阅通知
InfoTypeRejectSubscribeMessage InfoType = "reject"
)
// PushReceiver 接收消息推送 // PushReceiver 接收消息推送
// 暂仅支付 Aes 加密方式 // 暂仅支付 Aes 加密方式
type PushReceiver struct { type PushReceiver struct {
@@ -188,6 +201,21 @@ func (receiver *PushReceiver) getEvent(dataType string, eventType EventType, dec
var pushData PushDataXpayCoinPayNotify var pushData PushDataXpayCoinPayNotify
err := receiver.unmarshal(dataType, decryptMsg, &pushData) err := receiver.unmarshal(dataType, decryptMsg, &pushData)
return &pushData, err return &pushData, err
case EventSubscribePopup:
// 用户操作订阅通知弹窗事件推送
var pushData PushDataSubscribePopup
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
return &pushData, err
case EventSubscribeMsgChange:
// 用户管理订阅通知事件推送
var pushData PushDataSubscribeMsgChange
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
return &pushData, err
case EventSubscribeMsgSent:
// 用户发送订阅通知事件推送
var pushData PushDataSubscribeMsgSent
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
return &pushData, err
} }
// 暂不支持其他事件类型,直接返回解密后的数据,由调用方处理 // 暂不支持其他事件类型,直接返回解密后的数据,由调用方处理
return decryptMsg, nil return decryptMsg, nil
@@ -306,8 +334,8 @@ type PushDataSecVodUpload struct {
type SecVodUploadEvent struct { type SecVodUploadEvent struct {
MediaID string `json:"media_id" xml:"media_id"` // 媒资 id MediaID string `json:"media_id" xml:"media_id"` // 媒资 id
SourceContext string `json:"source_context" xml:"source_context"` // 透传上传接口中开发者设置的值。 SourceContext string `json:"source_context" xml:"source_context"` // 透传上传接口中开发者设置的值。
Errcode int `json:"errcode" xml:"errcode"` // 错误码,上传失败时该值非 ErrCode int `json:"errcode" xml:"errcode"` // 错误码,上传失败时该值非
Errmsg string `json:"errmsg" xml:"errmsg"` // 错误提示 ErrMsg string `json:"errmsg" xml:"errmsg"` // 错误提示
} }
// PushDataSecVodAudit 短剧媒资审核状态 // PushDataSecVodAudit 短剧媒资审核状态
@@ -373,3 +401,57 @@ type CoinInfo struct {
ActualPrice int64 `json:"ActualPrice" xml:"ActualPrice"` // 物品实际支付价格(单位:分) ActualPrice int64 `json:"ActualPrice" xml:"ActualPrice"` // 物品实际支付价格(单位:分)
Attach string `json:"Attach" xml:"Attach"` // 透传信息 Attach string `json:"Attach" xml:"Attach"` // 透传信息
} }
// PushDataSubscribePopup 用户操作订阅通知弹窗事件推送
type PushDataSubscribePopup struct {
CommonPushData
List []SubscribeMsgPopupEventList `xml:"SubscribeMsgPopupEvent>List" json:"List"`
}
// SubscribeMsgPopupEvent 用户操作订阅通知弹窗消息回调
type SubscribeMsgPopupEvent struct {
List []SubscribeMsgPopupEventList `xml:"List" json:"List"`
}
// SubscribeMsgPopupEventList 订阅消息事件列表
type SubscribeMsgPopupEventList struct {
TemplateID string `xml:"TemplateId" json:"TemplateId"`
SubscribeStatusString string `xml:"SubscribeStatusString" json:"SubscribeStatusString"`
PopupScene string `xml:"PopupScene" json:"PopupScene"`
}
// PushDataSubscribeMsgChange 用户管理订阅通知事件推送
type PushDataSubscribeMsgChange struct {
CommonPushData
List []SubscribeMsgChangeList `xml:"SubscribeMsgChangeEvent>List" json:"List"`
}
// 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"`
}
// PushDataSubscribeMsgSent 用户发送订阅通知事件推送
type PushDataSubscribeMsgSent struct {
CommonPushData
List []SubscribeMsgSentEventList `xml:"SubscribeMsgSentEvent>List" json:"List"`
}
// SubscribeMsgSentEvent 用户发送订阅通知回调
type SubscribeMsgSentEvent struct {
List []SubscribeMsgSentEventList `xml:"List" json:"List"`
}
// SubscribeMsgSentEventList 订阅消息事件列表
type SubscribeMsgSentEventList 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"`
}

View File

@@ -0,0 +1,15 @@
package message
import "errors"
// ErrInvalidReply 无效的回复
var ErrInvalidReply = errors.New("无效的回复信息")
// ErrUnsupportedReply 不支持的回复类型
var ErrUnsupportedReply = errors.New("不支持的回复消息")
// Reply 消息回复
type Reply struct {
MsgType MsgType
MsgData interface{}
}