Sha256: d5d35c3225bb1472b937e4afd0fa7533207cfc12afaf105883749b93d382faec

Contents?: true

Size: 690 Bytes

Versions: 8

Compression:

Stored size: 690 Bytes

Contents

module Rongcloud
  module Sign

    #生成header数据
    def self.gen_headers
      app_key = Rongcloud.app_key
      app_secret = Rongcloud.app_secret
      nonce = Rongcloud::Sign.random_str(32)
      time_stamp = Time.now.to_i
      signature = Digest::SHA1.hexdigest("#{app_secret}#{nonce}#{time_stamp}")
      {
          'App-Key' => app_key,
          'Nonce' => nonce,
          'Timestamp' => time_stamp,
          'Signature' => signature
      }
    end

    #生成随机字符串
    def self.random_str(length)
      seed = '0123456789abcdefjhijklmnopqrstuvwxyz'
      length.times.inject('') { |acc, t|
        acc+ seed[Random.rand(seed.length)]
      }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rongcloud-0.1.7 lib/rongcloud/sign.rb
rongcloud-0.1.6 lib/rongcloud/sign.rb
rongcloud-0.1.5 lib/rongcloud/sign.rb
rongcloud-0.1.4 lib/rongcloud/sign.rb
rongcloud-0.1.3 lib/rongcloud/sign.rb
rongcloud-0.1.2 lib/rongcloud/sign.rb
rongcloud-0.1.1 lib/rongcloud/sign.rb
rongcloud-0.1.0 lib/rongcloud/sign.rb