-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathstart.php
More file actions
41 lines (34 loc) · 1.17 KB
/
start.php
File metadata and controls
41 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Service\PayService;
use Workerman\WebServer;
use Workerman\Worker;
$webServer = new WebServer('http://127.0.0.1:8083');
$webServer->addRoot('localhost:8083', __DIR__ . '/../public/');
$webServer->count = 3;
$context = [
'ssl' => [
'local_cert' => '',
'local_pk' => '',
'verify_peer' => false,
],
];
$webSocketServer = new Worker('websocket://0.0.0.0:11942', $context);
$webSocketServer->count = 1;
$webSocketServer->transport = 'ssl';
$webSocketServer->userConnections = [];
$webSocketServer->userQRs = [];
$webSocketServer->onWorkerStart = function () use ($webSocketServer) {
$textWorker = new Worker('Text://127.0.0.1:11900');
$textWorker->onMessage = 'Service\\InnerTextServer::onMessage';
$textWorker->listen();
};
$webSocketServer->onMessage = function ($connection, $message) use ($webSocketServer) {
$arr = explode(',', $message);
if (!isset($connection->userId)) {
$connection->userId = $arr[0];
$webSocketServer->userConnections[$connection->userId] = $connection;
}
(new PayService)->create($connection, $arr[1], $arr[2]);
};
Worker::runAll();