Commit 945a30a7 by Francis Zhou

add group robot signature calculate method

parent 153f3d43
......@@ -73,7 +73,7 @@ module DingtalkSdk
end
signature_str = OpenSSL::HMAC.digest('SHA256', app_secret, timestamp.to_s)
signature_str_base64 = Base64.encode64(signature_str).strip
signature_str_base64 = Base64.strict_encode64(signature_str)
Signature.new(signature_str_base64)
end
......
# frozen_string_literal: true
require 'base64'
require 'openssl'
require 'dingtalk_sdk'
require 'dingtalk_sdk/core'
require 'dingtalk_sdk/request_url'
require 'active_support/core_ext/time/zones'
module DingtalkSdk
module Robot
extend DingtalkSdk::Core
def self.calculate_signature(secret, timestamp = nil)
timestamp = Time.zone.now.to_i if timestamp.nil?
origin_str = [timestamp * 1000, secret].join("\n")
signature_str = OpenSSL::HMAC.digest('SHA256', secret, origin_str)
signature_str_base64 = Base64.strict_encode64(signature_str)
Signature.new(signature_str_base64)
end
end
end
# frozen_string_literal: true
require 'dingtalk_sdk'
require 'dingtalk_sdk/robot'
RSpec.describe DingtalkSdk::Robot do
it 'should calculate correct signature' do
timestamp = 1_603_868_410
secret = 'this is secret'
sign = DingtalkSdk::Robot.calculate_signature(secret, timestamp)
expect(sign.url_encoded).to eq('3E1RZgQrn1ZLgQGU4C4n4SMei%2BObeZVym5BbqrwOJPs%3D')
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment