github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/shakearound/device/update.go (about) 1 package device 2 3 import ( 4 "github.com/chanxuehong/wechat/internal/util" 5 "github.com/chanxuehong/wechat/mp/core" 6 ) 7 8 // 设备标识 9 type DeviceIdentifier struct { 10 // 设备编号,若填了UUID、major、minor,则可不填设备编号,若二者都填,则以设备编号为优先 11 DeviceId *int64 `json:"device_id,omitempty"` 12 13 // UUID、major、minor,三个信息需填写完整,若填了设备编号,则可不填此信息。 14 UUID string `json:"uuid,omitempty"` 15 Major *int `json:"major,omitempty"` 16 Minor *int `json:"minor,omitempty"` 17 } 18 19 func NewDeviceIdentifier1(deviceId int64) *DeviceIdentifier { 20 return &DeviceIdentifier{ 21 DeviceId: util.Int64(deviceId), 22 } 23 } 24 25 func NewDeviceIdentifier2(uuid string, major, minor int) *DeviceIdentifier { 26 return &DeviceIdentifier{ 27 UUID: uuid, 28 Major: util.Int(major), 29 Minor: util.Int(minor), 30 } 31 } 32 33 func NewDeviceIdentifier3(deviceId int64, uuid string, major, minor int) *DeviceIdentifier { 34 return &DeviceIdentifier{ 35 DeviceId: util.Int64(deviceId), 36 UUID: uuid, 37 Major: util.Int(major), 38 Minor: util.Int(minor), 39 } 40 } 41 42 // 编辑设备信息 43 func Update(clt *core.Client, deviceIdentifier *DeviceIdentifier, comment string) (err error) { 44 request := struct { 45 DeviceIdentifier *DeviceIdentifier `json:"device_identifier,omitempty"` 46 Comment string `json:"comment"` 47 }{ 48 DeviceIdentifier: deviceIdentifier, 49 Comment: comment, 50 } 51 52 var result core.Error 53 54 incompleteURL := "https://api.weixin.qq.com/shakearound/device/update?access_token=" 55 if err = clt.PostJSON(incompleteURL, &request, &result); err != nil { 56 return 57 } 58 59 if result.ErrCode != core.ErrCodeOK { 60 err = &result 61 return 62 } 63 return 64 }