Commit 5ea2dd5b by mingyuan

dingtalk

parent b7b09c64
......@@ -22,7 +22,6 @@ module Dingtalk::Api
def with_access_token(method, path, params = {}, headers = {}, payload = {}, tries = 2)
app.refresh_access_token unless app.access_token_valid?
payload.merge!(access_token: app.access_token)
#params.merge!(access_token: app.access_token)
processed_headers = sign_header(method, path, params, payload)
yield params, processed_headers
rescue => e
......@@ -34,8 +33,8 @@ module Dingtalk::Api
def sign_header(method, path, params = {}, payload = {})
headers = {
apiKey: app.app_key,
'X-Hmac-Auth-Timestamp': Time.now.strftime('%Y-%m-%dT%H:%M:%S.%6N%:z'),
'X-Hmac-Auth-Nonce': '16314248251027993', #(Time.now.to_f * 1000).round.to_s + rand(1000..9999).to_s,
'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
......
......@@ -10,14 +10,14 @@ module Dingtalk
@api = Api::Saas.new(self)
end
def xx(code)
result = api.getuserinfo(code)
new_app.api.getuserinfo(result['unionid'])
end
def generate_user(code)
r = api.getuserinfo(code)
binding.b
info = api.getuserinfo(code)
return unless info.is_a?(Hash)
dingtalk_user = dingtalk_users.find_or_initialize_by(uid: info['openid'])
dingtalk_user.name = info['nickNameCn']
dingtalk_user.identity = info['account']
dingtalk_user.extra = info.slice('clientId', 'lastName', 'realmId', 'realmName', 'tenantUserId', 'employeeCode', 'accountId', 'tenantId', 'tenantName', 'referId', 'namespace')
dingtalk_user
end
end
......
......@@ -15,7 +15,8 @@ module Dingtalk
attribute :extra, :json, default: {}
attribute :identity, :string, index: true
belongs_to :new_app, foreign_key: :appid, primary_key: :app_key
belongs_to :new_app, foreign_key: :appid, primary_key: :app_key, optional: true
belongs_to :saas_app, foreign_key: :appid, primary_key: :app_key, optional: true
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