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
80285ebe
Commit
80285ebe
authored
Sep 12, 2021
by
mingyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
with access token suport more params
parent
24174c61
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
41 deletions
+51
-41
base.rb
app/apis/dingtalk/api/base.rb
+8
-8
saas.rb
app/apis/dingtalk/api/inner/saas.rb
+21
-0
new.rb
app/apis/dingtalk/api/new.rb
+2
-23
saas.rb
app/apis/dingtalk/api/saas.rb
+18
-9
saas_app.rb
app/models/dingtalk/model/app/saas_app.rb
+2
-1
No files found.
app/apis/dingtalk/api/base.rb
View file @
80285ebe
...
...
@@ -21,27 +21,27 @@ module Dingtalk::Api
end
def
get
(
path
,
params:
{},
headers:
{},
base:
base_host
,
as:
nil
)
with_access_token
(
params
)
do
|
with_token_param
s
|
@client
.
get
path
,
headers:
headers
,
params:
with_token
_params
,
base:
base
,
as:
as
with_access_token
(
'get'
,
path
,
params
,
headers
)
do
|
processed_params
,
processed_header
s
|
@client
.
get
path
,
headers:
processed_headers
,
params:
processed
_params
,
base:
base
,
as:
as
end
end
def
post
(
path
,
params:
{},
headers:
{},
base:
base_host
,
**
payload
)
with_access_token
(
params
)
do
|
with_token_param
s
|
@client
.
post
path
,
payload
.
to_json
,
headers:
headers
,
params:
with_token
_params
,
base:
base
with_access_token
(
'post'
,
path
,
params
,
headers
)
do
|
processed_params
,
processed_header
s
|
@client
.
post
path
,
payload
.
to_json
,
headers:
processed_headers
,
params:
processed
_params
,
base:
base
end
end
def
post_file
(
path
,
file
,
params:
{},
headers:
{},
base:
base_host
)
with_access_token
(
params
)
do
|
with_token_param
s
|
@client
.
post_file
path
,
file
,
headers:
headers
,
params:
with_token
_params
,
base:
base
with_access_token
(
'post'
,
path
,
params
,
headers
)
do
|
processed_params
,
processed_header
s
|
@client
.
post_file
path
,
file
,
headers:
processed_headers
,
params:
processed
_params
,
base:
base
end
end
protected
def
with_access_token
(
param
s
=
{},
tries
=
2
)
def
with_access_token
(
method
,
path
,
params
=
{},
header
s
=
{},
tries
=
2
)
app
.
refresh_access_token
unless
app
.
access_token_valid?
yield
params
.
merge!
(
access_token:
app
.
access_token
)
yield
params
.
merge!
(
access_token:
app
.
access_token
)
,
headers
rescue
=>
e
Rails
.
logger
.
debug
e
.
full_message
app
.
refresh_access_token
...
...
app/apis/dingtalk/api/inner/saas.rb
0 → 100644
View file @
80285ebe
module
Dingtalk::Api
module
Inner::Saas
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
binding
.
b
if
r
.
is_a?
Hash
r
[
'result'
]
else
r
end
end
end
end
app/apis/dingtalk/api/new.rb
View file @
80285ebe
...
...
@@ -19,31 +19,10 @@ module Dingtalk::Api
BASE
end
def
get
(
path
,
params:
{},
headers:
{},
base:
base_host
,
as:
nil
)
with_access_token
(
headers
)
do
|
with_token_headers
|
@client
.
get
path
,
headers:
with_token_headers
,
params:
params
,
base:
base
,
as:
as
end
end
def
post
(
path
,
params:
{},
headers:
{},
base:
base_host
,
**
payload
)
with_access_token
(
headers
)
do
|
with_token_headers
|
@client
.
post
path
,
payload
.
to_json
,
headers:
with_token_headers
,
params:
params
,
base:
base
end
end
def
post_file
(
path
,
file
,
params:
{},
headers:
{},
base:
base_host
)
with_access_token
(
headers
)
do
|
with_token_headers
|
@client
.
post_file
path
,
file
,
headers:
with_token_headers
,
params:
params
,
base:
base
end
end
protected
def
with_access_token
(
headers
=
{},
tries
=
2
)
def
with_access_token
(
method
,
path
,
params
=
{},
headers
=
{},
tries
=
2
)
app
.
refresh_access_token
unless
app
.
access_token_valid?
yield
headers
.
merge!
(
Authorization
:
"Bearer
#{
app
.
access_token
}
"
,
'x-acs-dingtalk-access-token'
:
app
.
access_token
)
yield
params
,
headers
.
merge!
(
Authorization
:
"Bearer
#{
app
.
access_token
}
"
,
'x-acs-dingtalk-access-token'
:
app
.
access_token
)
rescue
=>
e
Rails
.
logger
.
debug
e
.
full_message
app
.
refresh_access_token
...
...
app/apis/dingtalk/api/saas.rb
View file @
80285ebe
require
'net/http'
module
Dingtalk::Api
class
Saas
<
Base
include
Inner
::
Saas
BASE
=
'https://openplatform.dg-work.cn/'
def
token
...
...
@@ -12,6 +12,22 @@ module Dingtalk::Api
}
end
def
sign_assess_header
(
method
,
path
,
params
=
{})
sign_header
(
method
,
path
,
params
=
{})
end
protected
def
with_access_token
(
method
,
path
,
params
=
{},
headers
=
{},
tries
=
2
)
app
.
refresh_access_token
unless
app
.
access_token_valid?
processed_headers
=
sign_header
(
method
,
path
,
params
=
{})
yield
params
.
merge!
(
access_token:
app
.
access_token
),
processed_headers
rescue
=>
e
Rails
.
logger
.
debug
e
.
full_message
app
.
refresh_access_token
retry
unless
(
tries
-=
1
).
zero?
end
def
sign_header
(
method
,
path
,
params
=
{})
headers
=
{
apiKey:
app
.
app_key
,
...
...
@@ -23,7 +39,7 @@ module Dingtalk::Api
}
result
=
[
method
,
method
.
upcase
,
headers
[
:'X-Hmac-Auth-Timestamp'
],
headers
[
:'X-Hmac-Auth-Nonce'
],
path
...
...
@@ -33,12 +49,5 @@ module Dingtalk::Api
headers
.
merge!
'X-Hmac-Auth-Signature'
:
Base64
.
strict_encode64
(
signature
)
end
protected
def
with_access_token
(
params
=
{},
tries
=
2
)
yield
params
rescue
=>
e
Rails
.
logger
.
debug
e
.
full_message
retry
unless
(
tries
-=
1
).
zero?
end
end
end
app/models/dingtalk/model/app/saas_app.rb
View file @
80285ebe
...
...
@@ -16,7 +16,8 @@ module Dingtalk
end
def
generate_user
(
code
)
api
.
token
r
=
api
.
getuserinfo
(
code
)
binding
.
b
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