MCPcopy Create free account
hub / github.com/Mashiro2000/HeyTapTask / WeCom

Class WeCom

sendNotify.py:280–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278 print(e)
279
280class WeCom:
281 def __init__(self, corpid, corpsecret, agentid):
282 self.CORPID = corpid
283 self.CORPSECRET = corpsecret
284 self.AGENTID = agentid
285
286 def get_access_token(self):
287 url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
288 values = {'corpid': self.CORPID,
289 'corpsecret': self.CORPSECRET,
290 }
291 req = requests.post(url, params=values)
292 data = json.loads(req.text)
293 return data["access_token"]
294
295 def send_text(self, message, touser="@all"):
296 send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + self.get_access_token()
297 send_values = {
298 "touser": touser,
299 "msgtype": "text",
300 "agentid": self.AGENTID,
301 "text": {
302 "content": message
303 },
304 "safe": "0"
305 }
306 send_msges = (bytes(json.dumps(send_values), 'utf-8'))
307 respone = requests.post(send_url, send_msges)
308 respone = respone.json()
309 return respone["errmsg"]
310
311 def send_mpnews(self, title, message, media_id, touser="@all"):
312 send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + self.get_access_token()
313 send_values = {
314 "touser": touser,
315 "msgtype": "mpnews",
316 "agentid": self.AGENTID,
317 "mpnews": {
318 "articles": [
319 {
320 "title": title,
321 "thumb_media_id": media_id,
322 "author": "Author",
323 "content_source_url": "",
324 "content": message.replace('\n', '<br/>'),
325 "digest": message
326 }
327 ]
328 }
329 }
330 send_msges = (bytes(json.dumps(send_values), 'utf-8'))
331 respone = requests.post(send_url, send_msges)
332 respone = respone.json()
333 return respone["errmsg"]
334
335def send(title, content):
336 """

Callers 1

wecom_appFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected