Skip to content

Commit

Permalink
营销api回调接口
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmhub committed Dec 2, 2024
1 parent 4e672b0 commit b44ced9
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 18 deletions.
24 changes: 24 additions & 0 deletions callbacks/callback_constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,27 @@ const EventTypeQrcodeStatus EventType = "qrcode_status"

// 订单其他信息更新
const EventTypeChannelsEcOrderExtInfoUpdate EventType = "channels_ec_order_ext_info_update"

// 创建优惠券通知
const EventTypeChannelsEcCouponCreate EventType = "channels_ec_coupon_create"

// 删除优惠券通知
const EventTypeChannelsEcCouponDelete EventType = "channels_ec_coupon_delete"

// 优惠券过期通知
const EventTypeChannelsEcCouponExpire EventType = "channels_ec_coupon_expire"

// 优惠券信息更新通知
const EventTypeChannelsEcCouponInfoChange EventType = "channels_ec_coupon_info_change"

// 作废优惠券通知
const EventTypeChannelsEcCouponInvalid EventType = "channels_ec_coupon_invalid"

// 用户优惠券过期通知
const EventTypeChannelsEcUserCouponExpire EventType = "channels_ec_user_coupon_expire"

// 优惠券返还通知
const EventTypeChannelsEcUserCouponUnuse EventType = "channels_ec_user_coupon_unuse"

// 优惠券核销通知
const EventTypeChannelsEcUserCouponUse EventType = "channels_ec_user_coupon_use"
41 changes: 41 additions & 0 deletions callbacks/event优惠券信息更新通知.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package callbacks

import "encoding/json"

// 优惠券信息更新通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_coupon_info_change.html

func init() {
//添加可解析的回调事件
supportCallback(ChannelsEcCouponInfoChange{})
}

type ChannelsEcCouponInfoChange struct {
CreateTime int `json:"CreateTime"`
Event string `json:"Event"`
FromUserName string `json:"FromUserName"`
MsgType string `json:"MsgType"`
ToUserName string `json:"ToUserName"`
CouponInfo struct {
ChangeTime string `json:"change_time"`
CouponID string `json:"coupon_id"`
} `json:"coupon_info"`
}

func (ChannelsEcCouponInfoChange) GetMessageType() string {
return "event"
}

func (ChannelsEcCouponInfoChange) GetEventType() string {
return "channels_ec_coupon_info_change"
}

func (m ChannelsEcCouponInfoChange) GetTypeKey() string {
return m.GetMessageType() + ":" + m.GetEventType()
}

func (ChannelsEcCouponInfoChange) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp ChannelsEcCouponInfoChange
err := json.Unmarshal(data, &temp)
return temp, err
}
43 changes: 43 additions & 0 deletions callbacks/event优惠券核销通知.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package callbacks

import "encoding/json"

// 优惠券核销通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_user_coupon_use.html

func init() {
//添加可解析的回调事件
supportCallback(ChannelsEcUserCouponUse{})
}

type ChannelsEcUserCouponUse struct {
CreateTime int `json:"CreateTime"`
Event string `json:"Event"`
FromUserName string `json:"FromUserName"`
MsgType string `json:"MsgType"`
ToUserName string `json:"ToUserName"`
UseInfo struct {
CouponID string `json:"coupon_id"`
OrderID string `json:"order_id"`
UseTime string `json:"use_time"`
UserCouponID string `json:"user_coupon_id"`
} `json:"use_info"`
}

func (ChannelsEcUserCouponUse) GetMessageType() string {
return "event"
}

func (ChannelsEcUserCouponUse) GetEventType() string {
return "channels_ec_user_coupon_use"
}

func (m ChannelsEcUserCouponUse) GetTypeKey() string {
return m.GetMessageType() + ":" + m.GetEventType()
}

func (ChannelsEcUserCouponUse) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp ChannelsEcUserCouponUse
err := json.Unmarshal(data, &temp)
return temp, err
}
41 changes: 41 additions & 0 deletions callbacks/event优惠券过期通知.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package callbacks

import "encoding/json"

// 优惠券过期通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_coupon_expire.html

func init() {
//添加可解析的回调事件
supportCallback(ChannelsEcCouponExpire{})
}

type ChannelsEcCouponExpire struct {
CreateTime int `json:"CreateTime"`
Event string `json:"Event"`
FromUserName string `json:"FromUserName"`
MsgType string `json:"MsgType"`
ToUserName string `json:"ToUserName"`
CouponInfo struct {
CouponID string `json:"coupon_id"`
ExpireTime string `json:"expire_time"`
} `json:"coupon_info"`
}

func (ChannelsEcCouponExpire) GetMessageType() string {
return "event"
}

func (ChannelsEcCouponExpire) GetEventType() string {
return "channels_ec_coupon_expire"
}

func (m ChannelsEcCouponExpire) GetTypeKey() string {
return m.GetMessageType() + ":" + m.GetEventType()
}

func (ChannelsEcCouponExpire) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp ChannelsEcCouponExpire
err := json.Unmarshal(data, &temp)
return temp, err
}
43 changes: 43 additions & 0 deletions callbacks/event优惠券返还通知.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package callbacks

import "encoding/json"

// 优惠券返还通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_user_coupon_unuse.html

func init() {
//添加可解析的回调事件
supportCallback(ChannelsEcUserCouponUnuse{})
}

type ChannelsEcUserCouponUnuse struct {
CreateTime int `json:"CreateTime"`
Event string `json:"Event"`
FromUserName string `json:"FromUserName"`
MsgType string `json:"MsgType"`
ToUserName string `json:"ToUserName"`
UseInfo struct {
CouponID string `json:"coupon_id"`
OrderID string `json:"order_id"`
UnuseTime string `json:"unuse_time"`
UserCouponID string `json:"user_coupon_id"`
} `json:"use_info"`
}

func (ChannelsEcUserCouponUnuse) GetMessageType() string {
return "event"
}

func (ChannelsEcUserCouponUnuse) GetEventType() string {
return "channels_ec_user_coupon_unuse"
}

func (m ChannelsEcUserCouponUnuse) GetTypeKey() string {
return m.GetMessageType() + ":" + m.GetEventType()
}

func (ChannelsEcUserCouponUnuse) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp ChannelsEcUserCouponUnuse
err := json.Unmarshal(data, &temp)
return temp, err
}
24 changes: 6 additions & 18 deletions callbacks/event优惠券领取通知.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package callbacks

import "github.com/tidwall/gjson"
import (
"encoding/json"
)

// 优惠券领取通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_coupon_receive.html
Expand Down Expand Up @@ -36,21 +38,7 @@ func (m ChannelsEcCouponReceive) GetTypeKey() string {
}

func (ChannelsEcCouponReceive) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp = ChannelsEcCouponReceive{
CreateTime: gjson.GetBytes(data, "CreateTime").Int(),
Event: gjson.GetBytes(data, "Event").String(),
FromUserName: gjson.GetBytes(data, "FromUserName").String(),
MsgType: gjson.GetBytes(data, "MsgType").String(),
ToUserName: gjson.GetBytes(data, "ToUserName").String(),
ReceiveInfo: struct {
CouponID string `json:"coupon_id"`
ReceiveTime string `json:"receive_time"`
UserCouponID string `json:"user_coupon_id"`
}{
CouponID: gjson.GetBytes(data, "receive_info.coupon_id").String(),
ReceiveTime: gjson.GetBytes(data, "receive_info.receive_time").String(),
UserCouponID: gjson.GetBytes(data, "receive_info.user_coupon_id").String(),
},
}
return temp, nil
var temp ChannelsEcCouponReceive
err := json.Unmarshal(data, &temp)
return temp, err
}
41 changes: 41 additions & 0 deletions callbacks/event作废优惠券通知.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package callbacks

import "encoding/json"

// 作废优惠券通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_coupon_invalid.html

func init() {
//添加可解析的回调事件
supportCallback(ChannelsEcCouponInvalid{})
}

type ChannelsEcCouponInvalid struct {
CreateTime int `json:"CreateTime"`
Event string `json:"Event"`
FromUserName string `json:"FromUserName"`
MsgType string `json:"MsgType"`
ToUserName string `json:"ToUserName"`
CouponInfo struct {
CouponID string `json:"coupon_id"`
InvalidTime string `json:"invalid_time"`
} `json:"coupon_info"`
}

func (ChannelsEcCouponInvalid) GetMessageType() string {
return "event"
}

func (ChannelsEcCouponInvalid) GetEventType() string {
return "channels_ec_coupon_invalid"
}

func (m ChannelsEcCouponInvalid) GetTypeKey() string {
return m.GetMessageType() + ":" + m.GetEventType()
}

func (ChannelsEcCouponInvalid) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp ChannelsEcCouponInvalid
err := json.Unmarshal(data, &temp)
return temp, err
}
41 changes: 41 additions & 0 deletions callbacks/event创建优惠券通知.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package callbacks

import "encoding/json"

// 创建优惠券通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_coupon_create.html

func init() {
//添加可解析的回调事件
supportCallback(ChannelsEcCouponCreate{})
}

type ChannelsEcCouponCreate struct {
CreateTime int `json:"CreateTime"`
Event string `json:"Event"`
FromUserName string `json:"FromUserName"`
MsgType string `json:"MsgType"`
ToUserName string `json:"ToUserName"`
CouponInfo struct {
CouponID string `json:"coupon_id"`
CreateTime string `json:"create_time"`
} `json:"coupon_info"`
}

func (ChannelsEcCouponCreate) GetMessageType() string {
return "event"
}

func (ChannelsEcCouponCreate) GetEventType() string {
return "channels_ec_coupon_create"
}

func (m ChannelsEcCouponCreate) GetTypeKey() string {
return m.GetMessageType() + ":" + m.GetEventType()
}

func (ChannelsEcCouponCreate) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp ChannelsEcCouponCreate
err := json.Unmarshal(data, &temp)
return temp, err
}
41 changes: 41 additions & 0 deletions callbacks/event删除优惠券通知.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package callbacks

import "encoding/json"

// 删除优惠券通知
// 文档: https://developers.weixin.qq.com/doc/channels/API/coupon/ec_callback/channels_ec_coupon_delete.html

func init() {
//添加可解析的回调事件
supportCallback(ChannelsEcCouponDelete{})
}

type ChannelsEcCouponDelete struct {
CreateTime int `json:"CreateTime"`
Event string `json:"Event"`
FromUserName string `json:"FromUserName"`
MsgType string `json:"MsgType"`
ToUserName string `json:"ToUserName"`
CouponInfo struct {
CouponID string `json:"coupon_id"`
DeleteTime string `json:"delete_time"`
} `json:"coupon_info"`
}

func (ChannelsEcCouponDelete) GetMessageType() string {
return "event"
}

func (ChannelsEcCouponDelete) GetEventType() string {
return "channels_ec_coupon_delete"
}

func (m ChannelsEcCouponDelete) GetTypeKey() string {
return m.GetMessageType() + ":" + m.GetEventType()
}

func (ChannelsEcCouponDelete) ParseFromJson(data []byte) (CallbackExtraInfoInterface, error) {
var temp ChannelsEcCouponDelete
err := json.Unmarshal(data, &temp)
return temp, err
}
Loading

0 comments on commit b44ced9

Please sign in to comment.