diff --git a/app/command/CheckPaymentError.php b/app/command/CheckPaymentError.php index 923823ca..a7a637a2 100644 --- a/app/command/CheckPaymentError.php +++ b/app/command/CheckPaymentError.php @@ -23,6 +23,7 @@ class CheckPaymentError extends Command protected function execute(Input $input, Output $output) { + // 一般付款 // 取得未完付款的訂單 $orders = Db::name('order_info') ->alias('oi') @@ -81,6 +82,9 @@ class CheckPaymentError extends Command } } + // 貨到付款 + + // 指令输出 $output->writeln('檢查支付過期'); } diff --git a/app/ws/include/.gitignore b/app/ws/include/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/app/ws/include/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/app/ws/wsbonus.php b/app/ws/wsbonus.php new file mode 100644 index 00000000..b8e60bf5 --- /dev/null +++ b/app/ws/wsbonus.php @@ -0,0 +1,110 @@ + 'mysql', + // 數據庫連接信息 + 'connections' => [ + 'mysql' => [ + // 數據庫類型 + 'type' => 'mysql', + // 主機地址 + 'hostname' => '127.0.0.1', + // 用户名 + 'username' => 'shop_h888_fun', + 'password' => 'h52DHfyG5rXkXTfJ', + // 數據庫名 + 'database' => 'shop_h888_fun', + // 數據庫編碼默認採用utf8 + 'charset' => 'utf8mb4', + // 數據庫表前綴 + 'prefix' => 'ecs_', + // 數據庫調試模式 + 'debug' => true, + ], + ], +]); + +$redis = new \Redis(); + +$redis->connect('127.0.0.1', 6379); + +// $server = new \Swoole\Websocket\Server('0.0.0.0', 9501); +$server = new \Swoole\Websocket\Server("0.0.0.0", 8443, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL); + +$server->set([ + 'daemonize' => false, //守護進程化。 + //配置SSL證書和密鑰路徑 + 'ssl_cert_file' => "/www/server/panel/vhost/cert/".WS_URL."/fullchain.pem", + 'ssl_key_file' => "/www/server/panel/vhost/cert/".WS_URL."/privkey.pem" +]); + + // 定義路由映射表 +$routes = [ + 'init' => 'app\\ws\\handleInit', + 'use' => 'app\\ws\\handleUse', +]; + +$server->on('start', function ($server) { + echo "Websocket Server is started at ws://0.0.0.0:9501\n"; +}); + +$server->on('open', function ($server, $req) { + echo "connection open: {$req->fd}\n"; +}); + +$server->on('message', function ($server, $frame) use (&$routes) { + echo "received message: {$frame->data}\n"; + // $server->push($frame->fd, json_encode(['hello', 'world'])); + $message = json_decode($frame->data, true); + if (isset($message['action']) && isset($routes[$message['action']])) { + $action = $message['action']; + $payload = $message['payload']; + + $handler = $routes[$action]; + + $handler($server, $frame->fd, $payload); + } else { + // 處理未知路由或錯誤情況 + $server->push($frame->fd, json_encode(['error' => 'Invalid action'])); + } +}); + +$server->on('close', function ($server, $fd) use ($redis){ + $conns = $redis->keys('sn:*'); + + foreach ($conns as $connKey) { + $bonus_sn = str_replace('sn:', '', $connKey); + $redis->sRem($connKey, $fd); + echo "Client #$fd left sn: $bonus_sn \n"; + } +}); + +function handleInit($server, $fd, $payload) +{ + // 將$payload 存入redis + global $redis; + $redis->sAdd('sn:' . $payload, $fd); +} + +function handleUse($server, $fd, $payload) +{ + global $redis; + + // 從 Redis 中獲取該序號所有連接 + $connections = $redis->sMembers('sn:' . $payload); + + // 廣播消息到房間中的所有連接 + foreach ($connections as $fd) { + $server->push($fd, json_encode(['action' => 'use', 'sn' => $payload])); + } +} +$server->start(); diff --git a/public/adm/includes/init.php b/public/adm/includes/init.php index a737bee4..46a736ea 100644 --- a/public/adm/includes/init.php +++ b/public/adm/includes/init.php @@ -347,6 +347,9 @@ header('Expires: Fri, 14 Mar 1980 20:53:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); +header("Access-Control-Allow-Origin: *"); +header("Access-Control-Allow-Methods: *"); +header("Access-Control-Allow-Headers: Origin, Methods, Content-Type"); if ((DEBUG_MODE & 1) == 1) { diff --git a/public/adm/privilege.php b/public/adm/privilege.php index 55849df1..a22e8111 100644 --- a/public/adm/privilege.php +++ b/public/adm/privilege.php @@ -60,18 +60,18 @@ elseif ($_REQUEST['act'] == 'signin') { $_POST = json_decode(file_get_contents("php://input"),true); - if (intval($_CFG['captcha']) & CAPTCHA_ADMIN) - { - include_once(ROOT_PATH . 'includes/cls_captcha.php'); - - /* 檢查驗證碼是否正確 */ - $validator = new captcha(); - if (!empty($_POST['captcha']) && !$validator->check_word($_POST['captcha'])) - { - echo json_encode(['code'=>'501','message'=>'驗證碼錯誤']); - exit; - } - } + // if (intval($_CFG['captcha']) & CAPTCHA_ADMIN) + // { + // include_once(ROOT_PATH . 'includes/cls_captcha.php'); + + // /* 檢查驗證碼是否正確 */ + // $validator = new captcha(); + // if (!empty($_POST['captcha']) && !$validator->check_word($_POST['captcha'])) + // { + // echo json_encode(['code'=>'501','message'=>'驗證碼錯誤']); + // exit; + // } + // } $_POST['username'] = isset($_POST['username']) ? trim($_POST['username']) : ''; $_POST['password'] = isset($_POST['password']) ? trim($_POST['password']) : ''; @@ -160,13 +160,14 @@ elseif ($_REQUEST['act'] == 'signin') // ecs_header("Location: ./index.php\n"); - echo json_encode(['code'=>'200','token'=>$jwt]); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['code'=>200,'token'=>$jwt]); exit; } else { - echo json_encode(['code'=>'502','message'=>'帳號密碼錯誤']); + echo json_encode(['code'=>502,'message'=>'帳號密碼錯誤']); } }