Class: Wechat::CorpApi

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

Constant Summary collapse

API_BASE =
'https://qyapi.weixin.qq.com/cgi-bin/'.freeze

Constants inherited from ApiBase

ApiBase::MP_BASE

Instance Attribute Summary collapse

Attributes inherited from ApiBase

#access_token, #client, #jsapi_ticket

Instance Method Summary collapse

Methods inherited from ApiBase

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

Constructor Details

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

Returns a new instance of CorpApi.



12
13
14
15
16
17
# File 'lib/wechat/corp_api.rb', line 12

def initialize(appid, secret, token_file, agentid, timeout, skip_verify_ssl, jsapi_ticket_file)
  @client = HttpClient.new(API_BASE, timeout, skip_verify_ssl)
  @access_token = Token::CorpAccessToken.new(@client, appid, secret, token_file)
  @agentid = agentid
  @jsapi_ticket = Ticket::CorpJsapiTicket.new(@client, @access_token, jsapi_ticket_file)
end

Instance Attribute Details

#agentidObject (readonly)

Returns the value of attribute agentid.



8
9
10
# File 'lib/wechat/corp_api.rb', line 8

def agentid
  @agentid
end

Instance Method Details

#agent(agentid) ⇒ Object



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

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

#agent_listObject



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

def agent_list
  get 'agent/list'
end

#batch_job_result(jobid) ⇒ Object



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

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

#batch_replaceparty(media_id) ⇒ Object



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

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

#batch_replaceuser(media_id) ⇒ Object



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

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

#batch_syncuser(media_id) ⇒ Object



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

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

#convert_to_openid(userid) ⇒ Object



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

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

#custom_message_send(message) ⇒ Object



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

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



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

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

#department_create(name, parentid) ⇒ Object



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

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

#department_delete(departmentid) ⇒ Object



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

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

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



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

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

#getuserinfo(code) ⇒ Object



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

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

#invite_user(userid) ⇒ Object



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

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

#material(media_id) ⇒ Object



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

def material(media_id)
  get 'material/get', params: { media_id: media_id, agentid: agentid }, as: :file
end

#material_add(type, file) ⇒ Object



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

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

#material_countObject



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

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

#material_delete(media_id) ⇒ Object



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

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

#material_list(type, offset, count) ⇒ Object



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

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


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

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


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

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


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

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

#message_send(userid, message) ⇒ Object



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

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

#tag(tagid) ⇒ Object



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

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

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



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

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



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

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



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

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



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

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

#tag_update(tagid, tagname) ⇒ Object



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

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

#tagsObject



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

def tags
  get 'tag/list'
end

#user(userid) ⇒ Object



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

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

#user_auth_success(userid) ⇒ Object



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

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

#user_batchdelete(useridlist) ⇒ Object



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

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

#user_create(user) ⇒ Object



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

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

#user_delete(userid) ⇒ Object



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

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

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



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

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



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

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