Class: Wechat::ShakeAround::Beacon

Inherits:
Object
  • Object
show all
Extended by:
Common
Defined in:
lib/wechat/shake_around/beacon.rb

Constant Summary

Constants included from Common

Common::ERROR_CODES

Class Method Summary collapse

Methods included from Common

normalize_date, normalize_device_id, normalize_page_ids

Class Method Details

.index(access_token, offset, limit, apply_id = nil) ⇒ Object

查询设备列表mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html#.E6.9F.A5.E8.AF.A2.E8.AE.BE.E5.A4.87.E5.88.97.E8.A1.A8

Return hash format if success: {

data:
{
  devices:
  [
    {
      comment:          '',
      device_id:        <DEVICE_ID>,
      major:            <MAJOR>,
      minor:            <MINOR>,
      status:           <STATUS>,           // 激活状态,0:未激活,1:已激活
      last_active_time: <LAST_ACTIVE_TIME>, // 设备最近一次被摇到的日期(最早只能获取前一天的数据);新申请的设备该字段值为0 
      poi_id:           <POI_ID>,           // 设备关联的门店ID,关联门店后,在门店1KM的范围内有优先摇出信息的机会。门店相关信息具体可查看门店相关的接口文档
      uuid:             <UUID>
    }
  ],
  total_count: <TOTAL_COUNT> // 商户名下的设备总量
},
errcode: 0,
errmsg:  'success.'

}



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/wechat/shake_around/beacon.rb', line 32

def self.index(access_token, offset, limit, apply_id = nil)
  options = { begin: offset, count: limit }
  if apply_id.present?
    options[:apply_id] = apply_id
    options[:type]     = 3
  else
    options[:type]     = 2
  end
  message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/device/search?access_token=#{access_token}", options
  message.body
end

.load(access_token, device_id) ⇒ Object

查询设备列表mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html#.E6.9F.A5.E8.AF.A2.E8.AE.BE.E5.A4.87.E5.88.97.E8.A1.A8

Return hash format if success: {

data:
{
  devices:
  [
    {
      comment:          '',
      device_id:        <DEVICE_ID>,
      major:            <MAJOR>,
      minor:            <MINOR>,
      status:           <STATUS>,           // 激活状态,0:未激活,1:已激活
      last_active_time: <LAST_ACTIVE_TIME>, // 设备最近一次被摇到的日期(最早只能获取前一天的数据);新申请的设备该字段值为0 
      poi_id:           <POI_ID>,           // 设备关联的门店ID,关联门店后,在门店1KM的范围内有优先摇出信息的机会。门店相关信息具体可查看门店相关的接口文档
      uuid:             <UUID>
    }
  ],
  total_count: <TOTAL_COUNT> // 商户名下的设备总量
},
errcode: 0,
errmsg:  'success.'

}

device_id is an integer or a hash like { uuid: <UUID>, major: <MAJOR>, minor: <MINOR> }.



71
72
73
74
75
76
77
78
79
# File 'lib/wechat/shake_around/beacon.rb', line 71

def self.load(access_token, device_id)
  device_identifier = self.normalize_device_id device_id
  message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/device/search?access_token=#{access_token}",
    {
      type:               1,
      device_identifiers: [ device_identifier ]
    }
  message.body
end

.update(access_token, device_id, comment) ⇒ Object

编辑设备信息mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html#.E7.BC.96.E8.BE.91.E8.AE.BE.E5.A4.87.E4.BF.A1.E6.81.AF

Return hash format if success:

data:    {,
errcode: 0,
errmsg:  'success.'

}

device_id is an integer or a hash like { uuid: <UUID>, major: <MAJOR>, minor: <MINOR> }.



92
93
94
95
96
97
98
99
100
# File 'lib/wechat/shake_around/beacon.rb', line 92

def self.update(access_token, device_id, comment)
  device_identifier = self.normalize_device_id device_id
  message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/device/update?access_token=#{access_token}",
    {
      device_identifier: device_identifier,
      comment:           comment
    }
  message.body
end