Class: Wechat::Core::AccessToken
- Inherits:
-
Object
- Object
- Wechat::Core::AccessToken
- Extended by:
- Common
- Defined in:
- lib/wechat/core/access_token.rb
Overview
Access Token 是访问令牌的远程调用封装类。
Constant Summary
Constants included from Common
Common::ERROR_CODES, Common::LANGUAGE_ENGLISH, Common::LANGUAGE_SIMPLIFIED_CHINESE, Common::LANGUAGE_TRANDITIONAL_CHINESE
Class Method Summary collapse
-
.create(app_id, app_secret) ⇒ Object
获取 Access Token mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html.
-
.load(app_id, app_secret) ⇒ Object
获取 Access Token mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html.
Methods included from Common
assert_present!, get_json, post_json
Class Method Details
.create(app_id, app_secret) ⇒ Object
获取 Access Token mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
Return hash format if success:
access_token: <ACCESS_TOKEN>,
expires_in: 7200
The ACCESS_TOKEN is 107 characters in 2015.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wechat/core/access_token.rb', line 40 def self.create(app_id, app_secret) assert_present! :app_id, app_id assert_present! :app_secret, app_secret get_json 'https://api.weixin.qq.com/cgi-bin/token', body: { grant_type: 'client_credential', appid: app_id, # Rails.application.secrets.wechat_app_id, secret: app_secret, # Rails.application.secrets.wechat_app_secret } end |
.load(app_id, app_secret) ⇒ Object
获取 Access Token mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
Return hash format if success:
access_token: <ACCESS_TOKEN>,
expires_in: 7200
The ACCESS_TOKEN is 107 characters in 2015.
20 21 22 23 24 25 26 27 28 |
# File 'lib/wechat/core/access_token.rb', line 20 def self.load(app_id, app_secret) = ::JSONClient.new.get 'https://api.weixin.qq.com/cgi-bin/token', { grant_type: 'client_credential', appid: app_id, # Rails.application.secrets.wechat_app_id, secret: app_secret, # Rails.application.secrets.wechat_app_secret } .body end |