Module: Wework::Api::Methods::Agent

Included in:
Agent
Defined in:
lib/wework/api/methods/agent.rb

Instance Method Summary collapse

Instance Method Details

#authorize_url(redirect_uri, scope = "snsapi_base", state = "wxwork") ⇒ Object



7
8
9
10
11
# File 'lib/wework/api/methods/agent.rb', line 7

def authorize_url(redirect_uri, scope="snsapi_base", state="wxwork")
  # user agent: UA is mozilla/5.0 (iphone; cpu iphone os 10_2 like mac os x) applewebkit/602.3.12 (khtml, like gecko) mobile/14c92 wxwork/1.3.2 micromessenger/6.2
  uri = ERB::Util.url_encode(redirect_uri)
  "#{AUTHORIZE_ENDPOINT}?appid=#{corp_id}&redirect_uri=#{uri}&response_type=code&scope=#{scope}&agentid=#{agent_id}&state=#{state}#wechat_redirect"
end

#get_agentObject



39
40
41
# File 'lib/wework/api/methods/agent.rb', line 39

def get_agent
  get 'agent/get', params: {agentid: agent_id}
end

#get_jssign_package(url) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wework/api/methods/agent.rb', line 21

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

#get_oauth_userinfo(code) ⇒ Object



13
14
15
# File 'lib/wework/api/methods/agent.rb', line 13

def get_oauth_userinfo code
  get 'user/getuserinfo', params: {code: code}
end

#get_session_with_jscode(js_code, grant_type = 'authorization_code') ⇒ Object



35
36
37
# File 'lib/wework/api/methods/agent.rb', line 35

def get_session_with_jscode(js_code, grant_type='authorization_code')
  post 'miniprogram/jscode2session', {}, params: {js_code: js_code, grant_type: grant_type}
end

#get_user_detail(user_ticket) ⇒ Object



17
18
19
# File 'lib/wework/api/methods/agent.rb', line 17

def get_user_detail user_ticket
  post 'user/getuserdetail', {user_ticket: user_ticket}
end

#set_agent(data = {}) ⇒ Object



43
44
45
# File 'lib/wework/api/methods/agent.rb', line 43

def set_agent data={}
  post 'agent/set', data.merge(agentid: agent_id)
end