1234567891011121314151617181920212223242526272829 |
- # -*- 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'
- SIM_CARD_EXPIRE_URL = "https://oapi.dingtalk.com/robot/send?access_token=6e0a9a36924477a9bbb60dd4abd2a0c957ff489d4d19621ccf3b533656258a67"
- class DingDingRobot(object):
- def __init__(self, url = _DINGDING_TALK_URL):
- self.url = url
- def send_msg(self, msg):
- try:
- 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)
- except Exception as e:
- logger.exception(e)
|