Files

87 lines
2.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
namespace addon\wxchat\command;
use GatewayWorker\Gateway;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use Workerman\Worker;
use \GatewayWorker\BusinessWorker;
use \GatewayWorker\Register;
// php think wxchat:server -a start
/**
* ChatServer 类
*
* @author ywxapp <admin@ywxapp.cn>
*/
class ChatServer extends Command
{
protected function configure()
{
$this->setName('wxchat:server')->addOption('action', 'a', Option::VALUE_OPTIONAL, '操作')->setDescription('Start wxchat GatewayWorker Server');
}
protected function execute(Input $input, Output $output)
{
// 初始化 GatewayWorker
$this->initGatewayWorker();
Worker::runAll();
}
private function initGatewayWorker()
{
// register 必须是text协议,切记不能将register端口开放给外网
$register = new Register('text://127.0.0.1:1238');
// bussinessWorker 进程
$worker = new BusinessWorker();
// worker名称
$worker->name = 'YourAppBusinessWorker';
// bussinessWorker进程数量
$worker->count = 4;
// 服务注册地址
$worker->registerAddress = '127.0.0.1:1238';
$worker->eventHandler = \addon\wxchat\worker\ChatEvent::class;
$context = [
'ssl' => [
'local_cert' => __DIR__ . '/fullchain.pem', // 也可以是crt文件
'local_pk' => __DIR__ . '/privkey.pem',
'verify_peer' => false,
'allow_self_signed' => true, //如果是自签名证书需要开启此选项
],
];
$gateway = new Gateway("websocket://0.0.0.0:2346", $context);
$gateway->name = 'AppGateway';
$gateway->count = 2;
$gateway->lanIp = '127.0.0.1';
$gateway->startPort = 2900;
$gateway->websocketCompression = false; // ⚠️ 必须关闭!
$gateway->maxPackageSize = 10 * 1024 * 1024; // 10MB(支持大Base64
$gateway->registerAddress = '127.0.0.1:1238';
//$gateway->onWorkerStart
//$gateway->onWorkerStop
//$gateway->onConnect
//$gateway->onMessage
//$gateway->onClose
$gateway->transport = 'ssl';
// 心跳间隔
//$gateway->pingInterval = 0;
// 心跳数据
//$gateway->pingData = '{"type":"ping"}';
}
}