Class: Wechat::ShakeAround::Page

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

Overview

Page 是管理页面的封装类。

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

.create(access_token, title, description, comment, page_link, icon_link) ⇒ Object

新增页面 mp.weixin.qq.com/wiki/5/6626199ea8757c752046d8e46cf13251.html#.E6.96.B0.E5.A2.9E.E9.A1.B5.E9.9D.A2

Return hash format if success: {

data:    { page_id: <PAGE_ID> },
errcode: 0,
errmsg:  'success.'

}

title 在摇一摇页面展示的主标题,不超过6个汉字或12个英文字母。 description 在摇一摇页面展示的副标题,不超过7个汉字或14个英文字母。 comment 页面的备注信息,不超过15个汉字或30个英文字母。 icon_link 在摇一摇页面展示的图片。图片需先上传至微信侧服务器,用“素材管理-上传图片素材”接口上传图片,返回的图片URL再配置在此处。



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/wechat/shake_around/page.rb', line 159

def self.create(access_token, title, description, comment, page_link, icon_link)

  assert_present! :access_token, access_token
  assert_present! :title,        title
  assert_present! :description,  description
  assert_present! :comment,      comment
  assert_present! :page_link,    page_link
  assert_present! :icon_link,    icon_link

  post_json "https://api.weixin.qq.com/shakearound/page/add?access_token=#{access_token}", body:
    {
      title:       title,
      description: description,
      page_url:    page_link,
      comment:     comment,
      icon_url:    icon_link
    }
end

.destroy(access_token, page_id) ⇒ Object

删除页面 mp.weixin.qq.com/wiki/5/6626199ea8757c752046d8e46cf13251.html#.E5.88.A0.E9.99.A4.E9.A1.B5.E9.9D.A2

Return hash format if success:

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

}



97
98
99
100
101
102
103
104
105
106
# File 'lib/wechat/shake_around/page.rb', line 97

def self.destroy(access_token, page_id)

  assert_present! :access_token, access_token
  assert_present! :page_id,      page_id

  post_json "https://api.weixin.qq.com/shakearound/page/delete?access_token=#{access_token}", body:
    {
      page_id: page_id.to_i
    }
end

.index(access_token, offset, limit) ⇒ Object

查询页面列表 mp.weixin.qq.com/wiki/5/6626199ea8757c752046d8e46cf13251.html#.E6.9F.A5.E8.AF.A2.E9.A1.B5.E9.9D.A2.E5.88.97.E8.A1.A8

Return hash format if success: {

data:
{
  pages:
  [
    {
      comment:     <COMMENT>,     // 页面的备注信息
      description: <DESCRIPTION>, // 在摇一摇页面展示的副标题
      icon_url:    <ICON_LINK>,   // 在摇一摇页面展示的图片
      page_id:     <PAGE_ID>,     // 摇周边页面唯一ID
      page_url:    <PAGE_LINK>,   // 跳转链接
      title:       <TITLE>        // 在摇一摇页面展示的主标题
    },
    ...
  ],
  total_count: <TOTAL_COUNT>      // 商户名下的页面总数
},
errcode:     0,
errmsg:      'success.'

}



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wechat/shake_around/page.rb', line 34

def self.index(access_token, offset, limit)

  assert_present! :access_token, access_token
  assert_present! :offset,       offset
  assert_present! :limit,        limit

  post_json "https://api.weixin.qq.com/shakearound/page/search?access_token=#{access_token}", body:
    {
      type:  2,
      begin: offset.to_i,
      count: limit.to_i
    }
end

.load(access_token, page_id) ⇒ Object

查询页面列表 mp.weixin.qq.com/wiki/5/6626199ea8757c752046d8e46cf13251.html#.E6.9F.A5.E8.AF.A2.E9.A1.B5.E9.9D.A2.E5.88.97.E8.A1.A8

Return hash format if success: {

data:
{
  pages:
  [
    {
      comment:     <COMMENT>,     // 页面的备注信息
      description: <DESCRIPTION>, // 在摇一摇页面展示的副标题
      icon_url:    <ICON_LINK>,   // 在摇一摇页面展示的图片
      page_id:     <PAGE_ID>,     // 摇周边页面唯一ID
      page_url:    <PAGE_LINK>,   // 跳转链接
      title:       <TITLE>        // 在摇一摇页面展示的主标题
    },
    ...
  ],
  total_count: <TOTAL_COUNT>      // 商户名下的页面总数
},
errcode:     0,
errmsg:      'success.'

}

page_id 可以是数字、整数或者它们的数组。



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/wechat/shake_around/page.rb', line 75

def self.load(access_token, page_id)

  assert_present! :access_token, access_token
  assert_present! :page_id,      page_id

  post_json "https://api.weixin.qq.com/shakearound/page/search?access_token=#{access_token}", body:
    {
      type:     1,
      page_ids: normalize_page_ids(page_id)
    }
end

.update(access_token, page_id, title, description, comment, page_link, icon_link) ⇒ Object

编辑页面信息 mp.weixin.qq.com/wiki/5/6626199ea8757c752046d8e46cf13251.html#.E7.BC.96.E8.BE.91.E9.A1.B5.E9.9D.A2.E4.BF.A1.E6.81.AF

Return hash format if success:

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

}

title 在摇一摇页面展示的主标题,不超过6个汉字或12个英文字母。 description 在摇一摇页面展示的副标题,不超过7个汉字或14个英文字母。 comment 页面的备注信息,不超过15个汉字或30个英文字母。 icon_link 在摇一摇页面展示的图片。图片需先上传至微信侧服务器,用“素材管理-上传图片素材”接口上传图片,返回的图片URL再配置在此处。



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/wechat/shake_around/page.rb', line 123

def self.update(access_token, page_id, title, description, comment, page_link, icon_link)

  assert_present! :access_token, access_token
  assert_present! :page_id,      page_id
  assert_present! :title,        title
  assert_present! :description,  description
  assert_present! :comment,      comment
  assert_present! :page_link,    page_link
  assert_present! :icon_link,    icon_link

  post_json "https://api.weixin.qq.com/shakearound/page/update?access_token=#{access_token}", body:
    {
      page_id:     page_id.to_i,
      title:       title,
      description: description,
      page_url:    page_link,
      comment:     comment,
      icon_url:    icon_link
    }
end