FastMovieAI AI短剧创作平台 二开基线

- 源码: xhadmincn/FastMovieAI (Apache 2.0)
- 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION
- vendor/示例资源已gitignore
This commit is contained in:
李建琦
2026-08-26 18:37:36 +08:00
commit eae151fd57
888 changed files with 105571 additions and 0 deletions
@@ -0,0 +1,57 @@
{
"title": "Notification",
"icon": "Bell",
"path": "/app/notification/admin",
"sort": 8000,
"children": [
{
"title": "Message List",
"icon": "Message",
"path": "/app/notification/admin/Message/index",
"component": "table",
"children": [
{
"title": "Message List",
"path": "/app/notification/admin/Message/index",
"component": "table"
},
{
"title": "Push Test",
"path": "/app/notification/admin/Message/pushTest",
"show": false,
"component": "form"
}
]
},
{
"title": "System Configuration",
"icon": "Setting",
"path": "/app/notification/admin/System",
"children": [
{
"title": "Notification Strategy",
"path": "/app/notification/admin/System/strategy",
"show": false,
"component": "form"
},
{
"title": "Site Push",
"path": "/app/notification/admin/System/push",
"component": "form"
},
{
"title": "WeChat Template",
"path": "/app/notification/admin/System/wechat_template",
"show": false,
"component": "form"
},
{
"title": "SMS Template",
"path": "/app/notification/admin/System/sms_template",
"show": false,
"component": "form"
}
]
}
]
}
@@ -0,0 +1,15 @@
<?php
namespace plugin\notification\api;
use app\expose\api\Install as ApiInstall;
class Install
{
use ApiInstall;
public function __construct()
{
$this->plugin='notification';
$this->path = __DIR__;
}
}
@@ -0,0 +1,35 @@
/*
Navicat Premium Data Transfer
Source Server : Loong
Source Server Type : MySQL
Source Server Version : 80024 (8.0.24)
Source Host : 127.0.0.1:3306
Source Schema : cloud_xhadmin_cn
Target Server Type : MySQL
Target Server Version : 80024 (8.0.24)
File Encoding : 65001
Date: 18/05/2024 18:25:14
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for php_plugin_notification_log
-- ----------------------------
DROP TABLE IF EXISTS `php_plugin_notification_log`;
CREATE TABLE `php_plugin_notification_log` (
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`uid` int NULL DEFAULT NULL,
`admin_uid` int NULL DEFAULT NULL,
`scene` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`num` int NULL DEFAULT NULL,
`create_time` datetime NULL DEFAULT NULL,
`update_time` datetime NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
@@ -0,0 +1,10 @@
<?php
namespace plugin\article\app;
use app\Basic as AppBasic;
class Basic extends AppBasic
{
public $plugin = '/app/article/';
}
@@ -0,0 +1,287 @@
<?php
namespace plugin\notification\app\admin\controller;
use app\Basic;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\State;
use plugin\control\app\model\PluginChannelsUser;
use plugin\notification\app\model\PluginNotificationMessage;
use plugin\notification\expose\helper\Message;
use plugin\notification\utils\enum\MessageScene;
use support\Request;
class MessageController extends Basic
{
public function __construct()
{
$this->model = new PluginNotificationMessage();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder();
$builder->addHeader();
$builder->addHeaderAction('推送测试', [
'model' => Action::DIALOG['value'],
'path' => '/app/notification/admin/Message/pushTest',
'props' => [
'title' => '推送测试'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$channelList = PluginChannelsUser::options();
$formBuilder = new FormBuilder(null, null, [
'inline' => true
]);
$formBuilder->add('channels_uid', '渠道', 'select', '', [
'options' => $channelList,
'props' => [
'placeholder' => '渠道搜索',
'clearable' => true
]
]);
$formBuilder->add('uid', 'UID', 'input', '', [
'props' => [
'placeholder' => 'UID搜索',
]
]);
$formBuilder->add('scene', '场景', 'select', '', [
'options' => MessageScene::getOptions(),
'props' => [
'placeholder' => '场景搜索',
'clearable' => true
]
]);
$formBuilder->add('state', '状态', 'select', '', [
'options' => State::getOptions(),
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
// $builder->addAction('操作', [
// 'width' => '200px',
// 'fixed' => 'right'
// ]);
$builder->add('id', 'ID', [
'props' => [
'width' => '100px'
]
]);
$builder->add('channels', '渠道', [
'where' => [
['channels_uid', '!=', null]
],
'component' => [
'name' => 'table-userinfo',
'props' => [
'nickname' => 'channels.nickname',
'avatar' => 'channels.headimg',
'info' => 'channels.mobile',
'tags' => [
[
'field' => 'channels_uid',
'props' => [
'type' => 'success',
'size' => 'small'
]
]
],
]
],
'props' => [
'width' => '300px'
]
]);
$builder->add('user', '用户', [
'where' => [
['uid', '!=', null]
],
'component' => [
'name' => 'table-userinfo',
'props' => [
'nickname' => 'user.nickname',
'avatar' => 'user.headimg',
'info' => 'user.mobile',
'tags' => [
[
'field' => 'uid',
'props' => [
'type' => 'success',
'size' => 'small'
]
]
],
]
],
'props' => [
'width' => '300px'
]
]);
$builder->add('title', '标题', [
'props' => [
'width' => '200px'
]
]);
$builder->add('scene', '场景', [
'component' => [
'name' => 'tag',
'options' => MessageScene::getOptions()
],
'props' => [
'width' => '120px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => '/app/notification/admin/Message/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '120px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$channels_uid = $request->get('channels_uid');
if ($channels_uid) {
$where[] = ['channels_uid', '=', $channels_uid];
}
$title = $request->get('title');
if ($title) {
$where[] = ['title', 'like', "%{$title}%"];
}
$scene = $request->get('scene');
if ($scene) {
$where[] = ['scene', '=', $scene];
}
$state = $request->get('state');
if ($state) {
$where[] = ['state', '=', $state];
}
$uid = $request->get('uid');
if ($uid) {
$where[] = ['uid', '=', $uid];
}
$list = PluginNotificationMessage::with(['user' => function ($query) {
$query->field('id,nickname,headimg,mobile,channels_uid');
}, 'channels' => function ($query) {
$query->field('id,nickname,headimg,mobile');
}])
->where($where)
->order('id desc')
->paginate($limit);
return $this->resData($list);
}
public function pushTest(Request $request)
{
if ($request->method() === 'POST') {
$D = $request->post();
$Message = new Message();
if ($D['channels_uid']) {
$Message->setChannelsUid($D['channels_uid']);
}
if ($D['uid']) {
$Message->setUid($D['uid']);
}
if ($D['scene']) {
$Message->setScene($D['scene']);
}
if ($D['title']) {
$Message->setTitle($D['title']);
}
if ($D['content']) {
$Message->setContent($D['content']);
}
$Message->save();
return $this->success('推送成功');
}
$formBuilder = new FormBuilder(null, null, [
'labelPosition' => 'right',
'label-width' => "200px",
'class' => 'w-80 mx-auto',
'size' => 'large'
]);
$channelList = PluginChannelsUser::options();
$formBuilder->add('channels_uid', '渠道', 'select', '', [
'options' => $channelList,
'props' => [
'placeholder' => '渠道',
'clearable' => true
]
]);
$formBuilder->add('uid', 'UID', 'input', '', [
'props' => [
'placeholder' => '推送指定UID',
'clearable' => true
]
]);
$formBuilder->add('state', '状态', 'switch', State::YES['value'], [
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
]);
$formBuilder->add('scene', '场景', 'select', '', [
'required' => true,
'options' => MessageScene::getOptions()
]);
$formBuilder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'placeholder' => '标题'
]
]);
$formBuilder->add('content', '内容', 'input', '', [
'required' => true,
'props' => [
'type' => 'textarea',
'autosize' => [
'minRows' => 4,
'maxRows' => 20
],
'placeholder' => '内容'
]
]);
return $this->resData($formBuilder);
}
}
@@ -0,0 +1,28 @@
<?php
namespace plugin\notification\app\admin\controller;
use app\Basic;
use app\expose\trait\Config;
use support\Request;
class SystemController extends Basic
{
use Config;
public function strategy(Request $request)
{
return $this->builder();
}
public function push(Request $request)
{
return $this->builder();
}
public function wechat_template(Request $request)
{
return $this->builder();
}
public function sms_template(Request $request)
{
return $this->builder();
}
}
@@ -0,0 +1,31 @@
<?php
namespace plugin\notification\app\admin\controller;
use app\Basic;
use app\expose\helper\Wechat;
use GuzzleHttp\Client;
use support\Request;
class WechatTemplateController extends Basic
{
public function getTemplateId(Request $request)
{
$field=$request->post('field');
$access_token = Wechat::getAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=" . $access_token;
$params = [
'template_id_short' => $request->post('template_id_short'),
'keyword_name_list' => $request->post('keywords'),
];
$client = new Client([
'content_type' => 'application/json',
]);
$response = $client->post($url, ['body' => json_encode($params, JSON_UNESCAPED_UNICODE)]);
$data = json_decode($response->getBody()->getContents(), true);
if (empty($data['template_id'])) {
throw new \Exception("[{$data['errcode']}]" . $data['errmsg']);
}
return $this->success('获取成功',[$field=>$data['template_id']]);
}
}
@@ -0,0 +1,71 @@
<?php
namespace plugin\notification\app\api\controller;
use app\Basic;
use app\expose\enum\State;
use plugin\developer\utils\enum\InviteState;
use plugin\notification\app\model\PluginNotificationMessage;
use plugin\notification\utils\enum\MessageScene;
use support\Request;
class MessageController extends Basic
{
public function index(Request $request)
{
return $this->resData([
'unread' => PluginNotificationMessage::where(['uid' => $request->uid, 'read_state' => State::NO['value']])->count(),
'read' => PluginNotificationMessage::where(['uid' => $request->uid, 'read_state' => State::YES['value']])->count(),
]);
}
public function list(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$title = $request->get('title');
if ($title) {
$where[] = ['title', 'like', "%{$title}%"];
}
$read=$request->get('read', 'all');
if($read !== 'all'){
$where[] = ['read_state', '=', $read == 'read' ? State::YES['value'] : State::NO['value']];
}
$where[] = ['uid', '=', $request->uid];
$model = PluginNotificationMessage::where($where);
$list = $model->order('id desc')->paginate($limit)->each(function ($item) {
if($item->effect=='danger'){
$item->effect = 'error';
}
$item->scene_enum = MessageScene::get($item->scene);
// switch($item->scene){
// case MessageScene::INVITE_JOIN_TEAM['value']:
// $item->state_enum = InviteState::get($item->state);
// break;
// default:
// $item->state_enum = State::get($item->state);
// if($item->state==State::YES['value']){
// $item->effect = 'info';
// }
// break;
// }
});
return $this->resData($list);
}
/**
* 详情
* @author:1950781041@qq.com
* @Date:2026-01-22
*/
public function detail(Request $request)
{
$id = $request->get('id');
$message = PluginNotificationMessage::with('content')->where(['id' => $id])->find();
$message->read_state=1;
$message->save();
if($message){
return $this->resData($message);
}
return $this->fail('消息不存在');
}
}
@@ -0,0 +1,60 @@
<?php
namespace plugin\notification\app\api\controller;
use app\Basic;
use app\expose\enum\State;
use plugin\finance\app\model\PluginFinanceOrders;
use plugin\notification\utils\Api;
use plugin\shortplay\app\model\PluginShortplayDrama;
use plugin\user\app\model\PluginUser;
use plugin\notification\utils\enum\AuthType;
use support\Request;
class PushController extends Basic
{
public function auth(Request $request)
{
$pusher = new Api(str_replace('0.0.0.0', '127.0.0.1', config('plugin.webman.push.app.api')), config('plugin.webman.push.app.app_key'), config('plugin.webman.push.app.app_secret'));
$channel_name = $request->post('channel_name');
$authType = AuthType::getValues();
$match = preg_match('/^private-(' . implode('|', $authType) . ')-(.+)$/', $channel_name, $matches);
if (!$match) {
return $this->fail('Forbidden');
}
$header = $matches[1];
$AuthTypeAction = AuthType::get($header);
$hash = $matches[2];
$has_authority = false;
switch ($AuthTypeAction['action']) {
case 'user':
$uid = PluginUser::getUidByUser($hash);
if ($uid != $request->uid) {
return $this->fail('Forbidden');
}
$PluginUser = PluginUser::where('id', $request->uid)->find();
$has_authority = $PluginUser && $PluginUser->state == State::YES['value'];
break;
case 'orders':
$PluginFinanceOrders = PluginFinanceOrders::where('trade_no', $hash)->find();
if (!$PluginFinanceOrders) {
return $this->fail('Forbidden');
}
$has_authority = $PluginFinanceOrders->uid == $request->uid;
break;
case 'drama':
$PluginShortplayDrama = PluginShortplayDrama::where(['id' => $hash, 'uid' => $request->uid])->find();
if (!$PluginShortplayDrama) {
return $this->fail('Forbidden');
}
$has_authority = true;
break;
}
if ($has_authority) {
return $this->resData(json_decode($pusher->socketAuth($channel_name, $request->post('socket_id')), true));
} else {
return $this->fail('Forbidden');
}
}
}
@@ -0,0 +1,101 @@
<?php
namespace plugin\notification\app\controller;
use app\Basic;
use plugin\finance\app\model\PluginFinanceOrders;
use plugin\notification\app\model\PluginNotificationOnline;
use plugin\notification\utils\enum\AuthType;
use plugin\shortplay\app\model\PluginShortplayDrama;
use plugin\user\app\model\PluginUser;
use support\Request;
class PushController extends Basic
{
public function hook(Request $request)
{
// 没有x-pusher-signature头视为伪造请求
if (!$webhook_signature = $request->header('x-pusher-signature')) {
return response('401 Not authenticated', 401);
}
$body = $request->rawBody();
// 计算签名,$app_secret 是双方使用的密钥,是保密的,外部无从得知
$expected_signature = hash_hmac('sha256', $body, config('plugin.webman.push.app.app_secret'), false);
// 安全校验,如果签名不一致可能是伪造的请求,返回401状态码
if ($webhook_signature !== $expected_signature) {
return response('401 Not authenticated', 401);
}
// 这里存储这上线 下线的channel数据
$payload = json_decode($body, true);
$channels_online = $channels_offline = [];
foreach ($payload['events'] as $event) {
if ($event['name'] === 'channel_added') {
$channels_online[] = $event['channel'];
} else if ($event['name'] === 'channel_removed') {
$channels_offline[] = $event['channel'];
}
}
// 业务根据需要处理上下线的channel,例如将在线状态写入数据库,通知其它channel等
// 上线的所有channel
// echo 'online channels: ' . implode(',', $channels_online) . "\n";
foreach ($channels_online as $channel) {
$PluginNotificationOnline = PluginNotificationOnline::where(['channel' => $channel])->find();
if ($PluginNotificationOnline) {
continue;
}
$authType = AuthType::getValues();
$match = preg_match('/^private-(' . implode('|', $authType) . ')-(.+)$/', $channel, $matches);
if (!$match) {
continue;
}
$header = $matches[1];
$hash = $matches[2];
$PluginNotificationOnline = new PluginNotificationOnline();
$PluginNotificationOnline->channel = $channel;
$PluginNotificationOnline->event = $header;
$PluginNotificationOnline->hash = $hash;
$AuthTypeAction = AuthType::get($header);
switch ($AuthTypeAction['action']) {
case 'user':
$PluginNotificationOnline->uid = PluginUser::getUidByUser($hash);
$PluginUser = PluginUser::where('id', $PluginNotificationOnline->uid)->find();
$PluginNotificationOnline->channels_uid = $PluginUser->channels_uid;
break;
case 'orders':
$PluginFinanceOrders = PluginFinanceOrders::where('trade_no', $hash)->find();
if (!$PluginFinanceOrders) {
break;
}
$PluginNotificationOnline->uid = $PluginFinanceOrders->uid;
$PluginNotificationOnline->channels_uid = $PluginFinanceOrders->channels_uid;
break;
case 'drama':
$PluginShortplayDrama = PluginShortplayDrama::where(['id' => $hash])->find();
if (!$PluginShortplayDrama) {
break;
}
$PluginNotificationOnline->uid = $PluginShortplayDrama->uid;
$PluginNotificationOnline->channels_uid = $PluginShortplayDrama->channels_uid;
break;
}
$PluginNotificationOnline->save();
}
// 下线的所有channel
// echo 'offline channels: ' . implode(',', $channels_offline) . "\n";
foreach ($channels_offline as $channel) {
$PluginNotificationOnline = PluginNotificationOnline::where(['channel' => $channel])->find();
if (!$PluginNotificationOnline) {
continue;
}
$PluginNotificationOnline->delete();
}
return 'OK';
}
}
@@ -0,0 +1,6 @@
<?php
/**
* Here is your custom functions.
*/
@@ -0,0 +1,32 @@
<?php
namespace plugin\notification\app\model;
use app\model\Basic;
use plugin\control\app\model\PluginChannelsUser;
use plugin\user\app\model\PluginUser;
class PluginNotificationMessage extends Basic
{
protected function getOptions(): array
{
return [
'type' => [
'extra' => 'json'
],
];
}
public function user()
{
return $this->hasOne(PluginUser::class, 'id', 'uid');
}
public function channels()
{
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
}
public function content()
{
return $this->hasOne(PluginNotificationMessageContent::class, 'message_id', 'id');
}
}
@@ -0,0 +1,11 @@
<?php
namespace plugin\notification\app\model;
use app\model\Basic;
use plugin\user\app\model\PluginUser;
class PluginNotificationMessageContent extends Basic
{
}
@@ -0,0 +1,8 @@
<?php
namespace plugin\notification\app\model;
use app\model\Basic;
class PluginNotificationOnline extends Basic {}
@@ -0,0 +1,9 @@
<?php
use support\Request;
return [
'debug' => true,
'controller_suffix' => 'Controller',
'controller_reuse' => false
];
@@ -0,0 +1,6 @@
<?php
return [
'files' => [
base_path() . '/plugin/notification/app/functions.php',
]
];
@@ -0,0 +1,2 @@
<?php
return new Webman\Container;
@@ -0,0 +1,5 @@
<?php
return [
];
@@ -0,0 +1,5 @@
<?php
return [
'' => app\exception\Handler::class,
];
@@ -0,0 +1,15 @@
<?php
return [
'' => [
app\expose\middleware\Platform::class
],
'admin' => [
app\expose\middleware\AdminAuth::class
],
'api' => [
plugin\control\expose\middleware\DomainMapping::class,
plugin\user\expose\middleware\UserAuth::class,
plugin\user\expose\middleware\Twofa::class,
],
];
@@ -0,0 +1,5 @@
<?php
return [
];
@@ -0,0 +1,43 @@
<?php
use app\expose\build\builder\ComponentBuilder;
$Component = new ComponentBuilder;
return [
[
'title' => '开关',
'field' => 'state',
'value' => false,
'component' => 'switch',
'extra' => [
'required' => true,
'prompt' => [
$Component->add('text', ['default' => '是否开启站内推送'], ['type' => 'info', 'size' => 'small'])
->builder()
],
'props' => []
]
],
[
'title' => 'wss地址',
'field' => 'wss_url',
'value' => 'wss://{HOST}',
'component' => 'input',
'extra' => [
'required' => true,
'where' => [
['state', '=', true]
],
'col'=>[
'span'=>12
],
'prompt' => [
$Component->add('text', ['default' => '只需要填写wss://+域名,不需要填写路径'], ['type' => 'info', 'size' => 'small'])
->builder()
],
'props' => [
'placeholder' => 'wss://+域名'
]
]
],
];
@@ -0,0 +1,24 @@
<?php
use app\expose\build\builder\ComponentBuilder;
use plugin\notification\utils\enum\Scene;
$data=[];
$Component = new ComponentBuilder;
$options=Scene::getOptions();
foreach ($options as $key => $value) {
$temp=[
'title' => $value['label'].'模板或模板ID',
'field' => $value['value'],
'value' => '',
'component' => 'input',
'extra' => [
'prompt' => [
$Component->add('text', ['default' => $value['label'].'场景使用的短信推送模板或模板ID,为空则关闭该场景通知'], ['type' => 'info', 'size' => 'small'])
->builder()
]
]
];
$data[]=$temp;
}
return $data;
@@ -0,0 +1,94 @@
<?php
use app\expose\build\builder\ComponentBuilder;
use plugin\notification\utils\enum\Method;
$Component = new ComponentBuilder;
return [
[
'title' => '开关',
'field' => 'state',
'value' => false,
'component' => 'switch',
'extra' => [
'required' => true,
'prompt' => [
$Component->add('text', ['default' => '是否开启通知'], ['type' => 'info', 'size' => 'small'])
->builder()
],
'props' => []
]
],
[
'title' => '同一用户每日通知次数',
'field' => 'user_limit',
'value' => 0,
'component' => 'input-number',
'extra' => [
'required' => true,
'where' => [
['state', '=', true]
],
'col'=>[
'xs' => 24,
'sm' => 12,
'md' => 6
],
'prompt' => [
$Component->add('text', ['default' => '同一用户所有场景每日通知次数,0:不限制'], ['type' => 'info', 'size' => 'small'])
->builder()
],
'props' => [
'min' => 0,
'controls'=>false,
'placeholder' => '次数'
]
]
],
[
'title' => '同一用户同一场景每日通知次数',
'field' => 'user_scene_limit',
'value' => 1,
'component' => 'input-number',
'extra' => [
'required' => true,
'where' => [
['state', '=', true]
],
'col'=>[
'xs' => 24,
'sm' => 12,
'md' => 6
],
'prompt' => [
$Component->add('text', ['default' => '同一用户同一场景每日通知次数,0:不限制'], ['type' => 'info', 'size' => 'small'])
->builder()
],
'props' => [
'min' => 0,
'controls'=>false,
'placeholder' => '次数'
]
]
],
[
'title' => '通知方式',
'field' => 'method',
'value' => Method::WECHAT_AND_SMS['value'],
'component' => 'radio',
'extra' => [
'required' => true,
'where' => [
['state', '=', true]
],
'prompt' => [
$Component->add('text', ['default' => '通知方式'], ['type' => 'info', 'size' => 'small'])
->builder()
],
'options'=>Method::getOptions(),
'subProps' => [
'border'=>true
]
]
]
];
@@ -0,0 +1,50 @@
<?php
use app\expose\build\builder\ComponentBuilder;
use app\expose\enum\Action;
use plugin\notification\utils\enum\Scene;
$data=[];
$Component = new ComponentBuilder;
$options=Scene::getOptions();
foreach ($options as $key => $value) {
$temp=[
'title' => $value['label'].'模板ID',
'field' => $value['value'],
'value' => '',
'component' => 'input',
'extra' => [
'prompt' => [
$Component->add('text', ['default' => $value['label'].'场景使用的微信公众号推送模板ID,为空则关闭该场景通知'], ['type' => 'info', 'size' => 'small'])
->builder()
],
'props' => [],
'children'=>[
'append'=>[
'component'=>'el-button',
'extra'=>[
'model'=>Action::COMFIRM['value'],
'path'=>'/app/notification/admin/WechatTemplate/getTemplateId',
'props'=>[
'type'=>'warning',
'message'=>'点击确定立即获取模板ID',
]
],
'children'=>[
'default'=>'一键获取模板ID'
]
]
]
]
];
if(isset($value['params'])){
foreach ($value['params'] as $k => $v) {
if(!isset($temp['extra']['children']['append']['extra']['params'])){
$temp['extra']['children']['append']['extra']['params']=[];
}
$temp['extra']['children']['append']['extra']['params'][$k]=$v;
}
}
$data[]=$temp;
}
return $data;
@@ -0,0 +1,6 @@
<?php
return [
'enable' => true,
'middleware' => [
],
];
@@ -0,0 +1,25 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Multilingual configuration
*/
return [
// Default language
'locale' => 'zh_CN',
// Fallback language
'fallback_locale' => ['zh_CN', 'en'],
// Folder where language files are stored
'path' => base_path() . '/plugin/notification/resource/translations',
];
@@ -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()
{
}
}
@@ -0,0 +1,12 @@
{
"name": "notification",
"title": "通知系统",
"version": "0.0.1",
"description": "通知系统",
"author": {
"name": "余心",
"email": "unknown.renloong@gmail.com"
},
"plugin":{
}
}
@@ -0,0 +1,10 @@
<?php
return [
'Notification' => 'Notification',
'System Configuration' => 'System Configuration',
'Notification Strategy' => 'Notification Strategy',
'Site Push' => 'Site Push',
'WeChat Template' => 'WeChat Template',
'SMS Template' => 'SMS Template',
];
@@ -0,0 +1,7 @@
<?php
return [
'Forbidden'=>'Forbidden',
'success' => 'Success',
'fail' => 'Fail',
];
@@ -0,0 +1,5 @@
<?php
return [
'success' => 'Success',
];
@@ -0,0 +1,10 @@
<?php
return [
'Notification' => '通知',
'System Configuration' => '系统配置',
'Notification Strategy' => '通知策略',
'Site Push' => '站内推送',
'WeChat Template' => '微信公众号模板',
'SMS Template' => '短信模板',
];
@@ -0,0 +1,7 @@
<?php
return [
'Forbidden'=>'无权限',
'success' => '成功',
'fail' => '失败',
];
@@ -0,0 +1,5 @@
<?php
return [
'success' => '成功',
];
@@ -0,0 +1,237 @@
<?php
namespace plugin\notification\utils;
/**
* Modified from https://github.com/pusher/pusher-http-php
*/
class Api
{
/**
* @var array
*/
protected $_settings = [
'timeout' => 2,
];
/**
* @param $api_address
* @param $auth_key
* @param $secret
* @throws PushException
*/
public function __construct($api_address, $auth_key, $secret)
{
$this->checkCompatibility();
$this->_settings['api_address'] = $api_address;
$this->_settings['auth_key'] = $auth_key;
$this->_settings['secret'] = $secret;
$this->_settings['base_path'] = '/apps/1024';
}
/**
* trigger an event by providing event name and payload.
* Optionally provide a socket ID to exclude a client (most likely the sender).
*
* @param array|string $channels An array of channel names to publish the event on.
* @param string $event
* @param mixed $data Event data
* @param string $socket_id [optional]
* @return bool|string
*/
public function trigger($channels, $event, $data, $socket_id = null)
{
if (is_string($channels)) {
$channels = array($channels);
}
$query_params = array();
$s_url = $this->_settings['base_path'] . '/events';
$data_encoded = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$post_params = array();
$post_params['name'] = $event;
$post_params['data'] = $data_encoded;
$post_params['channels'] = $channels;
if ($socket_id !== null) {
$post_params['socket_id'] = $socket_id;
}
$post_value = json_encode($post_params);
$query_params['body_md5'] = md5($post_value);
$ch = $this->createCurl($this->_settings['api_address'], $s_url, 'POST', $query_params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_value);
$response = $this->execCurl($ch);
if ($response['status'] === 200) {
return true;
} else {
return false;
}
}
public function getChannelInfo($channel, $params = array())
{
$this->validateChannel($channel);
$response = $this->get('/channels/' . $channel, $params);
if ($response['status'] === 200) {
$response = json_decode($response['body']);
} else {
$response = false;
}
return $response;
}
public function getChannels($params = array())
{
return $this->get('/channels', $params);
}
private function checkCompatibility()
{
if (!in_array('sha256', hash_algos())) {
throw new PushException('SHA256 appears to be unsupported - make sure you have support for it, or upgrade your version of PHP.');
}
}
private function validateChannel($channel)
{
if (!preg_match('/\A[-a-zA-Z0-9_=@,.;]+\z/', $channel)) {
throw new PushException('Invalid channel name ' . $channel);
}
}
private function validateSocketId($socket_id)
{
if ($socket_id !== null && !preg_match('/\A\d+\.\d+\z/', $socket_id)) {
throw new PushException('Invalid socket ID ' . $socket_id);
}
}
private function createCurl($domain, $s_url, $request_method = 'GET', $query_params = array())
{
static $ch = null;
$signed_query = self::buildAuthQueryString(
$this->_settings['auth_key'],
$this->_settings['secret'],
$request_method,
$s_url,
$query_params);
$full_url = $domain . $s_url . '?' . $signed_query;
if (null === $ch) {
$ch = curl_init();
if ($ch === false) {
throw new PushException('Could not initialise cURL!');
}
}
if (function_exists('curl_reset')) {
curl_reset($ch);
}
curl_setopt($ch, CURLOPT_URL, $full_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Expect:',
));
curl_setopt($ch, CURLOPT_PROXY, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->_settings['timeout']);
if ($request_method === 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
} elseif ($request_method === 'GET') {
curl_setopt($ch, CURLOPT_POST, 0);
} // Otherwise let the user configure it
return $ch;
}
private function execCurl($ch)
{
$response = array();
$response['body'] = curl_exec($ch);
$response['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $response;
}
public static function buildAuthQueryString($auth_key, $auth_secret, $request_method, $request_path,
$query_params = array())
{
$params = array();
$params['auth_key'] = $auth_key;
$params['auth_timestamp'] = time();
$params = array_merge($params, $query_params);
ksort($params);
$string_to_sign = "$request_method\n" . $request_path . "\n" . self::arrayImplode('=', '&', $params);
$auth_signature = hash_hmac('sha256', $string_to_sign, $auth_secret, false);
$params['auth_signature'] = $auth_signature;
ksort($params);
$auth_query_string = self::arrayImplode('=', '&', $params);
return $auth_query_string;
}
public static function arrayImplode($glue, $separator, $array)
{
if (!is_array($array)) {
return $array;
}
$string = array();
foreach ($array as $key => $val) {
if (is_array($val)) {
$val = implode(',', $val);
}
$string[] = "{$key}{$glue}{$val}";
}
return implode($separator, $string);
}
public function get($path, $params = array())
{
$ch = $this->createCurl($this->_settings['api_address'], $this->_settings['base_path'] . $path, 'GET', $params);
$response = $this->execCurl($ch);
if ($response['status'] === 200) {
$response['result'] = json_decode($response['body'], true);
}
return $response;
}
public function socketAuth($channel, $socket_id, $custom_data = null)
{
$this->validateChannel($channel);
$this->validateSocketId($socket_id);
if ($custom_data) {
$signature = hash_hmac('sha256', $socket_id . ':' . $channel . ':' . $custom_data, $this->_settings['secret'], false);
} else {
$signature = hash_hmac('sha256', $socket_id . ':' . $channel, $this->_settings['secret'], false);
}
$signature = array('auth' => $this->_settings['auth_key'] . ':' . $signature);
if ($custom_data) {
$signature['channel_data'] = $custom_data;
}
return json_encode($signature);
}
public function presenceAuth($channel, $socket_id, $user_id, $user_info = null)
{
$user_data = array('user_id' => $user_id);
if ($user_info) {
$user_data['user_info'] = $user_info;
}
return $this->socketAuth($channel, $socket_id, json_encode($user_data));
}
}
@@ -0,0 +1,7 @@
<?php
namespace plugin\notification\utils;
class PushException extends \Exception
{
}
@@ -0,0 +1,100 @@
<?php
namespace plugin\notification\utils\enum;
use app\expose\enum\builder\Enum;
class AuthType extends Enum
{
// notify|orders|continueepisode|generatescenestoryboard|generatesceneimage|generatedramacover|generateactorimage|generateactorthreeviewimage|generatestoryboardimage|generatestoryboard|generatecharacterlookcostume
const USER = [
'label' => '用户',
'value' => 'user',
'action' => 'user',
];
const WALLET = [
'label' => '钱包',
'value' => 'wallet',
'action' => 'user',
];
const NOTIFY = [
'label' => '通知',
'value' => 'notify',
'action' => 'user',
];
const ORDERS = [
'label' => '订单',
'value' => 'orders',
'action' => 'orders',
];
const CONTINUE_EPISODE = [
'label' => '续写分集',
'value' => 'continueepisode',
'action' => 'drama',
];
const GENERATE_SCENE_STORYBOARD = [
'label' => '创作分镜',
'value' => 'generatescenestoryboard',
'action' => 'drama',
];
const GENERATE_DRAMA_COVER = [
'label' => '创作短剧封面',
'value' => 'generatedramacover',
'action' => 'drama',
];
const GENERATE_SCENE_IMAGE = [
'label' => '创作场景',
'value' => 'generatesceneimage',
'action' => 'user',
];
const GENERATE_ACTOR_IMAGE = [
'label' => '创作角色形象',
'value' => 'generateactorimage',
'action' => 'user',
];
const GENERATE_ACTOR_THREE_VIEW_IMAGE = [
'label' => '创作角色三视图',
'value' => 'generateactorthreeviewimage',
'action' => 'user',
];
const GENERATE_STORYBOARD_IMAGE = [
'label' => '创作分镜图片',
'value' => 'generatestoryboardimage',
'action' => 'user',
];
const GENERATE_STORYBOARD = [
'label' => '创作分镜',
'value' => 'generatestoryboard',
'action' => 'user',
];
const GENERATE_CHARACTER_LOOK_COSTUME = [
'label' => '创作角色服饰',
'value' => 'generatecharacterlookcostume',
'action' => 'user',
];
const GENERATE_PROP_IMAGE = [
'label' => '创作物品图片',
'value' => 'generatepropimage',
'action' => 'user',
];
const GENERATE_PROP_THREE_VIEW_IMAGE = [
'label' => '创作物品三视图',
'value' => 'generatepropthreeviewimage',
'action' => 'user',
];
const CREATE_DRAMA = [
'label' => '创建短剧',
'value' => 'generatecreatedrama',
'action' => 'user',
];
const CLONE_VOICE = [
'label' => '克隆音色',
'value' => 'clonevoice',
'action' => 'user',
];
const DOWNLOAD_PACKAGE = [
'label' => '打包ZIP包',
'value' => 'downloadpackage',
'action' => 'user',
];
}
@@ -0,0 +1,13 @@
<?php
namespace plugin\notification\utils\enum;
use app\expose\enum\builder\Enum;
class MessageScene extends Enum
{
const ANNOUNCEMENT = [
'label' => '公告',
'value' => 'announcement'
];
}
@@ -0,0 +1,30 @@
<?php
namespace plugin\notification\utils\enum;
use app\expose\enum\builder\Enum;
class Method extends Enum
{
const WECHAT_AND_SMS = [
'label' => '微信+短信',
'value' => 'wechat_and_sms'
];
const WECHAT_FIRST = [
'label' => '微信优先',
'value' => 'wechat_first'
];
const SMS_FIRST = [
'label' => '短信优先',
'value' => 'sms_first'
];
const WECHAT_ONLY = [
'label' => '仅微信',
'value' => 'wechat_only'
];
const SMS_ONLY = [
'label' => '仅短信',
'value' => 'sms_only'
];
}
@@ -0,0 +1,34 @@
<?php
namespace plugin\notification\utils\enum;
use app\expose\enum\builder\Enum;
class Scene extends Enum
{
const TODO = [
'label' => '待办通知',
'value' => 'todo',
'sms_template' => [
'admin' => '您有新的待办事项,请登录控制台查看。',
'user' => '您有新的待办事项,请登录控制台查看。'
],
'params' => [
'template_id_short' => '52305',
'keywords' => ['项目名称', '客户名称', '提醒时间']
]
];
const WARNING = [
'label' => '预警通知',
'value' => 'warning',
'sms_template' => [
'admin' => '您有新的待办事项,请登录控制台查看。',
'user' => '您有新的待办事项,请登录控制台查看。'
],
'params' => [
'template_id_short' => '52305',
'keywords' => ['项目名称', '客户名称', '提醒时间']
]
];
}