Skip to content

Commit

Permalink
ADD: agent ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
cod7ce committed Jun 30, 2020
1 parent c1a9ec6 commit 8a6e655
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/wework/api/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ def jsapi_ticket
jsticket_store.ticket
end

def jsapi_agent_ticket
jsticket_agent_store.ticket
end

private

def jsticket_store
@jsticket_store ||= Token::JsTicket.new self
end

def jsticket_agent_store
@jsticket_agent_store ||= Token::JsAgentTicket.new self
end
end
end
end
14 changes: 14 additions & 0 deletions lib/wework/api/methods/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ def get_jssign_package url
}
end

def get_agent_jssign_package url
timestamp = Time.now.to_i
noncestr = SecureRandom.hex(8)
str = "jsapi_ticket=#{jsapi_agent_ticket}&noncestr=#{noncestr}&timestamp=#{timestamp}&url=#{url}"
{
"appId" => corp_id,
"nonceStr" => noncestr,
"timestamp" => timestamp,
"url" => url,
"signature" => Digest::SHA1.hexdigest(str),
"rawString" => str
}
end

def get_session_with_jscode(js_code, grant_type='authorization_code')
post 'miniprogram/jscode2session', {}, params: {js_code: js_code, grant_type: grant_type}
end
Expand Down
23 changes: 23 additions & 0 deletions lib/wework/token/js_agent_ticket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'wework/token/base'

module Wework
module Token
class JsAgentTicket < Base

alias_method :ticket, :token

def redis_key
@redis_key ||= Digest::MD5.hexdigest "WX_JS_AGENT_TICKET_#{client.corp_id}_#{client.agent_id}"
end

def token_key
'ticket'
end

def refresh_token
client.get 'ticket/get', params: { type: 'agent_config' }
end

end
end
end
4 changes: 1 addition & 3 deletions lib/wework/token/js_ticket.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'wework/token/base'

require 'wework/token/base'

module Wework
module Token
class JsTicket < Base
Expand All @@ -22,4 +20,4 @@ def refresh_token

end
end
end
end

0 comments on commit 8a6e655

Please sign in to comment.