123456789101112131415161718192021222324 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import logging
- import simplejson as json
- import requests
- from django.utils.encoding import force_text
- logger = logging.getLogger(__name__)
- _DINGDING_TALK_URL = 'https://oapi.dingtalk.com/robot/send?access_token=acb44458217bd584bd3c29129c7ac6e59b6484314b441374b8b79dab9181f7ee'
- class DingDingRobot(object):
- def __init__(self, url=_DINGDING_TALK_URL):
- self.url = url
- def send_msg(self, msg):
- data = {"msgtype": "text", "text": {"content": force_text(msg)}}
- headers = {'Content-Type': 'application/json;charset=UTF-8'}
- send_data = json.dumps(data).encode('utf-8')
- response = requests.post(url=self.url, data=send_data, headers=headers, timeout=15)
- logger.debug(response.text)
|