Module: Pingpp::WxLiteOauth
- Defined in:
- lib/pingpp/wx_lite_oauth.rb
Class Method Summary collapse
- .create_oauth_url_for_openid(app_id, app_secret, code) ⇒ Object
- .get_openid(app_id, app_secret, code) ⇒ Object
- .get_request(url) ⇒ Object
- .get_session(app_id, app_secret, code) ⇒ Object
Class Method Details
.create_oauth_url_for_openid(app_id, app_secret, code) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pingpp/wx_lite_oauth.rb', line 17 def self.create_oauth_url_for_openid(app_id, app_secret, code) query_parts = { 'appid' => app_id, 'secret' => app_secret, 'js_code' => code, 'grant_type' => 'authorization_code' } query_str = Util.encode_parameters(query_parts) 'https://api.weixin.qq.com/sns/jscode2session?' + query_str end |
.get_openid(app_id, app_secret, code) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/pingpp/wx_lite_oauth.rb', line 3 def self.get_openid(app_id, app_secret, code) response = get_session(app_id, app_secret, code) if response['openid'].nil? then return nil, response else return response['openid'], nil end end |
.get_request(url) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pingpp/wx_lite_oauth.rb', line 28 def self.get_request(url) request_opts = { :url => url, :verify_ssl => false, :ssl_version => 'TLSv1', :method => 'GET', :headers => false, :open_timeout => 30, :timeout => 30 } response = RestClient::Request.execute(request_opts) response = JSON.parse(response.body) end |
.get_session(app_id, app_secret, code) ⇒ Object
12 13 14 15 |
# File 'lib/pingpp/wx_lite_oauth.rb', line 12 def self.get_session(app_id, app_secret, code) url = create_oauth_url_for_openid(app_id, app_secret, code) return get_request(url) end |