BlsmMpWx
首趣微店微信公众号相关,包含了获取access_token、jsapi_ticket、用户详情、二维码、长短连接转换、发送消息等。依赖于正式环境数据库。
包含的model
VdMpMsg #消息通知
VdMpWx #微信公众号基本信息
Installation
Add this line to your application's Gemfile:
gem 'blsm-mp-wx'
And then execute:
$ bundle
Or install it yourself as:
$ gem install blsm-mp-wx
用法
初始化gem
#config/initializers/blsm_mp_wx.rb
BlsmMpWx.APP_ID='you_app_id' #默认的app_id
BlsmMpWx.APP_ID_2='another_app_id' #
获取 access_token
r = BlsmMpWx.access_token
puts "#{r}\n"
#=> awalk19233w123e09112ewq321as232
获取js_api_ticket
r = BlsmMpWx.js_api_ticket
puts "#{r}\n"
#=> awalk19233w123e09112ewq321as232
发送消息
r = BlsmMpWx.send_msg(nil, 'oOx9us4iLrID8v1MRg6KEvPXMZuY',
{
touser: "oOx9us4iLrID8v1MRg6KEvPXMZuY",
msgtype: "text",
text:
{
content: "Hello World"
}
}
)
puts "#{r}\n"
#=> true
获取js_api 签名
r = BlsmMpWx.js_api_sign_package(nil, 'http://test.wunion.4007060700.com')
puts "#{r}\n"
#=> awalk19233w123e09112ewq321as232
获取用户详情
r = BlsmMpWx.gen_wx_user_info(nil, 'oOx9us4iLrID8v1MRg6KEvPXMZuY')
puts "#{r}\n"
expect(r[:headimgurl]).to match /^http:\/\//
获取永久二维码
r = BlsmMpWx.gen_forever_qr_ticket(nil, '181')
puts "#{r}\n"
expect(r).to match /\w{30,100}/
长连接转短连接
r = BlsmMpWx.gen_short_url(nil, 'http://test.wunion.4007060700.com')
puts "#{r}\n"
expect(r).to match /^http:\/\//
将消息添加到队列
msg_content = {touser: 'ogcP4jvEx22o_BsFu03g95jHcQqw',
order_id: 'cd94ac361215014072b83064a356812c',
msg_to: 'buyer'}
# r = BlsmMpWx.create_msg(nil, 'oOx9us4iLrID8v1MRg6KEvPXMZuY', msg_content, 'score_change')
r = BlsmMpWx.create_msg('wx75766c8f4f06701f', msg_content[:touser], msg_content, 'new_order')
msg_content[:msg_to]='seller'
msg_content[:touser]='oOx9us4iLrID8v1MRg6KEvPXMZuY'
r = BlsmMpWx.create_msg(nil, msg_content[:touser], msg_content, 'new_order')
puts "#{r.inspect}\n"
expect(r.id>0).to eq(true)
获取素材列表
r = BlsmMpWx.batchget_material(nil, 'news', 0)
puts "#{r}\n"
expect(r[:item_count]>0).to match true
获取素材总数
r = BlsmMpWx.get_material_count(nil, 'news')
puts "#{r}\n"
expect(r>0).to match true
获取永久素材
r = BlsmMpWx.get_material(nil, 'AKbKJ9aEePImLoQGcYm9IDEtiHe79PPBEXae7tyGxMc')
puts "#{r}\n"
expect(r.nil?).to match false
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
- Fork it ( https://github.com/[my-github-username]/blsm-mp-wx/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request