WeixinJsSdk
a Weixin JS-SDK toolkit.
Installation
Add this line to your application's Gemfile:
gem 'weixin_js_sdk'
And then execute:
$ bundle
Or install it yourself as:
$ gem install weixin_js_sdk
Usage
- Fetch Access Token
access_token = WeixinJsSDK::AccessToken.new(
app_id: ENV['WEIXIN_APP_ID'],
app_secret: ENV['WEIXIN_APP_SECRET']
)
#=> #<WeixinJsSDK::AccessToken:0x007ff9c488a111>
access_token.token
#=> xxx
access_token.expires_in
#=> 7200
- Fetch Ticket
ticket = WeixinJsSDK::Ticket.new(access_token: access_token.token)
#=> #<WeixinJsSDK::Ticket:0x007fe62d133c68>
ticket.token
#=> xxx
ticket.expires_in
#=> 7200
- Generate Signature
signature = WeixinJsSDK::Signature.new(
ticket: ticket.token,
nonce_str: 'Wm3WZYTPz0wzccnW',
timestamp: '1414587457',
url: 'http://mp.weixin.qq.com'
).sign
#=> f4d90daf4b3bca3078ab155816175ba34c443a7b
Contributing
- Fork it ( https://github.com/[my-github-username]/weixin_js_sdk/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