Class: Junziqian::Tool::HttpSignUtils
- Inherits:
-
Object
- Object
- Junziqian::Tool::HttpSignUtils
- Defined in:
- lib/junziqian/tool/http_sign_utils.rb
Class Method Summary collapse
- .create_http_sign(body_params, timestamp = nil) ⇒ Object
- .create_http_url(body_params, timestamp = nil) ⇒ Object
- .get_millisecond ⇒ Object
- .get_params(hash) ⇒ Object
Class Method Details
.create_http_sign(body_params, timestamp = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/junziqian/tool/http_sign_utils.rb', line 21 def create_http_sign body_params, = nil ||= get_millisecond contactStr = [] contactStr << get_params(body_params) contactStr << ("timestamp"+) contactStr << ("appKey"+ Cfg::ClientInfo.app_key) contactStr << ("appSecret"+ Cfg::ClientInfo.app_secret;) Digest::SHA1.hexdigest(contactStr.join('')); end |
.create_http_url(body_params, timestamp = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/junziqian/tool/http_sign_utils.rb', line 7 def create_http_url body_params, = nil ||= get_millisecond sign=create_http_sign(body_params, ) url='timestamp='++'&'; #timestamp必须放在最前面民 body_params.each do |k, v| url += k.to_s + URI::escape(v.strip) end url += "sign=#{sign}" end |
.get_millisecond ⇒ Object
17 18 19 |
# File 'lib/junziqian/tool/http_sign_utils.rb', line 17 def get_millisecond (Time.now.to_f*1000).to_i.to_s end |
.get_params(hash) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/junziqian/tool/http_sign_utils.rb', line 31 def get_params(hash) contactStr=[] if hash.present? hash.sort.map {|array_item| contactStr << [array_item[0], array_item[1].strip] } end contactStr.flatten.join('') end |