Commit 724ff421 by mingyuan

app key

parent 651036db
module Dingtalk module Dingtalk
class AppsController < BaseController class AppsController < BaseController
before_action :set_app, only: [:login] before_action :set_new_app, only: [:login]
before_action :set_app_by_corp, only: [:info] before_action :set_normal_app, only: [:info]
def info def info
result = @app.xx(params[:code]) result = @app.xx(params[:code])
...@@ -17,12 +17,12 @@ module Dingtalk ...@@ -17,12 +17,12 @@ module Dingtalk
end end
private private
def set_app def set_new_app
@app = App.find params[:id] @app = NewlApp.find_by(app_key: params[:app_key])
end end
def set_app_by_corp def set_normal_app
@app = NormalApp.find_by corp_id: params[:corp_id] @app = NormalApp.find_by(app_key: params[:app_key])
end end
end end
......
...@@ -15,7 +15,7 @@ module Dingtalk ...@@ -15,7 +15,7 @@ module Dingtalk
attribute :oauth2_state, :string attribute :oauth2_state, :string
attribute :jsapi_ticket_expires_at, :datetime attribute :jsapi_ticket_expires_at, :datetime
has_many :dingtalk_users, foreign_key: :appid, primary_key: :corp_id has_many :dingtalk_users, foreign_key: :appid, primary_key: :app_key
end end
def api def api
......
...@@ -9,7 +9,7 @@ module Dingtalk ...@@ -9,7 +9,7 @@ module Dingtalk
def oauth2_url(scope = 'openid corpid', state: SecureRandom.hex(16), **host_options) def oauth2_url(scope = 'openid corpid', state: SecureRandom.hex(16), **host_options)
h = { h = {
client_id: app_key, client_id: app_key,
redirect_uri: Rails.application.routes.url_for(controller: 'dingtalk/apps', action: 'login', id: id, **host_options), redirect_uri: Rails.application.routes.url_for(controller: 'dingtalk/apps', action: 'login', app_key: app_key, **host_options),
response_type: 'code', response_type: 'code',
scope: scope, scope: scope,
state: state, state: state,
......
json.dingtalk_user @dingtalk_user.as_json
...@@ -17,7 +17,7 @@ dd.ready(() => { ...@@ -17,7 +17,7 @@ dd.ready(() => {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
corp_id: 'ding9f5ed2cec249700e35c2f4657eb6378f', app_id: 'xxxx',
code: info.code code: info.code
}) })
}).then(response => { }).then(response => {
......
...@@ -11,8 +11,6 @@ Rails.application.routes.draw do ...@@ -11,8 +11,6 @@ Rails.application.routes.draw do
resources :apps do resources :apps do
collection do collection do
post :info post :info
end
member do
get :login get :login
end end
end end
......
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