Module: LiooooUtils::SigCheck
- Defined in:
- lib/sigcheck.rb
Class Method Summary collapse
-
.makeSig(method, url_path, params, secret) ⇒ Object
生成URL签名.
- .makeSource(method, url_path, params) ⇒ Object
Class Method Details
.makeSig(method, url_path, params, secret) ⇒ Object
生成URL签名
13 14 15 16 17 18 19 |
# File 'lib/sigcheck.rb', line 13 def makeSig(method, url_path, params, secret) mk = makeSource(method, url_path, params) _secret = secret.tr('-_', '+/') my_sign = Digest::HMAC.digest(mk, _secret, Digest::SHA1) my_sign = Base64.encode64(my_sign).gsub("\n", "") return my_sign end |
.makeSource(method, url_path, params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sigcheck.rb', line 21 def makeSource(method, url_path, params) _method = method.upcase _url_path = CGI.escape(url_path) _query_string = params.sort.collect { |v| v.join('=') }.join('&') query_string = CGI.escape(_query_string) _strs = "#{_method}&#{_url_path}&" strs = _strs.gsub('~', '%7E') _source_str = "#{strs}#{query_string}".gsub('+', '%20') return _source_str end |