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
13590ba2
Commit
13590ba2
authored
Aug 20, 2021
by
mingyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get js api
parent
a3f50b73
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
base.rb
app/apis/dingtalk/api/base.rb
+4
-0
app.rb
app/models/dingtalk/model/app.rb
+28
-0
No files found.
app/apis/dingtalk/api/base.rb
View file @
13590ba2
...
@@ -12,6 +12,10 @@ module Dingtalk::Api
...
@@ -12,6 +12,10 @@ module Dingtalk::Api
@client
.
get
'gettoken'
,
params:
{
appkey:
app
.
app_key
,
appsecret:
app
.
app_secret
},
base:
BASE
@client
.
get
'gettoken'
,
params:
{
appkey:
app
.
app_key
,
appsecret:
app
.
app_secret
},
base:
BASE
end
end
def
jsapi_ticket
get
'get_jsapi_ticket'
,
base:
BASE
end
def
get
(
path
,
params:
{},
headers:
{},
base:
nil
,
as:
nil
)
def
get
(
path
,
params:
{},
headers:
{},
base:
nil
,
as:
nil
)
with_access_token
(
params
)
do
|
with_token_params
|
with_access_token
(
params
)
do
|
with_token_params
|
@client
.
get
path
,
headers:
headers
,
params:
with_token_params
,
base:
base
,
as:
as
@client
.
get
path
,
headers:
headers
,
params:
with_token_params
,
base:
base
,
as:
as
...
...
app/models/dingtalk/model/app.rb
View file @
13590ba2
...
@@ -10,6 +10,9 @@ module Dingtalk
...
@@ -10,6 +10,9 @@ module Dingtalk
attribute
:corp_id
,
:string
attribute
:corp_id
,
:string
attribute
:access_token
,
:string
attribute
:access_token
,
:string
attribute
:access_token_expires_at
,
:datetime
attribute
:access_token_expires_at
,
:datetime
attribute
:jsapi_ticket
,
:string
attribute
:oauth2_state
,
:string
attribute
:jsapi_ticket_expires_at
,
:datetime
end
end
def
api
def
api
...
@@ -37,5 +40,30 @@ module Dingtalk
...
@@ -37,5 +40,30 @@ module Dingtalk
access_token_expires_at
>
Time
.
current
access_token_expires_at
>
Time
.
current
end
end
def
jsapi_ticket
if
jsapi_ticket_valid?
super
else
refresh_jsapi_ticket
end
end
def
jsapi_ticket_valid?
return
false
unless
jsapi_ticket_expires_at
.
acts_like?
(
:time
)
jsapi_ticket_expires_at
>
Time
.
current
end
def
refresh_jsapi_ticket
r
=
api
.
jsapi_ticket
store_jsapi_ticket
(
r
)
jsapi_ticket
end
def
store_jsapi_ticket
(
ticket_hash
)
self
.
jsapi_ticket
=
ticket_hash
[
'ticket'
]
self
.
jsapi_ticket_expires_at
=
Time
.
current
+
ticket_hash
[
'expires_in'
].
to_i
self
.
save
end
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