Module: Wechat::Concern::Common
Constant Summary collapse
- WXA_BASE =
'https://api.weixin.qq.com/wxa/'.freeze
- API_BASE =
'https://api.weixin.qq.com/cgi-bin/'.freeze
- OAUTH2_BASE =
'https://api.weixin.qq.com/sns/'.freeze
Instance Method Summary collapse
- #custom_message_send(message) ⇒ Object
- #customservice_getonlinekflist ⇒ Object
- #group_create(group_name) ⇒ Object
- #group_delete(groupid) ⇒ Object
- #group_update(groupid, new_group_name) ⇒ Object
- #groups ⇒ Object
- #initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file) ⇒ Object
- #material(media_id) ⇒ Object
- #material_add(type, file) ⇒ Object
- #material_count ⇒ Object
- #material_delete(media_id) ⇒ Object
- #material_list(type, offset, count) ⇒ Object
- #menu ⇒ Object
- #menu_addconditional(menu) ⇒ Object
- #menu_create(menu) ⇒ Object
- #menu_delconditional(menuid) ⇒ Object
- #menu_delete ⇒ Object
- #menu_trymatch(user_id) ⇒ Object
- #message_mass_delete(msg_id) ⇒ Object
- #message_mass_get(msg_id) ⇒ Object
- #message_mass_preview(message) ⇒ Object
- #message_mass_sendall(message) ⇒ Object
- #qrcode_create_limit_scene(scene_id_or_str) ⇒ Object
- #qrcode_create_scene(scene_id_or_str, expire_seconds = 604800) ⇒ Object
- #shorturl(long_url) ⇒ Object
- #tag(tagid, next_openid = '') ⇒ Object
- #tag_add_user(tagid, openids) ⇒ Object
- #tag_create(tag_name) ⇒ Object
- #tag_del_user(tagid, openids) ⇒ Object
- #tag_delete(tagid) ⇒ Object
- #tag_update(tagid, new_tag_name) ⇒ Object
- #tags ⇒ Object
- #user(openid) ⇒ Object
- #user_batchget(openids, lang = 'zh-CN') ⇒ Object
- #user_change_group(openid, to_groupid) ⇒ Object
- #user_group(openid) ⇒ Object
- #user_update_remark(openid, remark) ⇒ Object
- #users(nextid = nil) ⇒ Object
- #web_access_token(code) ⇒ Object
- #web_auth_access_token(web_access_token, openid) ⇒ Object
- #web_refresh_access_token(user_refresh_token) ⇒ Object
- #web_userinfo(web_access_token, openid, lang = 'zh_CN') ⇒ Object
- #wxa_create_qrcode(path, width = 430) ⇒ Object
- #wxa_get_wxacode(path, width = 430) ⇒ Object
Instance Method Details
#custom_message_send(message) ⇒ Object
153 154 155 |
# File 'lib/wechat/concern/common.rb', line 153 def () post 'message/custom/send', .is_a?(Wechat::Message) ? .to_json : JSON.generate(), content_type: :json end |
#customservice_getonlinekflist ⇒ Object
157 158 159 |
# File 'lib/wechat/concern/common.rb', line 157 def customservice_getonlinekflist get 'customservice/getonlinekflist' end |
#group_create(group_name) ⇒ Object
18 19 20 |
# File 'lib/wechat/concern/common.rb', line 18 def group_create(group_name) post 'groups/create', JSON.generate(group: { name: group_name }) end |
#group_delete(groupid) ⇒ Object
26 27 28 |
# File 'lib/wechat/concern/common.rb', line 26 def group_delete(groupid) post 'groups/delete', JSON.generate(group: { id: groupid }) end |
#group_update(groupid, new_group_name) ⇒ Object
22 23 24 |
# File 'lib/wechat/concern/common.rb', line 22 def group_update(groupid, new_group_name) post 'groups/update', JSON.generate(group: { id: groupid, name: new_group_name }) end |
#groups ⇒ Object
14 15 16 |
# File 'lib/wechat/concern/common.rb', line 14 def groups get 'groups/get' end |
#initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file) ⇒ Object
8 9 10 11 12 |
# File 'lib/wechat/concern/common.rb', line 8 def initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file) @client = HttpClient.new(API_BASE, timeout, skip_verify_ssl) @access_token = Token::PublicAccessToken.new(@client, appid, secret, token_file) @jsapi_ticket = Ticket::PublicJsapiTicket.new(@client, @access_token, jsapi_ticket_file) end |
#material(media_id) ⇒ Object
133 134 135 |
# File 'lib/wechat/concern/common.rb', line 133 def material(media_id) get 'material/get', params: { media_id: media_id }, as: :file end |
#material_add(type, file) ⇒ Object
145 146 147 |
# File 'lib/wechat/concern/common.rb', line 145 def material_add(type, file) post_file 'material/add_material', file, params: { type: type } end |
#material_count ⇒ Object
137 138 139 |
# File 'lib/wechat/concern/common.rb', line 137 def material_count get 'material/get_materialcount' end |
#material_delete(media_id) ⇒ Object
149 150 151 |
# File 'lib/wechat/concern/common.rb', line 149 def material_delete(media_id) post 'material/del_material', JSON.generate(media_id: media_id) end |
#material_list(type, offset, count) ⇒ Object
141 142 143 |
# File 'lib/wechat/concern/common.rb', line 141 def material_list(type, offset, count) post 'material/batchget_material', JSON.generate(type: type, offset: offset, count: count) end |
#menu ⇒ Object
107 108 109 |
# File 'lib/wechat/concern/common.rb', line 107 def get 'menu/get' end |
#menu_addconditional(menu) ⇒ Object
120 121 122 123 |
# File 'lib/wechat/concern/common.rb', line 120 def () # Wechat not accept 7bit escaped json(eg \uxxxx), must using UTF-8, possible security vulnerability? post 'menu/addconditional', JSON.generate() end |
#menu_create(menu) ⇒ Object
115 116 117 118 |
# File 'lib/wechat/concern/common.rb', line 115 def () # 微信不接受7bit escaped json(eg \uxxxx), 中文必须UTF-8编码, 这可能是个安全漏洞 post 'menu/create', JSON.generate() end |
#menu_delconditional(menuid) ⇒ Object
129 130 131 |
# File 'lib/wechat/concern/common.rb', line 129 def () post 'menu/delconditional', JSON.generate(menuid: ) end |
#menu_delete ⇒ Object
111 112 113 |
# File 'lib/wechat/concern/common.rb', line 111 def get 'menu/delete' end |
#menu_trymatch(user_id) ⇒ Object
125 126 127 |
# File 'lib/wechat/concern/common.rb', line 125 def (user_id) post 'menu/trymatch', JSON.generate(user_id: user_id) end |
#message_mass_delete(msg_id) ⇒ Object
87 88 89 |
# File 'lib/wechat/concern/common.rb', line 87 def (msg_id) post 'message/mass/delete', JSON.generate(msg_id: msg_id) end |
#message_mass_get(msg_id) ⇒ Object
95 96 97 |
# File 'lib/wechat/concern/common.rb', line 95 def (msg_id) post 'message/mass/get', JSON.generate(msg_id: msg_id) end |
#message_mass_preview(message) ⇒ Object
91 92 93 |
# File 'lib/wechat/concern/common.rb', line 91 def () post 'message/mass/preview', .to_json end |
#message_mass_sendall(message) ⇒ Object
83 84 85 |
# File 'lib/wechat/concern/common.rb', line 83 def () post 'message/mass/sendall', .to_json end |
#qrcode_create_limit_scene(scene_id_or_str) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/wechat/concern/common.rb', line 68 def qrcode_create_limit_scene(scene_id_or_str) case scene_id_or_str when 0.class post 'qrcode/create', JSON.generate(action_name: 'QR_LIMIT_SCENE', action_info: { scene: { scene_id: scene_id_or_str } }) else post 'qrcode/create', JSON.generate(action_name: 'QR_LIMIT_STR_SCENE', action_info: { scene: { scene_str: scene_id_or_str } }) end end |
#qrcode_create_scene(scene_id_or_str, expire_seconds = 604800) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wechat/concern/common.rb', line 55 def qrcode_create_scene(scene_id_or_str, expire_seconds = 604800) case scene_id_or_str when 0.class post 'qrcode/create', JSON.generate(expire_seconds: expire_seconds, action_name: 'QR_SCENE', action_info: { scene: { scene_id: scene_id_or_str } }) else post 'qrcode/create', JSON.generate(expire_seconds: expire_seconds, action_name: 'QR_STR_SCENE', action_info: { scene: { scene_str: scene_id_or_str } }) end end |
#shorturl(long_url) ⇒ Object
79 80 81 |
# File 'lib/wechat/concern/common.rb', line 79 def shorturl(long_url) post 'shorturl', JSON.generate(action: 'long2short', long_url: long_url) end |
#tag(tagid, next_openid = '') ⇒ Object
185 186 187 |
# File 'lib/wechat/concern/common.rb', line 185 def tag(tagid, next_openid = '') post 'user/tag/get', JSON.generate(tagid: tagid, next_openid: next_openid) end |
#tag_add_user(tagid, openids) ⇒ Object
177 178 179 |
# File 'lib/wechat/concern/common.rb', line 177 def tag_add_user(tagid, openids) post 'tags/members/batchtagging', JSON.generate(openid_list: openids, tagid: tagid) end |
#tag_create(tag_name) ⇒ Object
165 166 167 |
# File 'lib/wechat/concern/common.rb', line 165 def tag_create(tag_name) post 'tags/create', JSON.generate(tag: { name: tag_name }) end |
#tag_del_user(tagid, openids) ⇒ Object
181 182 183 |
# File 'lib/wechat/concern/common.rb', line 181 def tag_del_user(tagid, openids) post 'tags/members/batchuntagging', JSON.generate(openid_list: openids, tagid: tagid) end |
#tag_delete(tagid) ⇒ Object
173 174 175 |
# File 'lib/wechat/concern/common.rb', line 173 def tag_delete(tagid) post 'tags/delete', JSON.generate(tag: { id: tagid }) end |
#tag_update(tagid, new_tag_name) ⇒ Object
169 170 171 |
# File 'lib/wechat/concern/common.rb', line 169 def tag_update(tagid, new_tag_name) post 'tags/update', JSON.generate(tag: { id: tagid, name: new_tag_name }) end |
#tags ⇒ Object
161 162 163 |
# File 'lib/wechat/concern/common.rb', line 161 def get 'tags/get' end |
#user(openid) ⇒ Object
35 36 37 |
# File 'lib/wechat/concern/common.rb', line 35 def user(openid) get 'user/info', params: { openid: openid } end |
#user_batchget(openids, lang = 'zh-CN') ⇒ Object
39 40 41 |
# File 'lib/wechat/concern/common.rb', line 39 def user_batchget(openids, lang = 'zh-CN') post 'user/info/batchget', JSON.generate(user_list: openids.collect { |v| { openid: v, lang: lang } }) end |
#user_change_group(openid, to_groupid) ⇒ Object
47 48 49 |
# File 'lib/wechat/concern/common.rb', line 47 def user_change_group(openid, to_groupid) post 'groups/members/update', JSON.generate(openid: openid, to_groupid: to_groupid) end |
#user_group(openid) ⇒ Object
43 44 45 |
# File 'lib/wechat/concern/common.rb', line 43 def user_group(openid) post 'groups/getid', JSON.generate(openid: openid) end |
#user_update_remark(openid, remark) ⇒ Object
51 52 53 |
# File 'lib/wechat/concern/common.rb', line 51 def user_update_remark(openid, remark) post 'user/info/updateremark', JSON.generate(openid: openid, remark: remark) end |
#users(nextid = nil) ⇒ Object
30 31 32 33 |
# File 'lib/wechat/concern/common.rb', line 30 def users(nextid = nil) params = { params: { next_openid: nextid } } if nextid.present? get('user/get', params || {}) end |
#web_access_token(code) ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/wechat/concern/common.rb', line 189 def web_access_token(code) params = { appid: access_token.appid, secret: access_token.secret, code: code, grant_type: 'authorization_code' } client.get 'oauth2/access_token', params: params, base: OAUTH2_BASE end |
#web_auth_access_token(web_access_token, openid) ⇒ Object
199 200 201 |
# File 'lib/wechat/concern/common.rb', line 199 def web_auth_access_token(web_access_token, openid) client.get 'auth', params: { access_token: web_access_token, openid: openid }, base: OAUTH2_BASE end |
#web_refresh_access_token(user_refresh_token) ⇒ Object
203 204 205 206 207 208 209 210 |
# File 'lib/wechat/concern/common.rb', line 203 def web_refresh_access_token(user_refresh_token) params = { appid: access_token.appid, grant_type: 'refresh_token', refresh_token: user_refresh_token } client.get 'oauth2/refresh_token', params: params, base: OAUTH2_BASE end |
#web_userinfo(web_access_token, openid, lang = 'zh_CN') ⇒ Object
212 213 214 |
# File 'lib/wechat/concern/common.rb', line 212 def web_userinfo(web_access_token, openid, lang = 'zh_CN') client.get 'userinfo', params: { access_token: web_access_token, openid: openid, lang: lang }, base: OAUTH2_BASE end |
#wxa_create_qrcode(path, width = 430) ⇒ Object
103 104 105 |
# File 'lib/wechat/concern/common.rb', line 103 def wxa_create_qrcode(path, width = 430) post 'wxaapp/createwxaqrcode', JSON.generate(path: path, width: width) end |
#wxa_get_wxacode(path, width = 430) ⇒ Object
99 100 101 |
# File 'lib/wechat/concern/common.rb', line 99 def wxa_get_wxacode(path, width = 430) post 'getwxacode', JSON.generate(path: path, width: width), base: WXA_BASE end |