Sha256: 7551e123665528e4bbde76d872eb788a94335eb30d03cbb1a83d951f96ce11f1

Contents?: true

Size: 663 Bytes

Versions: 3

Compression:

Stored size: 663 Bytes

Contents

require 'jsonclient'

class Wechat::Core::AccessToken

  # 获取 Access Token
  # http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
  #
  # Return hash format if success:
  # {
  #   access_token: <ACCESS_TOKEN>,
  #   expires_in: 7200
  # }
  # The ACCESS_TOKEN is 107 characters in 2015.
  def self.load(app_id, app_secret)
    message = ::JSONClient.new.get 'https://api.weixin.qq.com/cgi-bin/token',
      {
        grant_type: 'client_credential',
        appid:      app_id,     # Rails.application.secrets.wechat_app_id,
        secret:     app_secret, # Rails.application.secrets.wechat_app_secret
      }
    message.body
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wechat-core-0.3 lib/wechat/core/access_token.rb
wechat-core-0.2 lib/wechat/core/access_token.rb
wechat-core-0.1 lib/wechat/core/access_token.rb