Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_dingtalk
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
other
rails_dingtalk
Commits
24174c61
Commit
24174c61
authored
Sep 12, 2021
by
mingyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
saas
parent
0ebdd496
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
18 deletions
+31
-18
Gemfile.lock
Gemfile.lock
+4
-1
saas.rb
app/apis/dingtalk/api/saas.rb
+15
-12
http_client.rb
app/apis/dingtalk/http_client.rb
+6
-1
saas_app.rb
app/models/dingtalk/model/app/saas_app.rb
+1
-1
config.rb
lib/rails_dingtalk/config.rb
+5
-3
No files found.
Gemfile.lock
View file @
24174c61
...
@@ -7,7 +7,7 @@ GIT
...
@@ -7,7 +7,7 @@ GIT
GIT
GIT
remote: https://github.com/work-design/rails_com.git
remote: https://github.com/work-design/rails_com.git
revision:
8949509c4f26ecf76adecfdbb2e221535ee47ac0
revision:
62d866862c729077c67329a0faf255ebaa49eba2
specs:
specs:
rails_com (1.2.9)
rails_com (1.2.9)
acme-client
acme-client
...
@@ -183,6 +183,8 @@ GEM
...
@@ -183,6 +183,8 @@ GEM
nio4r (2.5.8)
nio4r (2.5.8)
nokogiri (1.12.4-x86_64-darwin)
nokogiri (1.12.4-x86_64-darwin)
racc (~> 1.4)
racc (~> 1.4)
nokogiri (1.12.4-x86_64-linux)
racc (~> 1.4)
pg (1.2.3)
pg (1.2.3)
puma (5.4.0)
puma (5.4.0)
nio4r (~> 2.0)
nio4r (~> 2.0)
...
@@ -250,6 +252,7 @@ GEM
...
@@ -250,6 +252,7 @@ GEM
PLATFORMS
PLATFORMS
x86_64-darwin-20
x86_64-darwin-20
x86_64-linux
DEPENDENCIES
DEPENDENCIES
amazing_print
amazing_print
...
...
app/apis/dingtalk/api/saas.rb
View file @
24174c61
require
'net/http'
module
Dingtalk::Api
module
Dingtalk::Api
class
Saas
<
Base
class
Saas
<
Base
BASE
=
'https://openplatform.dg-work.cn/'
BASE
=
'https://openplatform.dg-work.cn/'
def
token
def
token
payload
=
{
headers
=
sign_header
(
'POST'
,
'/gettoken.json'
)
appkey:
app
.
app_key
,
r
=
@client
.
post
'gettoken.json'
,
nil
,
headers:
headers
,
base:
BASE
appsecret:
app
.
app_secret
,
}
r
=
@client
.
post
'gettoken.json'
,
payload
.
to_json
,
headers:
{
},
base:
BASE
{
{
'access_token'
=>
r
.
dig
(
'content'
,
'data'
,
'accessToken'
),
'access_token'
=>
r
.
dig
(
'content'
,
'data'
,
'accessToken'
),
'expires_in'
=>
r
.
dig
(
'content'
,
'data'
,
'expiresIn'
)
'expires_in'
=>
r
.
dig
(
'content'
,
'data'
,
'expiresIn'
)
}
}
end
end
def
sign_header
def
sign_header
(
method
,
path
,
params
=
{})
headers
=
{
headers
=
{
apiKey:
app
.
app_key
,
apiKey:
app
.
app_key
,
'X-Hmac-Auth-Timestamp'
:
Time
.
now
.
to_s
(
:iso8601
),
'X-Hmac-Auth-Timestamp'
:
Time
.
now
.
strftime
(
'%Y-%m-%dT%H:%M:%S.%3N%:z'
),
'X-Hmac-Auth-Nonce'
:
(
Time
.
now
.
to_f
*
1000
).
round
.
to_s
+
rand
(
1000
..
9999
).
to_s
,
'X-Hmac-Auth-Nonce'
:
(
Time
.
now
.
to_f
*
1000
).
round
.
to_s
+
rand
(
1000
..
9999
).
to_s
,
'X-Hmac-Auth-Version'
:
'1.0'
,
'X-Hmac-Auth-Version'
:
'1.0'
,
'X-Hmac-Auth-IP'
:
RailsDingtalk
.
config
.
ip
,
'X-Hmac-Auth-IP'
:
RailsDingtalk
.
config
.
ip
,
'X-Hmac-Auth-MAC'
:
RailsDingtalk
.
config
.
mac
'X-Hmac-Auth-MAC'
:
RailsDingtalk
.
config
.
mac
}
}
result
=
[
method
,
headers
[
:'X-Hmac-Auth-Timestamp'
],
headers
[
:'X-Hmac-Auth-Nonce'
],
path
]
result
<<
params
.
to_query
if
params
.
present?
signature
=
OpenSSL
::
HMAC
.
digest
(
'SHA256'
,
app
.
app_secret
,
result
.
join
(
"
\n
"
))
headers
.
merge!
'X-Hmac-Auth-Signature'
:
Base64
.
strict_encode64
(
signature
)
end
end
protected
protected
def
with_access_token
(
params
=
{},
tries
=
2
)
def
with_access_token
(
params
=
{},
tries
=
2
)
yield
params
.
merge!
(
yield
params
accessKey:
app
.
app_key
,
secretKey:
app
.
app_secret
)
rescue
=>
e
rescue
=>
e
Rails
.
logger
.
debug
e
.
full_message
Rails
.
logger
.
debug
e
.
full_message
retry
unless
(
tries
-=
1
).
zero?
retry
unless
(
tries
-=
1
).
zero?
...
...
app/apis/dingtalk/http_client.rb
View file @
24174c61
...
@@ -22,7 +22,12 @@ module Dingtalk
...
@@ -22,7 +22,12 @@ module Dingtalk
headers
[
'Content-Type'
]
||=
'application/json'
headers
[
'Content-Type'
]
||=
'application/json'
url
=
base
+
path
url
=
base
+
path
response
=
@http
.
with_headers
(
headers
).
post
(
url
,
params:
params
,
body:
payload
)
opts
=
{
params:
params
}
opts
.
merge!
(
body:
payload
)
if
payload
.
present?
response
=
@http
.
with_headers
(
headers
).
post
(
url
,
**
opts
)
parse_response
(
response
,
options
[
:as
])
parse_response
(
response
,
options
[
:as
])
end
end
...
...
app/models/dingtalk/model/app/saas_app.rb
View file @
24174c61
...
@@ -16,7 +16,7 @@ module Dingtalk
...
@@ -16,7 +16,7 @@ module Dingtalk
end
end
def
generate_user
(
code
)
def
generate_user
(
code
)
binding
.
b
api
.
token
end
end
end
end
...
...
lib/rails_dingtalk/config.rb
View file @
24174c61
...
@@ -5,10 +5,12 @@ module RailsDingtalk
...
@@ -5,10 +5,12 @@ module RailsDingtalk
config
.
httpx
=
{
config
.
httpx
=
{
ssl:
{
ssl:
{
verify_mode:
OpenSSL
::
SSL
::
VERIFY_NONE
verify_mode:
OpenSSL
::
SSL
::
VERIFY_NONE
},
debug:
STDERR
,
debug_level:
-
1
}
}
}
config
.
ip
=
'127.0.0.1'
config
.
ip
=
'192.168.0.1'
config
.
mac
=
'78:7b:8a:dd:94:cc'
config
.
mac
=
'fa:16:3e:27:49:91'
end
end
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