-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2, Added the Beacon Page Relation wrapper class. 3, Upgraded the version from v0.2 to v0.3.
- Loading branch information
Showing
4 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'jsonclient' | ||
|
||
class Wechat::ShakeAround::BeaconPageRelation | ||
|
||
extend ::Wechat::ShakeAround::Common | ||
|
||
# 配置设备与页面的关联关系 | ||
# http://mp.weixin.qq.com/wiki/12/c8120214ec0ba08af5dfcc0da1a11400.html | ||
# | ||
# 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> }. | ||
# page_id is an integer or an integer array. | ||
# bind 关联操作标志位,0为解除关联关系,1为建立关联关系 | ||
# append 新增操作标志位,0为覆盖,1为新增 | ||
def self.create(access_token, device_id, page_id) | ||
|
||
device_identifier = normalize_device_id device_id | ||
page_ids = normalize_page_ids page_id | ||
|
||
message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/device/bindpage?access_token=#{access_token}", | ||
{ | ||
device_identifier: device_identifier, | ||
page_ids: page_ids, | ||
bind: 1, | ||
append: 1 | ||
} | ||
message.body | ||
end | ||
|
||
# 配置设备与页面的关联关系 | ||
# http://mp.weixin.qq.com/wiki/12/c8120214ec0ba08af5dfcc0da1a11400.html | ||
# | ||
# 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> }. | ||
# page_id is an integer or an integer array. | ||
# bind 关联操作标志位,0为解除关联关系,1为建立关联关系 | ||
# append 新增操作标志位,0为覆盖,1为新增 | ||
def self.destroy(access_token, device_id, page_id) | ||
|
||
device_identifier = normalize_device_id device_id | ||
page_ids = normalize_page_ids page_id | ||
|
||
message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/device/bindpage?access_token=#{access_token}", | ||
{ | ||
device_identifier: device_identifier, | ||
page_ids: page_ids, | ||
bind: 0, | ||
append: 0 | ||
} | ||
message.body | ||
end | ||
=begin | ||
def self.normalize_page_id(page_id) | ||
page_id.is_a?(Array) ? page_id.map { |i| i.to_i } : [ page_id.to_i ] | ||
end | ||
=end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
require 'jsonclient' | ||
|
||
class Wechat::ShakeAround::Page | ||
|
||
extend ::Wechat::ShakeAround::Common | ||
|
||
# 查询页面列表 | ||
# http://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.' | ||
# } | ||
def self.index(access_token, offset, limit) | ||
message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/page/search?access_token=#{access_token}", | ||
{ | ||
type: 2, | ||
begin: offset.to_i, | ||
count: limit.to_i | ||
} | ||
message.body | ||
end | ||
|
||
# 查询页面列表 | ||
# http://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 可以是数字、整数或者它们的数组。 | ||
def self.load(access_token, page_id) | ||
message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/page/search?access_token=#{access_token}", | ||
{ | ||
type: 1, | ||
page_ids: normalize_page_ids(page_id) | ||
} | ||
message.body | ||
end | ||
|
||
# 删除页面 | ||
# http://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.' | ||
# } | ||
def self.destroy(access_token, page_id) | ||
message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/page/delete?access_token=#{access_token}", { page_id: page_id.to_i } | ||
message.body | ||
end | ||
|
||
# 编辑页面信息 | ||
# http://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再配置在此处。 | ||
def self.update(access_token, page_id, title, description, comment, page_link, icon_link) | ||
message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/page/update?access_token=#{access_token}", | ||
{ | ||
page_id: page_id.to_i, | ||
title: title, | ||
description: description, | ||
page_url: page_link, | ||
comment: comment, | ||
icon_url: icon_link | ||
} | ||
message.body | ||
end | ||
|
||
# 新增页面 | ||
# http://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再配置在此处。 | ||
def self.create(access_token, title, description, comment, page_link, icon_link) | ||
message = ::JSONClient.new.post "https://api.weixin.qq.com/shakearound/page/add?access_token=#{access_token}", | ||
{ | ||
title: title, | ||
description: description, | ||
page_url: page_link, | ||
comment: comment, | ||
icon_url: icon_link | ||
} | ||
message.body | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Wechat | ||
module ShakeAround | ||
VERSION = '0.2'.freeze | ||
VERSION = '0.3'.freeze | ||
end | ||
end |