改名
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Server\Worker;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Server\Constant;
|
use Server\Constant;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
|
use Snowflake\Core\Help;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Snowflake\Exception\ConfigException;
|
use Snowflake\Exception\ConfigException;
|
||||||
use Snowflake\Runtime;
|
use Snowflake\Runtime;
|
||||||
@@ -150,23 +151,9 @@ class ServerWorker extends \Server\Abstracts\Server
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$email = Config::get('email');
|
$email = Config::get('email');
|
||||||
if (empty($email) || !$email['enable']) {
|
if (!empty($email) && ($email['enable'] ?? false) == true) {
|
||||||
return;
|
Help::sendEmail($email, 'Service Error', $messageContent);
|
||||||
}
|
}
|
||||||
$transport = (new \Swift_SmtpTransport($email['host'], $email['465']))
|
|
||||||
->setUsername($email['username'])
|
|
||||||
->setPassword($email['password']);
|
|
||||||
$mailer = new \Swift_Mailer($transport);
|
|
||||||
|
|
||||||
// Create a message
|
|
||||||
$message = (new \Swift_Message('Wonderful Subject'))
|
|
||||||
->setFrom([$email['send']['address'] => $email['send']['nickname']])
|
|
||||||
->setBody('Here is the message itself');
|
|
||||||
|
|
||||||
foreach ($email['receive'] as $item) {
|
|
||||||
$message->setTo([$item['address'], $item['address'] => $item['nickname']]);
|
|
||||||
}
|
|
||||||
$mailer->send($messageContent);
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
error($e, 'email');
|
error($e, 'email');
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-4
@@ -6,7 +6,6 @@ namespace Snowflake\Core;
|
|||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use JetBrains\PhpStorm\Pure;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +19,7 @@ class Help
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
#[Pure] public static function toXml(array $data): string
|
public static function toXml(array $data): string
|
||||||
{
|
{
|
||||||
$xml = "<xml>";
|
$xml = "<xml>";
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
@@ -171,10 +170,10 @@ class Help
|
|||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $array
|
||||||
* @param $key
|
* @param $key
|
||||||
* @param $type
|
* @param string $type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function sign(array $array, $key, $type = 'MD5'): string
|
public static function sign(array $array, $key, string $type = 'MD5'): string
|
||||||
{
|
{
|
||||||
ksort($array, SORT_ASC);
|
ksort($array, SORT_ASC);
|
||||||
$string = [];
|
$string = [];
|
||||||
@@ -193,4 +192,24 @@ class Help
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $email
|
||||||
|
* @param string $Subject
|
||||||
|
* @param $messageContent
|
||||||
|
*/
|
||||||
|
public static function sendEmail($email, string $Subject, $messageContent)
|
||||||
|
{
|
||||||
|
$mailer = new \Swift_Mailer((new \Swift_SmtpTransport($email['host'], $email['port']))
|
||||||
|
->setUsername($email['username'])->setPassword($email['password']));
|
||||||
|
$message = (new \Swift_Message($Subject))
|
||||||
|
->setFrom([$email['send']['address'] => $email['send']['nickname']])
|
||||||
|
->setBody('Here is the message itself');
|
||||||
|
|
||||||
|
foreach ($email['receive'] as $item) {
|
||||||
|
$message->setTo([$item['address'], $item['address'] => $item['nickname']]);
|
||||||
|
}
|
||||||
|
$mailer->send($messageContent);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user