github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/shakearound/event.go (about)

     1  package shakearound
     2  
     3  import (
     4  	"unsafe"
     5  
     6  	"github.com/chanxuehong/wechat/mp/core"
     7  )
     8  
     9  const (
    10  	// 推送到公众号URL上的事件类型
    11  	EventTypeUserShake core.EventType = "ShakearoundUserShake" // 摇一摇事件通知
    12  )
    13  
    14  type UserShakeEvent struct {
    15  	XMLName struct{} `xml:"xml" json:"-"`
    16  	core.MsgHeader
    17  
    18  	EventType core.EventType `xml:"Event" json:"Event"` // 事件类型,ShakearoundUserShake
    19  
    20  	ChosenBeacon  *ChosenBeacon  `xml:"ChosenBeacon,omitempty" json:"ChosenBeacon,omitempty"`
    21  	AroundBeacons []AroundBeacon `xml:"AroundBeacons>AroundBeacon,omitempty" json:"AroundBeacons,omitempty"`
    22  }
    23  
    24  // 和 github.com/chanxuehong/wechat/mp/core.MixedMsg.ChosenBeacon 一样, 同步修改
    25  type ChosenBeacon struct {
    26  	UUID     string  `xml:"Uuid"     json:"Uuid"`
    27  	Major    int     `xml:"Major"    json:"Major"`
    28  	Minor    int     `xml:"Minor"    json:"Minor"`
    29  	Distance float64 `xml:"Distance" json:"Distance"`
    30  }
    31  
    32  // 和 github.com/chanxuehong/wechat/mp/core.MixedMsg.AroundBeacon 一样, 同步修改
    33  type AroundBeacon struct {
    34  	UUID     string  `xml:"Uuid"     json:"Uuid"`
    35  	Major    int     `xml:"Major"    json:"Major"`
    36  	Minor    int     `xml:"Minor"    json:"Minor"`
    37  	Distance float64 `xml:"Distance" json:"Distance"`
    38  }
    39  
    40  func GetUserShakeEvent(msg *core.MixedMsg) *UserShakeEvent {
    41  	return &UserShakeEvent{
    42  		MsgHeader:     msg.MsgHeader,
    43  		EventType:     msg.EventType,
    44  		ChosenBeacon:  (*ChosenBeacon)(msg.ChosenBeacon),
    45  		AroundBeacons: *(*[]AroundBeacon)(unsafe.Pointer(&msg.AroundBeacons)),
    46  	}
    47  }