github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/shakearound/user/getshakeinfo.go (about) 1 package user 2 3 import ( 4 "github.com/chanxuehong/wechat/mp/core" 5 ) 6 7 type BeaconInfo struct { 8 Distance float64 `json:"distance"` // Beacon信号与手机的距离,单位为米 9 UUID string `json:"uuid"` 10 Major int `json:"major"` 11 Minor int `json:"minor"` 12 } 13 14 type Shakeinfo struct { 15 PageId int64 `json:"page_id"` // 摇周边页面唯一ID 16 BeaconInfo BeaconInfo `json:"beacon_info"` // 设备信息,包括UUID、major、minor,以及距离 17 Openid string `json:"openid"` // 商户AppID下用户的唯一标识 18 PoiId *int64 `json:"poi_id"` // 门店ID,有的话则返回,反之不会在JSON格式内 19 } 20 21 // 获取摇周边的设备及用户信息 22 // 23 // ticket: 摇周边业务的ticket,可在摇到的URL中得到,ticket生效时间为30分钟,每一次摇都会重新生成新的ticket 24 // needPoi: 是否需要返回门店poi_id 25 func GetShakeInfo(clt *core.Client, ticket string, needPoi bool) (info *Shakeinfo, err error) { 26 request := struct { 27 Ticket string `json:"ticket"` 28 NeedPoi int `json:"need_poi,omitempty"` 29 }{ 30 Ticket: ticket, 31 } 32 33 if needPoi { 34 request.NeedPoi = 1 35 } 36 37 var result struct { 38 core.Error 39 Shakeinfo `json:"data"` 40 } 41 42 incompleteURL := "https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=" 43 if err = clt.PostJSON(incompleteURL, &request, &result); err != nil { 44 return 45 } 46 47 if result.ErrCode != core.ErrCodeOK { 48 err = &result.Error 49 return 50 } 51 info = &result.Shakeinfo 52 return 53 }