def robot(url: str, msg: str, at_mobiles: list, is_at_all: bool = False):
data = {
"msgtype": "text",
"text": {
"content": msg
}
}
if at_mobiles:
at_mobiles = list(map(str, at_mobiles))
data["at"] = {"atMobiles": at_mobiles, "isAtAll": is_at_all}
data = json.dumps(data)
try:
response = requests.post(url=url, headers={'Content-Type': 'application/json; charset=utf-8'}, data=data, timeout=2)
except requests.exceptions.HTTPError as exc:
Log("消息发送失败, HTTP error: %s, reason: %s" % (exc.response.status_code, exc.response.reason))
raise
except requests.exceptions.ConnectionError:
Log("消息发送失败,连接失败!")
raise
else:
result = response.json()
return result
def goods_num_warning(goods: GoodsDef):
if goods:
info = ARGoodsSupplierInfo.by_id(int(goods.id), fail=False)
_info = ARGoodsSupplierDef.by_id(int(goods.id), fail=False)
url = "https://oapi.dingtalk.com/robot/send?access_token=a75183aea75ccffdf84c615503546ace6cd42afd9cd938f8f2dd3644c62a06f1"
if info.output - _info.total == 0:
robot(url, "[%s][%s] 库存:%s,出货数:%s,没有库存了" % (goods.id, goods.name, _info.total, info.output), [], True)
if info.output - _info.total > 0:
robot(url, "[%s][%s] 库存:%s,出货数:%s,超出库存了" % (goods.id, goods.name, _info.total, info.output), [], True)
钉钉机器人
最新推荐文章于 2024-07-15 13:47:28 发布