You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pdd-order-api/app/libs/tool/class.DingTalkTool.php

120 lines
4.4 KiB
PHP

<?php
class DingTalkTool {
const dingTalkBizDsPurchaseOrderUpdate = 'dsPurchaseOrderUpdate';
const dingTalkBizAdminSelf = 'adminSelf';
const dingTalkBizDsMessageProcess = 'dsMessageProcess';
const dingTalkBizDsAutoAfs = 'dsAutoAfs';
const dingTalkBizMonitorWaitProcessPlatformAfs = 'monitorWaitProcessPlatformAfs';
const dingTalkBizMonitorNoPushPlatformAfs = 'monitorNoPushPlatformAfs';
const dingTalkDsOrderMergeException = 'dsOrderMergeException';
const warningDsMessageProcessLimit = 500;
private static function getAtMobiles($bizKey) {
$atMobiles = [];
switch ($bizKey) {
case self::dingTalkDsOrderMergeException:
case self::dingTalkBizDsPurchaseOrderUpdate:
$atMobiles[] = '15280166568';
$atMobiles[] = '18650082100';
$atMobiles[] = '18059004031';
break;
default:
break;
}
return $atMobiles;
}
private static function getRobotConfig($bizKey) {
switch ($bizKey) {
case self::dingTalkBizAdminSelf:
//【订单软件预警群】
$robotConfig = [
'accessToken' => '8576d292b80fbff8be0f6d7b54c457455869b96d20aa4af6e0ba1337814bd2ed',
'secret' => 'SECc394240efbed19b82969d8326d87fa18d53dcfe018e52bac08aa9adb72ea9590',
];
break;
break;
case self::dingTalkBizDsPurchaseOrderUpdate:
case self::dingTalkDsOrderMergeException:
//主客铺货订单同步预警
$robotConfig = [
'accessToken' => 'af7472757e374b989161051ced00cfa0fd2751e255812736f937d79ca0093629',
'secret' => 'SEC166963154c95e671bc27e15953d2c1c3f3df82e188e74eef3da0313228259775',
];
break;
case self::dingTalkBizDsMessageProcess:
//主客铺货订单同步预警
$robotConfig = [
'accessToken' => '6b7258a8dddd4029e97847d090b4598264a6f60654c533a07fc509ea5f847e1a',
'secret' => 'SEC3b0ba512a3b8625e652603b9ae7a4103cc4286af8935d48c563f69e777a150ea',
];
break;
case self::dingTalkBizDsAutoAfs:
case self::dingTalkBizMonitorWaitProcessPlatformAfs:
case self::dingTalkBizMonitorNoPushPlatformAfs:
//主客铺货售后预警
$robotConfig = [
'accessToken' => '64d850a178f1a8ab09e4614526e506e0a09d6a35277d668b4cdec6f31a75321d',
'secret' => 'SEC159b3475c07ddb018712e79d7dd5d3bf6b9cdbdf7c784b5a2e767acfb297101d',
];
break;
default:
$robotConfig = null;
break;
}
return $robotConfig;
}
public static function sendMessage($bizKey, $message, $atMobiles = [], $isAtAll = false, $title = "监控预警") {
$robotConfig = self::getRobotConfig($bizKey);
if (!$robotConfig) {
return CommonTool::failResult('机器人不存在');
}
$atMobiles = $atMobiles ?: [];
$atMobiles = array_merge($atMobiles, self::getAtMobiles($bizKey));
if ($robotConfig['secret']) {
$timestamp = ZcNumberHelper::microtimeFloat(3) * 1000;
$sign = hash_hmac('sha256', $timestamp . "\n" . $robotConfig['secret'], $robotConfig['secret'],true);
$sign = base64_encode($sign);
$sign = urlencode($sign);
$dingdingRobotUrl = sprintf('https://oapi.dingtalk.com/robot/send?access_token=%s&timestamp=%s&sign=%s', $robotConfig['accessToken'], $timestamp, $sign);
} else {
$dingdingRobotUrl = sprintf('https://oapi.dingtalk.com/robot/send?access_token=%s', $robotConfig['accessToken']);
}
$curl = CommonTool::getCurl();
$headers = array (
'Content-Type: application/json',
);
$curl->setCurlOpt(CURLOPT_HTTPHEADER, $headers);
$msgData = array(
'title' => $title,
'msgtype' => 'text',
'text' => array(
'content' => $message,
),
);
if (!empty($atMobiles)) {
$msgData['at'] = array (
'atMobiles' => $atMobiles,
'isAtAll' => $isAtAll
);
}
$msgData = json_encode($msgData);
return $curl->post($dingdingRobotUrl, $msgData);
}
}