module Paymax1::Http
Public Class Methods
checkResponse(response)
click to toggle source
# File lib/paymax1/http.rb, line 62 def checkResponse response isVerify = Sign.responseSignVerify(response.headers,response.body); if !isVerify then raise AuthorizationException.new('Invalid Response.[Response Data And Sign Verify Failure.]') end if @@VALID_RESPONSE_TTL.to_i+response.headers[:timestamp].to_i<(Time.new().to_f * 1000).to_i then raise InvalidResponseException('Invalid Response.[Response Time Is Invalid.]') end if !Config.settings[:secret_key].to_s == response.headers[:authorization].to_s then raise InvalidResponseException('Invalid Response.[Secret Key Is Invalid.]') end end
get(url, header = {})
click to toggle source
# File lib/paymax1/http.rb, line 14 def get (url, header = {}) # 配置请求Header req_headers = { :'Content-Type' => 'application/json;charset=utf-8', :'content-length' => 0, :'Authorization' => header[:Authorization], :'nonce' => header[:nonce], :'timestamp' => header[:timestamp], :'sign' => header['sign'], :'X-Paymax-Client-User-Agent' => header[:UA] } # 发送请求 puts 'url::'+url begin response = RestClient.get(url, req_headers) rescue => e #responseCode>400 return e.response end self.checkResponse response return response end
post(url, header = {},req_body)
click to toggle source
# File lib/paymax1/http.rb, line 41 def post (url, header = {},req_body) # 配置请求Header req_headers = { :'Content-Type' => 'application/json;charset=utf-8', :'Authorization' => header[:Authorization], :'nonce' => header[:nonce], :'timestamp' => header[:timestamp], :'sign' => header['sign'], :'X-Paymax-Client-User-Agent' => header[:UA] } # 发送请求 begin response = RestClient.post(url, req_body.to_s, req_headers) self.checkResponse response return response.body rescue => e return e.response end end