From 8105eb79ca30f7db005b401fcbc032a453588c39 Mon Sep 17 00:00:00 2001 From: tradewind Date: Sun, 7 Feb 2021 19:50:21 +0800 Subject: [PATCH] #tradewind:update notify --- composer.json | 3 ++- jobs/ddns.php | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index e31d820..2d8c00c 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ }, "require": { "php": ">=7.1.0", - "cloudflare/sdk": "^1.1" + "cloudflare/sdk": "^1.1", + "guzzlehttp/guzzle": "~6.0" } } diff --git a/jobs/ddns.php b/jobs/ddns.php index 1197797..9891ab3 100644 --- a/jobs/ddns.php +++ b/jobs/ddns.php @@ -44,10 +44,17 @@ if (!empty($realIp)) { try { $dns->updateRecordDetails($zoneID, $recordId, $details); - $cmd = <<< CMD -curl -s 'https://oapi.dingtalk.com/robot/send?access_token={$globalConfig['dingtalk_token']}' -H 'Content-Type: application/json' -d "{\"msgtype\": \"text\",\"text\": {\"content\": \"$msg\"}}" -CMD; - shell_exec($cmd); + $url = 'https://sc.ftqq.com/' . $globalConfig['serverchan_token'] . '.send'; + + $client = new \GuzzleHttp\Client(); + $client->request('POST', $url, [ + 'text' => 'IP变更', + 'desc' => $msg, + ]); +// $cmd = <<< CMD +//curl -s 'https://oapi.dingtalk.com/robot/send?access_token={$globalConfig['dingtalk_token']}' -H 'Content-Type: application/json' -d "{\"msgtype\": \"text\",\"text\": {\"content\": \"$msg\"}}" +//CMD; +// shell_exec($cmd); logMessage('SUCCESS', $msg); } catch (Exception $e) { @@ -61,6 +68,27 @@ CMD; } +function sc_send($text, $desp = '', $key = 'SCU159053T3de1450d55d3b894e39c7a2ecd583984601fce6865119') +{ + $postdata = http_build_query( + array( + 'text' => $text, + 'desp' => $desp + ) + ); + + $opts = array('http' => + array( + 'method' => 'POST', + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $postdata + ) + ); + $context = stream_context_create($opts); + return $result = file_get_contents('https://sc.ftqq.com/' . $key . '.send', false, $context); + +} + function logMessage($type, $msg = '') {