if (!function_exists('send_dd_msg')) {
/**
* 傳送釘釘訊息.
*
* @see https://developers.dingtalk.com/document/robots/custom-robot-access/title-r82-8g5-0sk
*
* @param $api
* @param $content
* @param $at
*
* @return string
*/
function send_dd_msg($api, $content, $at = [])
{
try {
$data = [
'msgtype' => 'text',
'text' => ['content' => $content],
];
if ($at) {
$data['at'] = $at;
}
$opts = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json;charset=utf-8',
'content' => json_encode($data),
'timeout' => 15,
],
];
return file_get_contents($api, false, stream_context_create($opts));
} catch (\Throwable $e) {
return '';
}
}
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結