Class: Wechat::Api
- Inherits:
-
Object
- Object
- Wechat::Api
- Defined in:
- lib/wechat/api.rb
Constant Summary collapse
- API_BASE =
"https://api.weixin.qq.com/cgi-bin/"
- FILE_BASE =
"http://file.api.weixin.qq.com/cgi-bin/"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #custom_message_send(message) ⇒ Object
-
#initialize(appid, secret, token_file) ⇒ Api
constructor
A new instance of Api.
- #media(media_id) ⇒ Object
- #media_create(type, file) ⇒ Object
- #menu ⇒ Object
- #menu_create(menu) ⇒ Object
- #menu_delete ⇒ Object
- #template_message_send(message) ⇒ Object
- #user(openid) ⇒ Object
- #users(nextid = nil) ⇒ Object
Constructor Details
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/wechat/api.rb', line 5 def access_token @access_token end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/wechat/api.rb', line 5 def client @client end |
Instance Method Details
#custom_message_send(message) ⇒ Object
45 46 47 |
# File 'lib/wechat/api.rb', line 45 def post "message/custom/send", .to_json, content_type: :json end |
#media(media_id) ⇒ Object
37 38 39 |
# File 'lib/wechat/api.rb', line 37 def media media_id response = get "media/get", params:{media_id: media_id}, base: FILE_BASE, as: :file end |
#media_create(type, file) ⇒ Object
41 42 43 |
# File 'lib/wechat/api.rb', line 41 def media_create type, file post "media/upload", {upload:{media: file}}, params:{type: type}, base: FILE_BASE end |
#menu ⇒ Object
24 25 26 |
# File 'lib/wechat/api.rb', line 24 def get("menu/get") end |
#menu_create(menu) ⇒ Object
32 33 34 35 |
# File 'lib/wechat/api.rb', line 32 def # 微信不接受7bit escaped json(eg \uxxxx), 中文必须UTF-8编码, 这可能是个安全漏洞 post("menu/create", JSON.generate()) end |
#menu_delete ⇒ Object
28 29 30 |
# File 'lib/wechat/api.rb', line 28 def get("menu/delete") end |
#template_message_send(message) ⇒ Object
49 50 51 |
# File 'lib/wechat/api.rb', line 49 def post "message/template/send", .to_json, content_type: :json end |
#user(openid) ⇒ Object
20 21 22 |
# File 'lib/wechat/api.rb', line 20 def user openid get("user/info", params:{openid: openid}) end |
#users(nextid = nil) ⇒ Object
15 16 17 18 |
# File 'lib/wechat/api.rb', line 15 def users nextid = nil params = {params: {next_openid: nextid}} if nextid.present? get('user/get', params||{}) end |