Module: Wechat::Concern::Common

Included in:
Api, MpApi
Defined in:
lib/wechat/concern/common.rb

Instance Method Summary collapse

Instance Method Details

#addvoicetorecofortext(voice_id, file, file_format = 'mp3', lang = 'zh_CN') ⇒ Object



224
225
226
# File 'lib/wechat/concern/common.rb', line 224

def addvoicetorecofortext(voice_id, file, file_format = 'mp3', lang = 'zh_CN')
  post_file 'media/voice/addvoicetorecofortext', file, params: { format: file_format, voice_id: voice_id, lang: lang }
end

#custom_message_send(message) ⇒ Object



180
181
182
# File 'lib/wechat/concern/common.rb', line 180

def custom_message_send(message)
  post 'message/custom/send', message.is_a?(Wechat::Message) ? message.to_json : JSON.generate(message), content_type: :json
end

#customservice_getonlinekflistObject



184
185
186
# File 'lib/wechat/concern/common.rb', line 184

def customservice_getonlinekflist
  get 'customservice/getonlinekflist'
end

#get_material(media_id) ⇒ Object



153
154
155
# File 'lib/wechat/concern/common.rb', line 153

def get_material(media_id)
  post 'material/get_material', JSON.generate(media_id: media_id), as: :file
end

#getusercumulate(begin_date, end_date) ⇒ Object



220
221
222
# File 'lib/wechat/concern/common.rb', line 220

def getusercumulate(begin_date, end_date)
  post 'getusercumulate', JSON.generate(begin_date: begin_date, end_date: end_date), base: Wechat::Api::DATACUBE_BASE
end

#getusersummary(begin_date, end_date) ⇒ Object



216
217
218
# File 'lib/wechat/concern/common.rb', line 216

def getusersummary(begin_date, end_date)
  post 'getusersummary', JSON.generate(begin_date: begin_date, end_date: end_date), base: Wechat::Api::DATACUBE_BASE
end

#group_create(group_name) ⇒ Object



10
11
12
# File 'lib/wechat/concern/common.rb', line 10

def group_create(group_name)
  post 'groups/create', JSON.generate(group: { name: group_name })
end

#group_delete(groupid) ⇒ Object



18
19
20
# File 'lib/wechat/concern/common.rb', line 18

def group_delete(groupid)
  post 'groups/delete', JSON.generate(group: { id: groupid })
end

#group_update(groupid, new_group_name) ⇒ Object



14
15
16
# File 'lib/wechat/concern/common.rb', line 14

def group_update(groupid, new_group_name)
  post 'groups/update', JSON.generate(group: { id: groupid, name: new_group_name })
end

#groupsObject



6
7
8
# File 'lib/wechat/concern/common.rb', line 6

def groups
  get 'groups/get'
end

#material(media_id) ⇒ Object



147
148
149
150
151
# File 'lib/wechat/concern/common.rb', line 147

def material(media_id)
  ActiveSupport::Deprecation.new.warn('material is deprecated. use get_material instead.')

  post 'material/get_material', JSON.generate(media_id: media_id), as: :file
end

#material_add(type, file, opts = {}) ⇒ Object



165
166
167
168
169
170
# File 'lib/wechat/concern/common.rb', line 165

def material_add(type, file, opts = {})
  params = { type: type }
  params.merge!(description: opts.slice(:title, :introduction).to_json) if type == 'video'

  post_file 'material/add_material', file, params: params
end

#material_add_news(mpnews_message) ⇒ Object



172
173
174
# File 'lib/wechat/concern/common.rb', line 172

def material_add_news(mpnews_message)
  post 'material/add_news', mpnews_message.to_json
end

#material_countObject



157
158
159
# File 'lib/wechat/concern/common.rb', line 157

def material_count
  get 'material/get_materialcount'
end

#material_delete(media_id) ⇒ Object



176
177
178
# File 'lib/wechat/concern/common.rb', line 176

def material_delete(media_id)
  post 'material/del_material', JSON.generate(media_id: media_id)
end

#material_list(type, offset, count) ⇒ Object



161
162
163
# File 'lib/wechat/concern/common.rb', line 161

def material_list(type, offset, count)
  post 'material/batchget_material', JSON.generate(type: type, offset: offset, count: count)
end


121
122
123
# File 'lib/wechat/concern/common.rb', line 121

def menu
  get 'menu/get'
end


134
135
136
137
# File 'lib/wechat/concern/common.rb', line 134

def menu_addconditional(menu)
  # Wechat not accept 7bit escaped json(eg \uxxxx), must using UTF-8, possible security vulnerability?
  post 'menu/addconditional', JSON.generate(menu)
end


129
130
131
132
# File 'lib/wechat/concern/common.rb', line 129

def menu_create(menu)
  # 微信不接受 7bit escaped json(eg \uxxxx),中文必须 UTF-8 编码,这可能是个安全漏洞
  post 'menu/create', JSON.generate(menu)
end


143
144
145
# File 'lib/wechat/concern/common.rb', line 143

def menu_delconditional(menuid)
  post 'menu/delconditional', JSON.generate(menuid: menuid)
end


125
126
127
# File 'lib/wechat/concern/common.rb', line 125

def menu_delete
  get 'menu/delete'
end


139
140
141
# File 'lib/wechat/concern/common.rb', line 139

def menu_trymatch(user_id)
  post 'menu/trymatch', JSON.generate(user_id: user_id)
end

#message_mass_delete(msg_id) ⇒ Object



79
80
81
# File 'lib/wechat/concern/common.rb', line 79

def message_mass_delete(msg_id)
  post 'message/mass/delete', JSON.generate(msg_id: msg_id)
end

#message_mass_get(msg_id) ⇒ Object



87
88
89
# File 'lib/wechat/concern/common.rb', line 87

def message_mass_get(msg_id)
  post 'message/mass/get', JSON.generate(msg_id: msg_id)
end

#message_mass_preview(message) ⇒ Object



83
84
85
# File 'lib/wechat/concern/common.rb', line 83

def message_mass_preview(message)
  post 'message/mass/preview', message.to_json
end

#message_mass_sendall(message) ⇒ Object



75
76
77
# File 'lib/wechat/concern/common.rb', line 75

def message_mass_sendall(message)
  post 'message/mass/sendall', message.to_json
end

#qrcode_create_limit_scene(scene_id_or_str) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/wechat/concern/common.rb', line 60

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



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wechat/concern/common.rb', line 47

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

#queryrecoresultfortext(voice_id, lang = 'zh_CN') ⇒ Object



228
229
230
# File 'lib/wechat/concern/common.rb', line 228

def queryrecoresultfortext(voice_id, lang = 'zh_CN')
  post 'media/voice/queryrecoresultfortext', nil, params: { voice_id: voice_id, lang: lang }
end

#shorturl(long_url) ⇒ Object



71
72
73
# File 'lib/wechat/concern/common.rb', line 71

def shorturl(long_url)
  post 'shorturl', JSON.generate(action: 'long2short', long_url: long_url)
end

#tag(tagid, next_openid = '') ⇒ Object



212
213
214
# File 'lib/wechat/concern/common.rb', line 212

def tag(tagid, next_openid = '')
  post 'user/tag/get', JSON.generate(tagid: tagid, next_openid: next_openid)
end

#tag_add_user(tagid, openids) ⇒ Object



204
205
206
# File 'lib/wechat/concern/common.rb', line 204

def tag_add_user(tagid, openids)
  post 'tags/members/batchtagging', JSON.generate(openid_list: openids, tagid: tagid)
end

#tag_create(tag_name) ⇒ Object



192
193
194
# File 'lib/wechat/concern/common.rb', line 192

def tag_create(tag_name)
  post 'tags/create', JSON.generate(tag: { name: tag_name })
end

#tag_del_user(tagid, openids) ⇒ Object



208
209
210
# File 'lib/wechat/concern/common.rb', line 208

def tag_del_user(tagid, openids)
  post 'tags/members/batchuntagging', JSON.generate(openid_list: openids, tagid: tagid)
end

#tag_delete(tagid) ⇒ Object



200
201
202
# File 'lib/wechat/concern/common.rb', line 200

def tag_delete(tagid)
  post 'tags/delete', JSON.generate(tag: { id: tagid })
end

#tag_update(tagid, new_tag_name) ⇒ Object



196
197
198
# File 'lib/wechat/concern/common.rb', line 196

def tag_update(tagid, new_tag_name)
  post 'tags/update', JSON.generate(tag: { id: tagid, name: new_tag_name })
end

#tagsObject



188
189
190
# File 'lib/wechat/concern/common.rb', line 188

def tags
  get 'tags/get'
end

#translatecontent(from_content, lfrom = 'zh_CN', lto = 'en_US') ⇒ Object



232
233
234
# File 'lib/wechat/concern/common.rb', line 232

def translatecontent(from_content, lfrom = 'zh_CN', lto = 'en_US')
  post 'media/voice/translatecontent', from_content, params: { lfrom: lfrom, lto: lto }
end

#user(openid) ⇒ Object



27
28
29
# File 'lib/wechat/concern/common.rb', line 27

def user(openid)
  get 'user/info', params: { openid: openid }
end

#user_batchget(openids, lang = 'zh-CN') ⇒ Object



31
32
33
# File 'lib/wechat/concern/common.rb', line 31

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



39
40
41
# File 'lib/wechat/concern/common.rb', line 39

def user_change_group(openid, to_groupid)
  post 'groups/members/update', JSON.generate(openid: openid, to_groupid: to_groupid)
end

#user_group(openid) ⇒ Object



35
36
37
# File 'lib/wechat/concern/common.rb', line 35

def user_group(openid)
  post 'groups/getid', JSON.generate(openid: openid)
end

#user_update_remark(openid, remark) ⇒ Object



43
44
45
# File 'lib/wechat/concern/common.rb', line 43

def user_update_remark(openid, remark)
  post 'user/info/updateremark', JSON.generate(openid: openid, remark: remark)
end

#users(nextid = nil) ⇒ Object



22
23
24
25
# File 'lib/wechat/concern/common.rb', line 22

def users(nextid = nil)
  params = { params: { next_openid: nextid } } if nextid.present?
  get('user/get', params || {})
end

#web_access_token(code) ⇒ Object



236
237
238
239
240
241
242
243
244
# File 'lib/wechat/concern/common.rb', line 236

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: Wechat::Api::OAUTH2_BASE
end

#web_auth_access_token(web_access_token, openid) ⇒ Object



246
247
248
# File 'lib/wechat/concern/common.rb', line 246

def web_auth_access_token(web_access_token, openid)
  client.get 'auth', params: { access_token: web_access_token, openid: openid }, base: Wechat::Api::OAUTH2_BASE
end

#web_refresh_access_token(user_refresh_token) ⇒ Object



250
251
252
253
254
255
256
257
# File 'lib/wechat/concern/common.rb', line 250

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: Wechat::Api::OAUTH2_BASE
end

#web_userinfo(web_access_token, openid, lang = 'zh_CN') ⇒ Object



259
260
261
# File 'lib/wechat/concern/common.rb', line 259

def web_userinfo(web_access_token, openid, lang = 'zh_CN')
  client.get 'userinfo', params: { access_token: web_access_token, openid: openid, lang: lang }, base: Wechat::Api::OAUTH2_BASE
end

#wxa_create_qrcode(path, width = 430) ⇒ Object



104
105
106
# File 'lib/wechat/concern/common.rb', line 104

def wxa_create_qrcode(path, width = 430)
  post 'wxaapp/createwxaqrcode', JSON.generate(path: path, width: width)
end


117
118
119
# File 'lib/wechat/concern/common.rb', line 117

def wxa_generate_shortlink(body_hash)
  post 'genwxashortlink', JSON.generate(body_hash), base: Wechat::Api::WXA_BASE
end


112
113
114
115
# File 'lib/wechat/concern/common.rb', line 112

def wxa_generate_urllink(body_hash)
  # https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html
  post 'generate_urllink', JSON.generate(body_hash), base: Wechat::Api::WXA_BASE
end

#wxa_get_user_phone_number(code) ⇒ Object



91
92
93
94
# File 'lib/wechat/concern/common.rb', line 91

def wxa_get_user_phone_number(code)
  # https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html
  post 'business/getuserphonenumber', JSON.generate(code: code), base: Wechat::Api::WXA_BASE
end

#wxa_get_wxacode(path, width = 430) ⇒ Object



96
97
98
# File 'lib/wechat/concern/common.rb', line 96

def wxa_get_wxacode(path, width = 430)
  post 'getwxacode', JSON.generate(path: path, width: width), base: Wechat::Api::WXA_BASE
end

#wxa_get_wxacode_unlimit(scene, page = nil, width = 430) ⇒ Object



100
101
102
# File 'lib/wechat/concern/common.rb', line 100

def wxa_get_wxacode_unlimit(scene, page = nil, width = 430)
  post 'getwxacodeunlimit', JSON.generate(scene: scene, page: page, width: width), base: Wechat::Api::WXA_BASE
end

#wxa_msg_sec_check(content) ⇒ Object



108
109
110
# File 'lib/wechat/concern/common.rb', line 108

def wxa_msg_sec_check(content)
  post 'msg_sec_check', JSON.generate(content: content), base: Wechat::Api::WXA_BASE
end