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
5378b5ba
Commit
5378b5ba
authored
Sep 16, 2021
by
mingyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use base url for db
parent
1db89fa8
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
20 additions
and
26 deletions
+20
-26
Gemfile.lock
Gemfile.lock
+1
-3
base.rb
app/apis/dingtalk/api/base.rb
+5
-9
new.rb
app/apis/dingtalk/api/inner/new.rb
+1
-2
saas.rb
app/apis/dingtalk/api/inner/saas.rb
+0
-1
user.rb
app/apis/dingtalk/api/inner/user.rb
+1
-1
new.rb
app/apis/dingtalk/api/new.rb
+1
-6
saas.rb
app/apis/dingtalk/api/saas.rb
+2
-4
app.rb
app/models/dingtalk/model/app.rb
+1
-0
new_app.rb
app/models/dingtalk/model/app/new_app.rb
+5
-0
normal_app.rb
app/models/dingtalk/model/app/normal_app.rb
+2
-0
saas_app.rb
app/models/dingtalk/model/app/saas_app.rb
+1
-0
No files found.
Gemfile.lock
View file @
5378b5ba
...
@@ -30,7 +30,7 @@ GIT
...
@@ -30,7 +30,7 @@ GIT
GIT
GIT
remote: https://github.com/work-design/rails_extend.git
remote: https://github.com/work-design/rails_extend.git
revision:
40067af089497d0abe0ebf2fba77e813902bc868
revision:
ef2aa3492d3d214a8d60cb6322c39d2e568adb74
specs:
specs:
rails_extend (1.0.0)
rails_extend (1.0.0)
rails (>= 6.0)
rails (>= 6.0)
...
@@ -181,8 +181,6 @@ GEM
...
@@ -181,8 +181,6 @@ GEM
minitest (> 5.3)
minitest (> 5.3)
multipart-post (2.1.1)
multipart-post (2.1.1)
nio4r (2.5.8)
nio4r (2.5.8)
nokogiri (1.12.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.12.4-x86_64-linux)
nokogiri (1.12.4-x86_64-linux)
racc (~> 1.4)
racc (~> 1.4)
pg (1.2.3)
pg (1.2.3)
...
...
app/apis/dingtalk/api/base.rb
View file @
5378b5ba
...
@@ -9,30 +9,26 @@ module Dingtalk::Api
...
@@ -9,30 +9,26 @@ module Dingtalk::Api
end
end
def
token
def
token
@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:
app
.
base_url
end
end
def
jsapi_ticket
def
jsapi_ticket
get
'get_jsapi_ticket'
,
base:
BASE
get
'get_jsapi_ticket'
,
base:
app
.
base_url
end
end
def
base_host
def
get
(
path
,
params:
{},
headers:
{},
base:
app
.
base_url
,
as:
nil
)
BASE
end
def
get
(
path
,
params:
{},
headers:
{},
base:
base_host
,
as:
nil
)
with_access_token
(
'get'
,
path
,
params
,
headers
,
nil
)
do
|
processed_params
,
processed_headers
|
with_access_token
(
'get'
,
path
,
params
,
headers
,
nil
)
do
|
processed_params
,
processed_headers
|
@client
.
get
path
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
,
as:
as
@client
.
get
path
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
,
as:
as
end
end
end
end
def
post
(
path
,
params:
{},
headers:
{},
base:
base_host
,
**
payload
)
def
post
(
path
,
params:
{},
headers:
{},
base:
app
.
base_url
,
**
payload
)
with_access_token
(
'post'
,
path
,
params
,
headers
,
payload
)
do
|
processed_params
,
processed_headers
|
with_access_token
(
'post'
,
path
,
params
,
headers
,
payload
)
do
|
processed_params
,
processed_headers
|
@client
.
post
path
,
payload
.
to_json
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
@client
.
post
path
,
payload
.
to_json
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
end
end
end
end
def
post_file
(
path
,
file
,
params:
{},
headers:
{},
base:
base_host
)
def
post_file
(
path
,
file
,
params:
{},
headers:
{},
base:
app
.
base_url
)
with_access_token
(
'post'
,
path
,
params
,
headers
,
nil
)
do
|
processed_params
,
processed_headers
|
with_access_token
(
'post'
,
path
,
params
,
headers
,
nil
)
do
|
processed_params
,
processed_headers
|
@client
.
post_file
path
,
file
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
@client
.
post_file
path
,
file
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
end
end
...
...
app/apis/dingtalk/api/inner/new.rb
View file @
5378b5ba
module
Dingtalk::Api
module
Dingtalk::Api
module
Inner::New
module
Inner::New
BASE
=
'https://api.dingtalk.com/'
def
getuserinfo
(
union_id
)
def
getuserinfo
(
union_id
)
get
"v1.0/contact/users/
#{
union_id
}
"
get
"
/
v1.0/contact/users/
#{
union_id
}
"
end
end
end
end
...
...
app/apis/dingtalk/api/inner/saas.rb
View file @
5378b5ba
module
Dingtalk::Api
module
Dingtalk::Api
module
Inner::Saas
module
Inner::Saas
#BASE = 'https://openplatform.dg-work.cn'
BASE
=
'https://openplatform-pro.ding.zj.gov.cn'
BASE
=
'https://openplatform-pro.ding.zj.gov.cn'
def
getuserinfo
(
code
)
def
getuserinfo
(
code
)
...
...
app/apis/dingtalk/api/inner/user.rb
View file @
5378b5ba
...
@@ -3,7 +3,7 @@ module Dingtalk::Api
...
@@ -3,7 +3,7 @@ module Dingtalk::Api
BASE
=
'https://oapi.dingtalk.com/'
BASE
=
'https://oapi.dingtalk.com/'
def
getuserinfo
(
code
)
def
getuserinfo
(
code
)
r
=
post
'topapi/v2/user/getuserinfo'
,
code:
code
r
=
post
'
/
topapi/v2/user/getuserinfo'
,
code:
code
if
r
.
is_a?
Hash
if
r
.
is_a?
Hash
r
[
'result'
]
r
[
'result'
]
else
else
...
...
app/apis/dingtalk/api/new.rb
View file @
5378b5ba
module
Dingtalk::Api
module
Dingtalk::Api
class
New
<
Base
class
New
<
Base
BASE
=
'https://api.dingtalk.com/'
include
Inner
::
New
include
Inner
::
New
def
token
def
token
...
@@ -8,17 +7,13 @@ module Dingtalk::Api
...
@@ -8,17 +7,13 @@ module Dingtalk::Api
appKey:
app
.
app_key
,
appKey:
app
.
app_key
,
appSecret:
app
.
app_secret
,
appSecret:
app
.
app_secret
,
}
}
r
=
@client
.
post
'v1.0/oauth2/accessToken'
,
payload
.
to_json
,
base:
BASE
r
=
@client
.
post
'v1.0/oauth2/accessToken'
,
payload
.
to_json
,
base:
app
.
base_url
{
{
'access_token'
=>
r
[
'accessToken'
],
'access_token'
=>
r
[
'accessToken'
],
'expires_in'
=>
r
[
'expireIn'
]
'expires_in'
=>
r
[
'expireIn'
]
}
}
end
end
def
base_host
BASE
end
protected
protected
def
with_access_token
(
method
,
path
,
params
=
{},
headers
=
{},
payload
=
{},
tries
=
2
)
def
with_access_token
(
method
,
path
,
params
=
{},
headers
=
{},
payload
=
{},
tries
=
2
)
app
.
refresh_access_token
unless
app
.
access_token_valid?
app
.
refresh_access_token
unless
app
.
access_token_valid?
...
...
app/apis/dingtalk/api/saas.rb
View file @
5378b5ba
module
Dingtalk::Api
module
Dingtalk::Api
class
Saas
<
Base
class
Saas
<
Base
include
Inner
::
Saas
include
Inner
::
Saas
#BASE = 'https://openplatform.dg-work.cn'
BASE
=
'https://openplatform-pro.ding.zj.gov.cn'
def
token
def
token
headers
=
sign_header
(
'POST'
,
'/gettoken.json'
)
headers
=
sign_header
(
'POST'
,
'/gettoken.json'
)
r
=
@client
.
post
'/gettoken.json'
,
headers:
headers
,
base:
BASE
r
=
@client
.
post
'/gettoken.json'
,
headers:
headers
,
base:
app
.
base_url
{
{
'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
post
(
path
,
params:
{},
headers:
{},
base:
base_host
,
**
payload
)
def
post
(
path
,
params:
{},
headers:
{},
base:
app
.
base_url
,
**
payload
)
with_access_token
(
'post'
,
path
,
params
,
headers
,
payload
)
do
|
processed_params
,
processed_headers
|
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
@client
.
post
path
,
payload
.
to_query
,
headers:
processed_headers
,
params:
processed_params
,
base:
base
end
end
...
...
app/models/dingtalk/model/app.rb
View file @
5378b5ba
...
@@ -15,6 +15,7 @@ module Dingtalk
...
@@ -15,6 +15,7 @@ module Dingtalk
attribute
:oauth2_state
,
:string
attribute
:oauth2_state
,
:string
attribute
:jsapi_ticket_expires_at
,
:datetime
attribute
:jsapi_ticket_expires_at
,
:datetime
attribute
:tenant_id
,
:string
,
comment:
'专有钉钉,租户ID'
attribute
:tenant_id
,
:string
,
comment:
'专有钉钉,租户ID'
attribute
:base_url
,
:string
,
comment:
'对应的 Base Host'
has_many
:dingtalk_users
,
foreign_key: :appid
,
primary_key: :app_key
has_many
:dingtalk_users
,
foreign_key: :appid
,
primary_key: :app_key
end
end
...
...
app/models/dingtalk/model/app/new_app.rb
View file @
5378b5ba
module
Dingtalk
module
Dingtalk
module
Model::App::NewApp
module
Model::App::NewApp
extend
ActiveSupport
::
Extend
included
do
attribute
:base_url
,
:string
,
default:
'https://api.dingtalk.com'
end
def
api
def
api
return
@api
if
defined?
@api
return
@api
if
defined?
@api
...
...
app/models/dingtalk/model/app/normal_app.rb
View file @
5378b5ba
...
@@ -3,6 +3,8 @@ module Dingtalk
...
@@ -3,6 +3,8 @@ module Dingtalk
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
attribute
:base_url
,
:string
,
default:
'https://oapi.dingtalk.com'
has_one
:new_app
,
foreign_key: :app_key
,
primary_key: :app_key
has_one
:new_app
,
foreign_key: :app_key
,
primary_key: :app_key
end
end
...
...
app/models/dingtalk/model/app/saas_app.rb
View file @
5378b5ba
...
@@ -3,6 +3,7 @@ module Dingtalk
...
@@ -3,6 +3,7 @@ module Dingtalk
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
attribute
:base_url
,
:string
,
default:
'https://openplatform.dg-work.cn'
end
end
def
api
def
api
...
...
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