class Paymax1::Header

Public Instance Methods

getHeader(method,path,query,request_data) click to toggle source

拼装请求头header

# File lib/paymax1/header.rb, line 10
def getHeader (method,path,query,request_data)
  header= {
      :Authorization => Config.settings[:secret_key],
      :nonce=>randomSerize(32),
      :timestamp=>(Time.new().to_f * 1000).to_i,
      :UA=>Config.user_agent.to_json
  }
  header.store('sign',Sign.requestSign(method,header,path,query,request_data))
  return header
end
randomSerize( len ) click to toggle source

header-nonce生成器

# File lib/paymax1/header.rb, line 24
def randomSerize( len )
  chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
  randomStr = ""
  1.upto(len) { |i| randomStr << chars[rand(chars.size-1)] }
  return randomStr
end