Class: Wechat::CorpApi

Inherits:
ApiBase show all
Defined in:
lib/wechat/corp_api.rb

Constant Summary

Constants inherited from ApiBase

ApiBase::API_BASE, ApiBase::DATACUBE_BASE, ApiBase::MP_BASE, ApiBase::OAUTH2_BASE, ApiBase::QYAPI_BASE, ApiBase::TCB_BASE, ApiBase::WXA_BASE

Instance Attribute Summary collapse

Attributes inherited from ApiBase

#access_token, #client, #jsapi_ticket, #qcloud

Instance Method Summary collapse

Methods inherited from ApiBase

#callbackip, #clear_quota, #media, #media_create, #media_hq, #media_uploadimg, #media_uploadnews, #qrcode

Constructor Details

#initialize(appid, secret, token_file, agentid, network_setting, jsapi_ticket_file) ⇒ CorpApi

Returns a new instance of CorpApi.



7
8
9
10
11
12
13
14
# File 'lib/wechat/corp_api.rb', line 7

def initialize(appid, secret, token_file, agentid, network_setting, jsapi_ticket_file)
  super()
  @client = HttpClient.new(QYAPI_BASE, network_setting)
  @access_token = Token::CorpAccessToken.new(@client, appid, secret, token_file)
  @agentid = agentid
  @jsapi_ticket = Ticket::CorpJsapiTicket.new(@client, @access_token, jsapi_ticket_file)
  @qcloud = nil
end

Instance Attribute Details

#agentidObject (readonly)

Returns the value of attribute agentid.



5
6
7
# File 'lib/wechat/corp_api.rb', line 5

def agentid
  @agentid
end

Instance Method Details

#agent(agentid) ⇒ Object



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

def agent(agentid)
  get 'agent/get', params: { agentid: agentid }
end

#agent_listObject



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

def agent_list
  get 'agent/list'
end

#batch_get_by_user(userid_list, cursor: nil, limit: nil) ⇒ Object



26
27
28
29
# File 'lib/wechat/corp_api.rb', line 26

def batch_get_by_user(userid_list, cursor: nil, limit: nil)
  # https://developer.work.weixin.qq.com/document/path/93010
  post 'externalcontact/batch/get_by_user', JSON.generate(userid_list: userid_list, cursor: cursor, limit: limit)
end

#batch_job_result(jobid) ⇒ Object



84
85
86
# File 'lib/wechat/corp_api.rb', line 84

def batch_job_result(jobid)
  get 'batch/getresult', params: { jobid: jobid }
end

#batch_replaceparty(media_id) ⇒ Object



88
89
90
# File 'lib/wechat/corp_api.rb', line 88

def batch_replaceparty(media_id)
  post 'batch/replaceparty', JSON.generate(media_id: media_id)
end

#batch_replaceuser(media_id) ⇒ Object



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

def batch_replaceuser(media_id)
  post 'batch/replaceuser', JSON.generate(media_id: media_id)
end

#batch_syncuser(media_id) ⇒ Object



92
93
94
# File 'lib/wechat/corp_api.rb', line 92

def batch_syncuser(media_id)
  post 'batch/syncuser', JSON.generate(media_id: media_id)
end

#checkin(useridlist, starttime = Time.now.beginning_of_day, endtime = Time.now.end_of_day, opencheckindatatype = 3) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/wechat/corp_api.rb', line 39

def checkin(useridlist, starttime = Time.now.beginning_of_day, endtime = Time.now.end_of_day, opencheckindatatype = 3)
  post 'checkin/getcheckindata', JSON.generate(
    opencheckindatatype: opencheckindatatype,
    starttime: starttime.to_i,
    endtime: endtime.to_i,
    useridlist: useridlist
  )
end

#convert_to_openid(userid) ⇒ Object



56
57
58
# File 'lib/wechat/corp_api.rb', line 56

def convert_to_openid(userid)
  post 'user/convert_to_openid', JSON.generate(userid: userid, agentid: agentid)
end

#convert_to_userid(openid) ⇒ Object



60
61
62
# File 'lib/wechat/corp_api.rb', line 60

def convert_to_userid(openid)
  post 'user/convert_to_userid', JSON.generate(openid: openid)
end

#custom_message_send(message) ⇒ Object



203
204
205
# File 'lib/wechat/corp_api.rb', line 203

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

#department(departmentid = 1) ⇒ Object



112
113
114
# File 'lib/wechat/corp_api.rb', line 112

def department(departmentid = 1)
  get 'department/list', params: { id: departmentid }
end

#department_create(name, parentid) ⇒ Object



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

def department_create(name, parentid)
  post 'department/create', JSON.generate(name: name, parentid: parentid)
end

#department_delete(departmentid) ⇒ Object



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

def department_delete(departmentid)
  get 'department/delete', params: { id: departmentid }
end

#department_update(departmentid, name = nil, parentid = nil, order = nil) ⇒ Object



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

def department_update(departmentid, name = nil, parentid = nil, order = nil)
  post 'department/update', JSON.generate({ id: departmentid, name: name, parentid: parentid, order: order }.compact)
end

#follow_user_listObject



21
22
23
24
# File 'lib/wechat/corp_api.rb', line 21

def follow_user_list
  # https://developer.work.weixin.qq.com/document/path/92576
  get 'externalcontact/get_follow_user_list'
end

#get_externalcontact(external_userid, cursor = nil) ⇒ Object



16
17
18
19
# File 'lib/wechat/corp_api.rb', line 16

def get_externalcontact(external_userid, cursor = nil)
  # https://developer.work.weixin.qq.com/document/path/92114
  get 'externalcontact/get', params: { external_userid: external_userid, cursor: cursor }
end

#get_material(media_id) ⇒ Object



179
180
181
# File 'lib/wechat/corp_api.rb', line 179

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

#getuserinfo(code) ⇒ Object



52
53
54
# File 'lib/wechat/corp_api.rb', line 52

def getuserinfo(code)
  get 'user/getuserinfo', params: { code: code }
end

#invite_user(userid) ⇒ Object



64
65
66
# File 'lib/wechat/corp_api.rb', line 64

def invite_user(userid)
  post 'invite/send', JSON.generate(userid: userid)
end

#material(media_id) ⇒ Object



173
174
175
176
177
# File 'lib/wechat/corp_api.rb', line 173

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), params: { agentid: agentid }, as: :file
end

#material_add(type, file) ⇒ Object



183
184
185
# File 'lib/wechat/corp_api.rb', line 183

def material_add(type, file)
  post_file 'material/add_material', file, params: { type: type, agentid: agentid }
end

#material_countObject



165
166
167
# File 'lib/wechat/corp_api.rb', line 165

def material_count
  get 'material/get_count', params: { agentid: agentid }
end

#material_delete(media_id) ⇒ Object



187
188
189
# File 'lib/wechat/corp_api.rb', line 187

def material_delete(media_id)
  get 'material/del', params: { media_id: media_id, agentid: agentid }
end

#material_list(type, offset, count) ⇒ Object



169
170
171
# File 'lib/wechat/corp_api.rb', line 169

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


152
153
154
# File 'lib/wechat/corp_api.rb', line 152

def menu
  get 'menu/get', params: { agentid: agentid }
end


160
161
162
163
# File 'lib/wechat/corp_api.rb', line 160

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


156
157
158
# File 'lib/wechat/corp_api.rb', line 156

def menu_delete
  get 'menu/delete', params: { agentid: agentid }
end

#message_send(userid, message) ⇒ Object



191
192
193
# File 'lib/wechat/corp_api.rb', line 191

def message_send(userid, message)
  post 'message/send', Message.to(userid).text(message).agent_id(agentid).to_json, content_type: :json
end

#msgaudit_check_room_agree(roomid) ⇒ Object



215
216
217
# File 'lib/wechat/corp_api.rb', line 215

def msgaudit_check_room_agree(roomid)
  post 'msgaudit/check_room_agree', JSON.generate(roomid: roomid)
end

#msgaudit_check_single_agree(info) ⇒ Object



211
212
213
# File 'lib/wechat/corp_api.rb', line 211

def msgaudit_check_single_agree(info)
  post 'msgaudit/get_permit_user_list', JSON.generate(info: info)
end

#msgaudit_get_permit_user_list(type = nil) ⇒ Object



207
208
209
# File 'lib/wechat/corp_api.rb', line 207

def msgaudit_get_permit_user_list(type = nil)
  post 'msgaudit/get_permit_user_list', JSON.generate(type: type)
end

#msgaudit_groupchat(roomid) ⇒ Object



219
220
221
# File 'lib/wechat/corp_api.rb', line 219

def msgaudit_groupchat(roomid)
  post 'msgaudit/groupchat/get', JSON.generate(roomid: roomid)
end

#news_message_send(userid, title, description, link_url, pic_url) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/wechat/corp_api.rb', line 195

def news_message_send(userid, title, description, link_url, pic_url)
  post 'message/send', Message.to(userid).news([{ title: title,
                                                  description: description,
                                                  url: link_url,
                                                  pic_url: pic_url }])
                              .agent_id(agentid).to_json, content_type: :json
end

#tag(tagid) ⇒ Object



140
141
142
# File 'lib/wechat/corp_api.rb', line 140

def tag(tagid)
  get 'tag/get', params: { tagid: tagid }
end

#tag_add_user(tagid, userids = nil, departmentids = nil) ⇒ Object



144
145
146
# File 'lib/wechat/corp_api.rb', line 144

def tag_add_user(tagid, userids = nil, departmentids = nil)
  post 'tag/addtagusers', JSON.generate(tagid: tagid, userlist: userids, partylist: departmentids)
end

#tag_create(tagname, tagid = nil) ⇒ Object



124
125
126
# File 'lib/wechat/corp_api.rb', line 124

def tag_create(tagname, tagid = nil)
  post 'tag/create', JSON.generate(tagname: tagname, tagid: tagid)
end

#tag_del_user(tagid, userids = nil, departmentids = nil) ⇒ Object



148
149
150
# File 'lib/wechat/corp_api.rb', line 148

def tag_del_user(tagid, userids = nil, departmentids = nil)
  post 'tag/deltagusers', JSON.generate(tagid: tagid, userlist: userids, partylist: departmentids)
end

#tag_delete(tagid) ⇒ Object



132
133
134
# File 'lib/wechat/corp_api.rb', line 132

def tag_delete(tagid)
  get 'tag/delete', params: { tagid: tagid }
end

#tag_update(tagid, tagname) ⇒ Object



128
129
130
# File 'lib/wechat/corp_api.rb', line 128

def tag_update(tagid, tagname)
  post 'tag/update', JSON.generate(tagid: tagid, tagname: tagname)
end

#tagsObject



136
137
138
# File 'lib/wechat/corp_api.rb', line 136

def tags
  get 'tag/list'
end

#user(userid) ⇒ Object



48
49
50
# File 'lib/wechat/corp_api.rb', line 48

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

#user_auth_success(userid) ⇒ Object



68
69
70
# File 'lib/wechat/corp_api.rb', line 68

def user_auth_success(userid)
  get 'user/authsucc', params: { userid: userid }
end

#user_batchdelete(useridlist) ⇒ Object



80
81
82
# File 'lib/wechat/corp_api.rb', line 80

def user_batchdelete(useridlist)
  post 'user/batchdelete', JSON.generate(useridlist: useridlist)
end

#user_create(user) ⇒ Object



72
73
74
# File 'lib/wechat/corp_api.rb', line 72

def user_create(user)
  post 'user/create', JSON.generate(user)
end

#user_delete(userid) ⇒ Object



76
77
78
# File 'lib/wechat/corp_api.rb', line 76

def user_delete(userid)
  get 'user/delete', params: { userid: userid }
end

#user_list(department_id, fetch_child = 0, status = 0) ⇒ Object



120
121
122
# File 'lib/wechat/corp_api.rb', line 120

def user_list(department_id, fetch_child = 0, status = 0)
  get 'user/list', params: { department_id: department_id, fetch_child: fetch_child, status: status }
end

#user_simplelist(department_id, fetch_child = 0, status = 0) ⇒ Object



116
117
118
# File 'lib/wechat/corp_api.rb', line 116

def user_simplelist(department_id, fetch_child = 0, status = 0)
  get 'user/simplelist', params: { department_id: department_id, fetch_child: fetch_child, status: status }
end