Class: Paymax1::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/paymax1/header.rb

Instance Method Summary collapse

Instance Method Details

#getHeader(method, path, query, request_data) ⇒ Object

拼装请求头header



10
11
12
13
14
15
16
17
18
19
# 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) ⇒ Object

header-nonce生成器



24
25
26
27
28
29
# 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