No commit activity in last 3 years
No release in over 3 years
微信模板消息 Ruby SDK, 非官方
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

微信模板消息 Ruby SDK

微信模板消息 Ruby SDK, 支持以下功能:

  • 获取账号模板列表
  • 发送模板消息

其它 ruby gem 都封装了 access-token 获取的逻辑, 不便于分布式环境使用,此 gem access-token 均需要从参数传入

Source Code

Table of Contents

  • Installation
  • Quick Start
  • License
  • Contact

Installation

You may get the latest stable version from [Rubygems]:

$ gem install wechat_template_message

For bundler:

gem 'wechat_template_message'

Quick Start

require 'rubygems'
require 'wechat_template_message'

# 获取微信公众号模板列表
result = WechatTemplateMessage::Template.all access_token
if result.successful
  result.body.each do |element|
    template_id = element["template_id"]
    template_title = element["title"]
    template_content = element["content"]
  end  
else
  # raise error
end

# 发送模板消息
url = 'http://xxx.com'
miniprogram_data = {
  appid: "xxxx",
  "pagepath":"index?foo=bar"     
}
data = {
  first: {
      value: '您有一张车票 L2019002234324 距乘车时间小于 30 分钟, 线路: 横琴号 十号线',
      color: '#173177'
  },
  keyword1: {
      value: '2019-04-09 18:10',
      color: '#173177'
  },
  keyword2: {
      value: '横琴创意谷',
      color: '#173177'
  },
  keyword3: {
      value: '西江月',
      color: '#173177'
  },
  keyword4: {
      value: '粤C66666',
      color: '#173177'
  },
  remark: {
      value: '请提前到乘车站点候车以免耽误您的出行',
      color: '#173177'
  }
}
result = WechatTemplateMessage::Sender.template_send access_token, openid, template_id, url, miniprogram_data, data

License

The wechat_template_message ruby gem is licensed under the terms of the MIT license. See the file LICENSE for details.

Contact