Commit 4681dd2d by lanrion

获取jsticket,用于微信js sdk,仅支持对象存储

parent 2b9b04a8
source 'https://rubygems.org'
group :test, :development do
gem "rspec", "~> 3.0.0.beta1"
gem 'redis-namespace', '~> 1.5.1'
gem "rake", "~> 0.9.6"
gem "rspec"
gem 'redis-namespace'
gem 'simplecov', '~> 0.7.1', :require => false
gem "codeclimate-test-reporter", require: nil
gem 'coveralls', require: false
# For debugger
gem "pry-rails", "~> 0.3.2"
gem "pry-rails"
gem "pry-debugger", "~> 0.2.2"
gem "pry-byebug"
end
# Specify your gem's dependencies in weixin_authorize.gemspec
......
......@@ -15,7 +15,7 @@ module WeixinAuthorize
attr_accessor :app_id, :app_secret, :expired_at # Time.now + expires_in
attr_accessor :access_token, :redis_key
attr_accessor :storage
attr_accessor :storage, :jsticket
def initialize(app_id, app_secret, redis_key=nil)
@app_id = app_id
......@@ -35,13 +35,29 @@ module WeixinAuthorize
@storage.valid?
end
# TODO: refactor with difference storage
def js_ticket
raise ValidAccessTokenException if !is_valid?
if @jsticket.nil? || @jsticket.result["expired_at"] <= Time.now.to_i
@jsticket ||= get_jsticket
end
@jsticket.result["ticket"]
end
private
def get_jsticket
ticket = http_get("/ticket/getticket", {type: 1})
ticket.result["expired_at"] = ticket.result["expires_in"] + Time.now.to_i
ticket
end
def access_token_param
{access_token: get_access_token}
end
def http_get(url, headers={}, endpoint="plain")
puts "get jsticket" if url.include?("getticket")
headers = headers.merge(access_token_param)
WeixinAuthorize.http_get_without_token(url, headers, endpoint)
end
......
......@@ -19,16 +19,16 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.add_dependency "rest-client", ">= 1.6.7"
spec.add_dependency "redis", "~> 3.1.0"
spec.add_dependency "redis", ">= 3.1.0"
spec.add_dependency "carrierwave", "~> 0.10.0"
spec.add_dependency 'mini_magick', '~> 3.7.0'
spec.add_dependency "carrierwave", ">= 0.10.0"
spec.add_dependency 'mini_magick', '>= 3.7.0'
# A streaming JSON parsing and encoding library for Ruby (C bindings to yajl)
# https://github.com/brianmario/yajl-ruby
spec.add_dependency "yajl-ruby", "~> 1.2.0"
spec.add_dependency "yajl-ruby", ">= 1.2.0"
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment