Module: Paymax1::Http
- Defined in:
- lib/paymax1/http.rb
Constant Summary collapse
- @@VALID_RESPONSE_TTL =
合法响应时间:2分钟内
2*60*1000
Class Method Summary collapse
-
.checkResponse(response) ⇒ Object
post.
- .get(url, header = {}) ⇒ Object
- .post(url, header = {}, req_body) ⇒ Object
Class Method Details
.checkResponse(response) ⇒ Object
post
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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 = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 |