class EasyWechat::Client
Constants
- ADD_NEWS_URL
- BATCHGET_MATERIAL_URL
- GET_TICKET_URL
- GET_USER_CUMULATE_URL
- GET_USER_SUMMARY_URL
- TOKEN_URL
- UPLOADIMG_URL
Public Class Methods
new()
click to toggle source
# File lib/easy_wechat/client.rb, line 16 def initialize end
Public Instance Methods
access_token()
click to toggle source
# File lib/easy_wechat/client.rb, line 19 def access_token @access_token ||= token["access_token"] end
add_news(articles) { |r| ... }
click to toggle source
新增永久图文素材 developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
# File lib/easy_wechat/client.rb, line 59 def add_news(articles) payload = { articles: articles } resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload) r = ::JSON.parse(resp.body, quirks_mode: true) yield r if block_given? r end
batchget_material(type = "image", offset = 0, count = 20) { |r| ... }
click to toggle source
获取永久素材的列表 developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
# File lib/easy_wechat/client.rb, line 79 def batchget_material(type = "image", offset = 0, count = 20) # TODO: 检查参数完整性 # TODO: 检查参数合法性 payload = { type: type, offset: offset, count: count } resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload) r = ::JSON.parse(resp.body, quirks_mode: true) yield r if block_given? r end
get_ticket(type) { |r| ... }
click to toggle source
# File lib/easy_wechat/client.rb, line 69 def get_ticket(type) resp = HTTPX.get(GET_TICKET_URL, params: { access_token: access_token, type: type }) r = ::JSON.parse(resp.body, quirks_mode: true) yield r if block_given? r end
get_user_cumulate(begin_date, end_date) { |r| ... }
click to toggle source
# File lib/easy_wechat/client.rb, line 33 def get_user_cumulate(begin_date, end_date) payload = { begin_date: begin_date, end_date: end_date } resp = HTTPX.post(GET_USER_CUMULATE_URL, params: { access_token: access_token }, json: payload) r = ::JSON.parse(resp.body, quirks_mode: true) yield r if block_given? r end
get_user_summary(begin_date, end_date) { |r| ... }
click to toggle source
# File lib/easy_wechat/client.rb, line 23 def get_user_summary(begin_date, end_date) payload = { begin_date: begin_date, end_date: end_date } resp = HTTPX.post(GET_USER_SUMMARY_URL, params: { access_token: access_token }, json: payload) r = ::JSON.parse(resp.body, quirks_mode: true) yield r if block_given? r end
token() { |r| ... }
click to toggle source
获取access_token developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
# File lib/easy_wechat/client.rb, line 45 def token resp = HTTPX.get(TOKEN_URL, params: { appid: EasyWechat.app_id, secret: EasyWechat.app_secret, grant_type: "client_credential", }) r = ::JSON.parse(resp.body, quirks_mode: true) yield r if block_given? r end
uploadimg(media) { |r| ... }
click to toggle source
上传图文消息内的图片获取URL developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
# File lib/easy_wechat/client.rb, line 93 def uploadimg(media) # media path or Tempfile # https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes file = HTTP::FormData::File.new(media) resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file }) r = ::JSON.parse(resp.body, quirks_mode: true) yield r if block_given? r end