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
0094fa1e
Commit
0094fa1e
authored
Sep 12, 2021
by
mingyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sass
parent
5471c943
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
22 deletions
+24
-22
base.rb
app/apis/dingtalk/api/base.rb
+1
-1
saas.rb
app/apis/dingtalk/api/inner/saas.rb
+3
-8
saas.rb
app/apis/dingtalk/api/saas.rb
+14
-7
http_client.rb
app/apis/dingtalk/http_client.rb
+5
-2
saas_app.rb
app/models/dingtalk/model/app/saas_app.rb
+0
-1
config.rb
lib/rails_dingtalk/config.rb
+1
-3
No files found.
app/apis/dingtalk/api/base.rb
View file @
0094fa1e
...
...
@@ -28,7 +28,7 @@ module Dingtalk::Api
def
post
(
path
,
params:
{},
headers:
{},
base:
base_host
,
**
payload
)
with_access_token
(
'post'
,
path
,
params
,
headers
,
payload
)
do
|
processed_params
,
processed_headers
|
@client
.
post
path
,
payload
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
@client
.
post
path
,
payload
.
to_json
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
end
end
...
...
app/apis/dingtalk/api/inner/saas.rb
View file @
0094fa1e
module
Dingtalk::Api
module
Inner::Saas
BASE
=
'https://openplatform.dg-work.cn
/
'
BASE
=
'https://openplatform.dg-work.cn'
def
getuserinfo
(
code
)
payload
=
{
auth_code:
code
}
headers
=
sign_access_header
(
'POST'
,
'/gettoken.json'
,
payload
)
r
=
post
'rpc/oauth2/dingtalk_app_user.json'
,
headers:
headers
,
base:
BASE
r
=
post
'/rpc/oauth2/dingtalk_app_user.json'
,
auth_code:
code
,
base:
BASE
binding
.
b
if
r
.
is_a?
Hash
r
[
'result'
]
r
.
dig
(
'content'
,
'data'
)
else
r
end
...
...
app/apis/dingtalk/api/saas.rb
View file @
0094fa1e
module
Dingtalk::Api
class
Saas
<
Base
include
Inner
::
Saas
BASE
=
'https://openplatform.dg-work.cn
/
'
BASE
=
'https://openplatform.dg-work.cn'
def
token
headers
=
sign_header
(
'POST'
,
'/gettoken.json'
)
...
...
@@ -12,12 +12,19 @@ module Dingtalk::Api
}
end
def
post
(
path
,
params:
{},
headers:
{},
base:
base_host
,
**
payload
)
with_access_token
(
'post'
,
path
,
params
,
headers
,
payload
)
do
|
processed_params
,
processed_headers
|
@client
.
post
path
,
payload
.
to_query
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
end
end
protected
def
with_access_token
(
method
,
path
,
params
=
{},
headers
=
{},
payload
=
{},
tries
=
2
)
app
.
refresh_access_token
unless
app
.
access_token_valid?
processed_params
=
params
.
merge!
(
access_token:
app
.
access_token
)
processed_headers
=
sign_header
(
method
,
path
,
processed_params
,
payload
)
yield
processed_params
,
processed_headers
payload
.
merge!
(
access_token:
app
.
access_token
)
#params.merge!(access_token: app.access_token)
processed_headers
=
sign_header
(
method
,
path
,
params
,
payload
)
yield
params
,
processed_headers
rescue
=>
e
Rails
.
logger
.
debug
e
.
full_message
app
.
refresh_access_token
...
...
@@ -27,8 +34,8 @@ module Dingtalk::Api
def
sign_header
(
method
,
path
,
params
=
{},
payload
=
{})
headers
=
{
apiKey:
app
.
app_key
,
'X-Hmac-Auth-Timestamp'
:
Time
.
now
.
strftime
(
'%Y-%m-%dT%H:%M:%S.%
3
N%:z'
),
'X-Hmac-Auth-Nonce'
:
(
Time
.
now
.
to_f
*
1000
).
round
.
to_s
+
rand
(
1000
..
9999
).
to_s
,
'X-Hmac-Auth-Timestamp'
:
Time
.
now
.
strftime
(
'%Y-%m-%dT%H:%M:%S.%
6
N%:z'
),
'X-Hmac-Auth-Nonce'
:
'16314248251027993'
,
#
(Time.now.to_f * 1000).round.to_s + rand(1000..9999).to_s,
'X-Hmac-Auth-Version'
:
'1.0'
,
'X-Hmac-Auth-IP'
:
RailsDingtalk
.
config
.
ip
,
'X-Hmac-Auth-MAC'
:
RailsDingtalk
.
config
.
mac
...
...
@@ -40,7 +47,7 @@ module Dingtalk::Api
headers
[
:'X-Hmac-Auth-Nonce'
],
path
]
result
<<
params
.
merge
(
payload
).
to_query
if
params
.
present?
result
<<
params
.
merge
(
payload
).
to_query
if
params
.
present?
||
payload
.
present?
signature
=
OpenSSL
::
HMAC
.
digest
(
'SHA256'
,
app
.
app_secret
,
result
.
join
(
"
\n
"
))
headers
.
merge!
'X-Hmac-Auth-Signature'
:
Base64
.
strict_encode64
(
signature
)
end
...
...
app/apis/dingtalk/http_client.rb
View file @
0094fa1e
...
...
@@ -23,11 +23,14 @@ module Dingtalk
url
=
base
+
path
opts
=
{
params:
params
params:
params
,
headers:
headers
}
opts
.
merge!
(
body:
payload
.
to_json
)
if
payload
.
present?
opts
.
merge!
(
body:
payload
)
if
payload
.
present?
response
=
@http
.
with_headers
(
headers
).
post
(
url
,
**
opts
)
binding
.
b
parse_response
(
response
,
options
[
:as
])
end
...
...
app/models/dingtalk/model/app/saas_app.rb
View file @
0094fa1e
...
...
@@ -17,7 +17,6 @@ module Dingtalk
def
generate_user
(
code
)
r
=
api
.
getuserinfo
(
code
)
binding
.
b
end
end
...
...
lib/rails_dingtalk/config.rb
View file @
0094fa1e
...
...
@@ -5,9 +5,7 @@ module RailsDingtalk
config
.
httpx
=
{
ssl:
{
verify_mode:
OpenSSL
::
SSL
::
VERIFY_NONE
},
debug:
STDERR
,
debug_level:
-
1
}
}
config
.
ip
=
'127.0.0.1'
config
.
mac
=
'78:7b:8a:dd:94:cc'
...
...
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