FastMovieAI 二开基线 v1.0 (完整源码)
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\notification\expose\helper;
|
||||
|
||||
use app\expose\enum\State;
|
||||
use app\expose\helper\Config;
|
||||
use plugin\notification\app\model\PluginNotificationMessage;
|
||||
use plugin\notification\app\model\PluginNotificationMessageContent;
|
||||
use plugin\notification\utils\enum\MessageScene;
|
||||
use support\Log;
|
||||
|
||||
class Message
|
||||
{
|
||||
protected $uid = null;
|
||||
protected $channels_uid = null;
|
||||
protected $form_uid = null;
|
||||
protected $form_id = null;
|
||||
protected $scene = null;
|
||||
protected $alias_id = null;
|
||||
protected $extra = [];
|
||||
protected $title = null;
|
||||
protected $effect = 'info';
|
||||
protected $content = null;
|
||||
protected $subtitle = null;
|
||||
public function setChannelsUid(int $channels_uid)
|
||||
{
|
||||
$this->channels_uid = $channels_uid;
|
||||
return $this;
|
||||
}
|
||||
public function setUid(int $uid)
|
||||
{
|
||||
$this->uid = $uid;
|
||||
return $this;
|
||||
}
|
||||
public function setFormUid(int $form_uid)
|
||||
{
|
||||
$this->form_uid = $form_uid;
|
||||
return $this;
|
||||
}
|
||||
public function setFormId(int $form_id)
|
||||
{
|
||||
$this->form_id = $form_id;
|
||||
return $this;
|
||||
}
|
||||
public function setScene(string $scene)
|
||||
{
|
||||
$this->scene = $scene;
|
||||
return $this;
|
||||
}
|
||||
public function setAliasId(int $alias_id)
|
||||
{
|
||||
$this->alias_id = $alias_id;
|
||||
return $this;
|
||||
}
|
||||
public function setExtra(array $extra)
|
||||
{
|
||||
$this->extra = $extra;
|
||||
return $this;
|
||||
}
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
public function setEffect(string $effect)
|
||||
{
|
||||
$this->effect = $effect;
|
||||
return $this;
|
||||
}
|
||||
public function setContent(string $content)
|
||||
{
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
public function setSubtitle(string $subtitle)
|
||||
{
|
||||
$this->subtitle = $subtitle;
|
||||
return $this;
|
||||
}
|
||||
public function save()
|
||||
{
|
||||
$messageId = null;
|
||||
if ($this->uid) {
|
||||
$Message = new PluginNotificationMessage();
|
||||
$Message->channels_uid = $this->channels_uid;
|
||||
$Message->uid = $this->uid;
|
||||
$Message->form_uid = $this->form_uid;
|
||||
$Message->form_id = $this->form_id;
|
||||
$Message->scene = $this->scene;
|
||||
$Message->alias_id = $this->alias_id;
|
||||
$Message->extra = $this->extra;
|
||||
$Message->title = $this->title;
|
||||
$Message->subtitle = $this->subtitle;
|
||||
$Message->effect = $this->effect;
|
||||
$Message->save();
|
||||
$MessageContent = new PluginNotificationMessageContent();
|
||||
$MessageContent->message_id = $Message->id;
|
||||
$MessageContent->content = $this->content;
|
||||
$MessageContent->save();
|
||||
$messageId = $Message->id;
|
||||
}
|
||||
|
||||
$pushConfig = new Config('push', 'notification');
|
||||
if ($pushConfig->state) {
|
||||
try {
|
||||
if ($this->uid) {
|
||||
Push::send(['uid' => $this->uid, 'event' => 'notify','channels_uid' => $this->channels_uid], [
|
||||
'unread' => PluginNotificationMessage::where(['uid' => $this->uid, 'read_state' => State::NO['value'], 'channels_uid' => $this->channels_uid])->count(),
|
||||
'read' => PluginNotificationMessage::where(['uid' => $this->uid, 'read_state' => State::YES['value'], 'channels_uid' => $this->channels_uid])->count(),
|
||||
'list' => [
|
||||
[
|
||||
'id' => $messageId,
|
||||
'scene' => MessageScene::get($this->scene),
|
||||
'title' => $this->title,
|
||||
]
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
Push::trigger('notify', 'message', [
|
||||
'id' => $messageId,
|
||||
'scene' => MessageScene::get($this->scene),
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'extra' => $this->extra,
|
||||
'effect' => $this->effect,
|
||||
'alias_id'=>$this->alias_id,
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('Message save push error: ' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\notification\expose\helper;
|
||||
|
||||
use app\expose\helper\Config;
|
||||
use app\expose\helper\Wechat;
|
||||
use app\expose\utils\Sms;
|
||||
use plugin\notification\utils\enum\Method;
|
||||
use plugin\notification\utils\enum\Scene;
|
||||
use plugin\notification\expose\template\sms\Notice as SmsNotice;
|
||||
use support\Log;
|
||||
|
||||
class Notice
|
||||
{
|
||||
protected $mobiles = [];
|
||||
protected $openids = [];
|
||||
protected $scene = '';
|
||||
protected $data = [];
|
||||
protected $method = '';
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
public function setScene($scene)
|
||||
{
|
||||
$this->scene = $scene;
|
||||
}
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
public function addMobile($mobile)
|
||||
{
|
||||
$this->mobiles[] = $mobile;
|
||||
}
|
||||
public function addOpenid($openid)
|
||||
{
|
||||
$this->openids[] = $openid;
|
||||
}
|
||||
public function builderSms()
|
||||
{
|
||||
$config = new Config('sms_template', 'notification');
|
||||
if (isset($config[$this->scene]) && $config[$this->scene]) {
|
||||
$sms_template = $config[$this->scene];
|
||||
//发送短信
|
||||
switch ($this->scene) {
|
||||
case Scene::TODO['value']:
|
||||
break;
|
||||
case Scene::WARNING['value']:
|
||||
break;
|
||||
}
|
||||
foreach ($this->data as $key => $value) {
|
||||
$sms_template = str_replace('{' . $key . '}', $value, $sms_template);
|
||||
}
|
||||
foreach ($this->mobiles as $mobile) {
|
||||
try {
|
||||
//发送短信
|
||||
$Sms = new Sms;
|
||||
$Sms->mobile = $mobile;
|
||||
$SmsNotice = new SmsNotice;
|
||||
$SmsNotice->setTemplateCode($sms_template);
|
||||
$Sms->setTemplate($SmsNotice);
|
||||
$Sms->setData($this->data);
|
||||
$Sms->send();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error("短信通知失败(手机号:mobile):" . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function builderWechat()
|
||||
{
|
||||
$config = new Config('wechat_template', 'notification');
|
||||
if (isset($config[$this->scene]) && $config[$this->scene]) {
|
||||
$template_id = $config[$this->scene];
|
||||
//发送微信
|
||||
switch ($this->scene) {
|
||||
case Scene::TODO['value']:
|
||||
break;
|
||||
case Scene::WARNING['value']:
|
||||
$data['template_id'] = $template_id;
|
||||
$data['data'] = [];
|
||||
foreach ($this->data as $key => $value) {
|
||||
$data['data'][$key] = ['value' => $value];
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isset($data['template_id'])) {
|
||||
foreach ($this->openids as $openid) {
|
||||
$data['touser'] = $openid;
|
||||
try {
|
||||
Wechat::sendTemplate($data);
|
||||
} catch (\Throwable $th) {
|
||||
Log::error("微信通知失败(openid:{$openid}):" . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function send()
|
||||
{
|
||||
$this->mobiles = array_unique($this->mobiles);
|
||||
$this->openids = array_unique($this->openids);
|
||||
switch ($this->method) {
|
||||
case Method::WECHAT_FIRST:
|
||||
if (!empty($this->openids)) {
|
||||
try {
|
||||
$this->builderWechat();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('微信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$this->builderSms();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('短信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Method::SMS_FIRST:
|
||||
if (!empty($this->mobiles)) {
|
||||
try {
|
||||
$this->builderSms();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('短信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$this->builderWechat();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('微信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Method::WECHAT_ONLY:
|
||||
try {
|
||||
$this->builderWechat();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('微信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
break;
|
||||
case Method::SMS_ONLY:
|
||||
try {
|
||||
$this->builderSms();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('短信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
$this->builderSms();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('短信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
try {
|
||||
$this->builderWechat();
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('微信通知发送失败:' . $th->getMessage(), $th->getTrace());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\notification\expose\helper;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class Online
|
||||
{
|
||||
public static function clear()
|
||||
{
|
||||
// 截断表
|
||||
Db::execute('TRUNCATE TABLE ' . getenv('DATABASE_PREFIX') . 'plugin_notification_online');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\notification\expose\helper;
|
||||
|
||||
use plugin\notification\app\model\PluginNotificationOnline;
|
||||
use plugin\notification\utils\Api;
|
||||
|
||||
class Push
|
||||
{
|
||||
public static function send(array $where = [], mixed $data = [], string $event = 'message'): bool
|
||||
{
|
||||
$PluginNotificationOnline = PluginNotificationOnline::where($where)->column('channel');
|
||||
if (!empty($PluginNotificationOnline)) {
|
||||
return self::trigger($PluginNotificationOnline, $event, $data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static function trigger(string|array $channel, string $event, array $data): bool
|
||||
{
|
||||
$api = new Api(
|
||||
config('plugin.webman.push.app.api'),
|
||||
config('plugin.webman.push.app.app_key'),
|
||||
config('plugin.webman.push.app.app_secret')
|
||||
);
|
||||
return $api->trigger($channel, $event, $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\notification\expose\template\sms;
|
||||
|
||||
use app\expose\template\sms\Basic;
|
||||
|
||||
class Notice extends Basic
|
||||
{
|
||||
public function setTemplateCode($templateCode)
|
||||
{
|
||||
$this->data['templateCode'] = $templateCode;
|
||||
}
|
||||
public function builder()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user