Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dingtalk-sdk
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
dingtalk-sdk
Commits
945a30a7
Commit
945a30a7
authored
Oct 28, 2020
by
Francis Zhou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add group robot signature calculate method
parent
153f3d43
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
dingtalk_sdk.rb
lib/dingtalk_sdk.rb
+1
-1
robot.rb
lib/dingtalk_sdk/robot.rb
+24
-0
robot_spec.rb
spec/dingtalk_sdk/robot_spec.rb
+14
-0
No files found.
lib/dingtalk_sdk.rb
View file @
945a30a7
...
@@ -73,7 +73,7 @@ module DingtalkSdk
...
@@ -73,7 +73,7 @@ module DingtalkSdk
end
end
signature_str
=
OpenSSL
::
HMAC
.
digest
(
'SHA256'
,
app_secret
,
timestamp
.
to_s
)
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
)
Signature
.
new
(
signature_str_base64
)
end
end
...
...
lib/dingtalk_sdk/robot.rb
0 → 100644
View file @
945a30a7
# 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
spec/dingtalk_sdk/robot_spec.rb
0 → 100644
View file @
945a30a7
# 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment