Module: Dingtalk::Signature

Extended by:
Signature
Included in:
Signature
Defined in:
app/apis/dingtalk/signature.rb

Instance Method Summary collapse

Instance Method Details

#signature(secret, timestamp = (Time.current.to_f * 1000).round) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
# File 'app/apis/dingtalk/signature.rb', line 5

def signature(secret, timestamp = (Time.current.to_f * 1000).round)
  raise ArgumentError, 'timestamp must in millis' if Math.log10(timestamp).ceil < 13

  origin_str = [timestamp, secret].join("\n")
  signature_str = OpenSSL::HMAC.digest('SHA256', secret, origin_str)
  signature_str_base64 = Base64.strict_encode64(signature_str)

  URI.encode_www_form_component(signature_str_base64)
end