diff --git a/src/config.php b/src/config.php index 7078048..f9372a0 100644 --- a/src/config.php +++ b/src/config.php @@ -85,6 +85,13 @@ return [ // 钉钉 'dingtalk' => [ 'access_token' => '' + ], + // 微信 + 'wechat' => [ + // 通知微信 + 'openid' => '', + // 网站名称 + 'node' => '' ] ] ]; diff --git a/src/exception/ThinkException.php b/src/exception/ThinkException.php index 2c0ada1..320bd09 100644 --- a/src/exception/ThinkException.php +++ b/src/exception/ThinkException.php @@ -16,7 +16,9 @@ namespace DtApp\ThinkLibrary\exception; +use DtApp\ThinkLibrary\service\curl\HttpService; use DtApp\ThinkLibrary\service\DingTalkService; +use DtApp\ThinkLibrary\service\SystemService; use think\exception\Handle; use think\exception\HttpException; use think\exception\ValidateException; @@ -69,6 +71,21 @@ class ThinkException extends Handle ->accessToken($access_token) ->text($msg); } + if (!empty($nt) && $nt == 'wechat') { + $openid = config('dtapp.exception.wechat.openid', ''); + if (!empty($access_token)) return HttpService::instance() + ->url("https://api.dtapp.net/v1/wechatmp/tmplmsgWebError/openid/{$openid}") + ->post() + ->data([ + 'domain' => request()->domain(), + 'url' => request()->url(), + 'node' => config('dtapp.exception.wechat.node', ''), + 'info' => '服务器IP为:' . SystemService::instance() + ->linuxIp(), + 'error' => base64_encode($msg) + ]) + ->toArray(); + } return true; } } diff --git a/src/service/SystemService.php b/src/service/SystemService.php index 24cf322..8d54f8a 100644 --- a/src/service/SystemService.php +++ b/src/service/SystemService.php @@ -136,4 +136,18 @@ class SystemService extends Service } } } + + /** + * 获取Linux服务器IP + * @return string + */ + public function linuxIp() + { + try { + $ip_cmd = "ifconfig eth0 | sed -n '/inet addr/p' | awk '{print $2}' | awk -F ':' '{print $2}'"; + return trim(exec($ip_cmd)); + } catch (\Exception $e) { + return "0.0.0.0"; + } + } }