Class: Fadada::Digest
- Inherits:
-
Object
- Object
- Fadada::Digest
- Defined in:
- lib/fadada/digest.rb
Class Method Summary collapse
-
.generate(timestamp, options = {}) ⇒ Object
生成摘要 Base64(SHA1(app_id + MD5(timestamp + 参数集合1) + SHA1(app_secret + 参数集合) + 参数集合2 )) 示例: options = { _params: { a: 1, b: 2 }, _md5_params: { a: 1, b: 2 }, _extend_params: { a: 1, b: 2 } }.
-
.verify?(params = {}) ⇒ Boolean
验证摘要.
Class Method Details
.generate(timestamp, options = {}) ⇒ Object
生成摘要 Base64(SHA1(app_id + MD5(timestamp + 参数集合1) + SHA1(app_secret + 参数集合) + 参数集合2 )) 示例: options = {
_params: { a: 1, b: 2 },
_md5_params: { a: 1, b: 2 },
_extend_params: { a: 1, b: 2 }
}
13 14 15 16 17 18 19 20 |
# File 'lib/fadada/digest.rb', line 13 def self.generate(, = {}) _biz_data = Fadada::config.app_secret + params_transform([:_params]) _sha1_biz_data = ::Digest::SHA1.hexdigest(_biz_data).upcase _md5 = ::Digest::MD5.hexdigest(params_transform([:_md5_params]) + .to_s).upcase _extend = params_transform([:_extend_params]) _data = ::Digest::SHA1.hexdigest(::Fadada::config.app_id + _md5 + _sha1_biz_data + _extend).upcase Base64.strict_encode64(_data) end |
.verify?(params = {}) ⇒ Boolean
验证摘要
24 25 26 27 28 29 |
# File 'lib/fadada/digest.rb', line 24 def self.verify?(params = {}) = params.transform_keys(&:to_sym) = [:timestamp] digest_params = { _params: { transaction_id: [:transaction_id] } } [:msg_digest].to_s == generate(, digest_params) end |