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



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

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

#agent_listObject



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

def agent_list
  get 'agent/list'
end

#batch_job_result(jobid) ⇒ Object



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

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

#batch_replaceparty(media_id) ⇒ Object



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

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

#batch_replaceuser(media_id) ⇒ Object



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

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

#batch_syncuser(media_id) ⇒ Object



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

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



24
25
26
27
28
29
30
31
# File 'lib/wechat/corp_api.rb', line 24

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



41
42
43
# File 'lib/wechat/corp_api.rb', line 41

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

#convert_to_userid(openid) ⇒ Object



45
46
47
# File 'lib/wechat/corp_api.rb', line 45

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

#custom_message_send(message) ⇒ Object



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

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



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

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

#department_create(name, parentid) ⇒ Object



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

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

#department_delete(departmentid) ⇒ Object



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

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

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



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

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

#get_material(media_id) ⇒ Object



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

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

#getuserinfo(code) ⇒ Object



37
38
39
# File 'lib/wechat/corp_api.rb', line 37

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

#invite_user(userid) ⇒ Object



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

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

#material(media_id) ⇒ Object



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

def material(media_id)
  ActiveSupport::Deprecation.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



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

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

#material_countObject



150
151
152
# File 'lib/wechat/corp_api.rb', line 150

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

#material_delete(media_id) ⇒ Object



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

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

#material_list(type, offset, count) ⇒ Object



154
155
156
# File 'lib/wechat/corp_api.rb', line 154

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


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

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


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

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


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

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

#message_send(userid, message) ⇒ Object



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

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



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

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

#msgaudit_check_single_agree(info) ⇒ Object



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

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



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

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

#msgaudit_groupchat(roomid) ⇒ Object



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

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

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



180
181
182
183
184
185
186
# File 'lib/wechat/corp_api.rb', line 180

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



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

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

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



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

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



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

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



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

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



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

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

#tag_update(tagid, tagname) ⇒ Object



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

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

#tagsObject



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

def tags
  get 'tag/list'
end

#user(userid) ⇒ Object



33
34
35
# File 'lib/wechat/corp_api.rb', line 33

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

#user_auth_success(userid) ⇒ Object



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

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

#user_batchdelete(useridlist) ⇒ Object



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

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

#user_create(user) ⇒ Object



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

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

#user_delete(userid) ⇒ Object



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

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

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



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

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



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

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