Sha256: 68f0047964a95998a7a72f233c3ed42beb22d15a20d3f265a0c66706c9093177
Contents?: true
Size: 1018 Bytes
Versions: 3
Compression:
Stored size: 1018 Bytes
Contents
# coding: utf-8 module RockFintech module Sign def self.sign(data, config) serialize_str = serialize(data) Sign::MD5.sign(serialize_str, Sign::MD5.sign(config[:rft_key], config[:rft_secret])) end # sign def self.verify(data, config) sign_str = data.delete(:sign) self.sign(data, config) == sign_str end # verify private def self.serialize(data) data = Hash[data.sort] # key 按照 alphabet 排序 data.each{ |k, v| if v.kind_of?(Hash) # 如果是 hash 接着 serialize data[k] = serialize(v) elsif v.kind_of?(Array) if v[0].kind_of?(Hash) # 如果是 hash 数组对元素接着 serialize v.each_with_index{ |ele, index| v[index] = ele.to_json #serialize(ele) } else # 如果是普通元素数组 data[k] = v.join('&') end end } data.map{|k,v| "#{k}=#{v}"}.join('&') end # serialize end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rock_fintech-0.7.0 | lib/rock_fintech/sign/sign.rb |
rock_fintech-0.6.0 | lib/rock_fintech/sign/sign.rb |
rock_fintech-0.5.0 | lib/rock_fintech/sign/sign.rb |