Commit 0ebdd496 by mingyuan

dingtalk

parent b24bb8a7
...@@ -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: 48e8b20f65097c981b8ecc3b9b35d2082512d9e8 revision: 9f79c3ba99e3d590841736b4a7855f54035a43cc
specs: specs:
rails_extend (1.0.0) rails_extend (1.0.0)
rails (>= 6.0) rails (>= 6.0)
......
...@@ -7,13 +7,26 @@ module Dingtalk::Api ...@@ -7,13 +7,26 @@ module Dingtalk::Api
appkey: app.app_key, appkey: app.app_key,
appsecret: app.app_secret, appsecret: app.app_secret,
} }
r = @client.post 'gettoken.json', payload.to_json, base: BASE r = @client.post 'gettoken.json', payload.to_json, headers: { }, base: BASE
{ {
'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 sign_header
headers = {
apiKey: app.app_key,
'X-Hmac-Auth-Timestamp': Time.now.to_s(:iso8601),
'X-Hmac-Auth-Nonce': (Time.now.to_f * 1000).round.to_s + rand(1000..9999).to_s,
'X-Hmac-Auth-Version': '1.0',
'X-Hmac-Auth-IP': RailsDingtalk.config.ip,
'X-Hmac-Auth-MAC': RailsDingtalk.config.mac
}
end
protected protected
def with_access_token(params = {}, tries = 2) def with_access_token(params = {}, tries = 2)
yield params.merge!( yield params.merge!(
......
module Dingtalk module Dingtalk
class AppsController < BaseController class AppsController < BaseController
before_action :set_new_app, only: [:login] before_action :set_app, only: [:login]
before_action :set_normal_app, only: [:info] before_action :set_normal_app, only: [:info]
def info def info
...@@ -17,8 +17,8 @@ module Dingtalk ...@@ -17,8 +17,8 @@ module Dingtalk
end end
private private
def set_new_app def set_app
@app = NewApp.find_by(app_key: params[:app_key]) @app = App.where(type: ['Dingtalk::NewApp', 'Dingtalk::SaasApp']).find_by(app_key: params[:app_key])
end end
def set_normal_app def set_normal_app
......
...@@ -15,5 +15,9 @@ module Dingtalk ...@@ -15,5 +15,9 @@ module Dingtalk
new_app.api.getuserinfo(result['unionid']) new_app.api.getuserinfo(result['unionid'])
end end
def generate_user(code)
binding.b
end
end end
end end
...@@ -5,4 +5,4 @@ zh: ...@@ -5,4 +5,4 @@ zh:
type: type:
Dingtalk::NormalApp: 普通App Dingtalk::NormalApp: 普通App
Dingtalk::NewApp: NewApp Dingtalk::NewApp: NewApp
Dingtalk::SaasApp: 政务钉
...@@ -7,6 +7,8 @@ module RailsDingtalk ...@@ -7,6 +7,8 @@ module RailsDingtalk
verify_mode: OpenSSL::SSL::VERIFY_NONE verify_mode: OpenSSL::SSL::VERIFY_NONE
} }
} }
config.ip = '192.168.0.1'
config.mac = 'fa:16:3e:27:49:91'
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