Commit 5378b5ba by mingyuan

use base url for db

parent 1db89fa8
......@@ -30,7 +30,7 @@ GIT
GIT
remote: https://github.com/work-design/rails_extend.git
revision: 40067af089497d0abe0ebf2fba77e813902bc868
revision: ef2aa3492d3d214a8d60cb6322c39d2e568adb74
specs:
rails_extend (1.0.0)
rails (>= 6.0)
......@@ -181,8 +181,6 @@ GEM
minitest (> 5.3)
multipart-post (2.1.1)
nio4r (2.5.8)
nokogiri (1.12.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.12.4-x86_64-linux)
racc (~> 1.4)
pg (1.2.3)
......
......@@ -9,30 +9,26 @@ module Dingtalk::Api
end
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
def jsapi_ticket
get 'get_jsapi_ticket', base: BASE
get 'get_jsapi_ticket', base: app.base_url
end
def base_host
BASE
end
def get(path, params: {}, headers: {}, base: base_host, as: nil)
def get(path, params: {}, headers: {}, base: app.base_url, as: nil)
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
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|
@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)
def post_file(path, file, params: {}, headers: {}, base: app.base_url)
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
end
......
module Dingtalk::Api
module Inner::New
BASE = 'https://api.dingtalk.com/'
def getuserinfo(union_id)
get "v1.0/contact/users/#{union_id}"
get "/v1.0/contact/users/#{union_id}"
end
end
......
module Dingtalk::Api
module Inner::Saas
#BASE = 'https://openplatform.dg-work.cn'
BASE = 'https://openplatform-pro.ding.zj.gov.cn'
def getuserinfo(code)
......
......@@ -3,7 +3,7 @@ module Dingtalk::Api
BASE = 'https://oapi.dingtalk.com/'
def getuserinfo(code)
r = post 'topapi/v2/user/getuserinfo', code: code
r = post '/topapi/v2/user/getuserinfo', code: code
if r.is_a? Hash
r['result']
else
......
module Dingtalk::Api
class New < Base
BASE = 'https://api.dingtalk.com/'
include Inner::New
def token
......@@ -8,17 +7,13 @@ module Dingtalk::Api
appKey: app.app_key,
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'],
'expires_in' => r['expireIn']
}
end
def base_host
BASE
end
protected
def with_access_token(method, path, params = {}, headers = {}, payload = {}, tries = 2)
app.refresh_access_token unless app.access_token_valid?
......
module Dingtalk::Api
class Saas < Base
include Inner::Saas
#BASE = 'https://openplatform.dg-work.cn'
BASE = 'https://openplatform-pro.ding.zj.gov.cn'
def token
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'),
'expires_in' => r.dig('content', 'data', 'expiresIn')
}
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|
@client.post path, payload.to_query, headers: processed_headers, params: processed_params, base: base
end
......
......@@ -15,6 +15,7 @@ module Dingtalk
attribute :oauth2_state, :string
attribute :jsapi_ticket_expires_at, :datetime
attribute :tenant_id, :string, comment: '专有钉钉,租户ID'
attribute :base_url, :string, comment: '对应的 Base Host'
has_many :dingtalk_users, foreign_key: :appid, primary_key: :app_key
end
......
module Dingtalk
module Model::App::NewApp
extend ActiveSupport::Extend
included do
attribute :base_url, :string, default: 'https://api.dingtalk.com'
end
def api
return @api if defined? @api
......
......@@ -3,6 +3,8 @@ module Dingtalk
extend ActiveSupport::Concern
included do
attribute :base_url, :string, default: 'https://oapi.dingtalk.com'
has_one :new_app, foreign_key: :app_key, primary_key: :app_key
end
......
......@@ -3,6 +3,7 @@ module Dingtalk
extend ActiveSupport::Concern
included do
attribute :base_url, :string, default: 'https://openplatform.dg-work.cn'
end
def api
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment