FastMovieAI 二开基线 v1.0 (完整源码)
This commit is contained in:
@@ -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' => ['项目名称', '客户名称', '提醒时间']
|
||||
]
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user