1.优化后台测试推送功能页面

2.优化开奖和实时对局页面
This commit is contained in:
2026-04-18 17:16:13 +08:00
parent 5c07967bf9
commit c184fa8a46
14 changed files with 582 additions and 78 deletions

View File

@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace app\common\service;
use support\think\Db;
use Throwable;
use Webman\Push\Api;
/**
* 用户私有频道推送private-user-{uuid}(与移动端接口设计草案 7.1 一致)
*/
final class UserPushService
{
public const EVT_BET_ACCEPTED = 'bet.accepted';
/** 单注开奖结果(含未中奖 win_amount=0 */
public const EVT_BET_SETTLED = 'bet.settled';
public const EVT_WALLET_CHANGED = 'wallet.changed';
private static function channelName(string $uuid): string
{
return 'private-user-' . $uuid;
}
private static function createApi(): Api
{
return new Api(
str_replace('0.0.0.0', '127.0.0.1', (string) config('plugin.webman.push.app.api')),
(string) config('plugin.webman.push.app.app_key'),
(string) config('plugin.webman.push.app.app_secret')
);
}
public static function uuidForUserId(int $userId): ?string
{
if ($userId <= 0) {
return null;
}
$u = Db::name('user')->where('id', $userId)->value('uuid');
return is_string($u) && $u !== '' ? $u : null;
}
/**
* @param array<string, mixed> $data
*/
public static function publish(int $userId, string $event, array $data): void
{
$uuid = self::uuidForUserId($userId);
if ($uuid === null) {
return;
}
try {
self::createApi()->trigger(self::channelName($uuid), $event, $data);
} catch (Throwable) {
}
}
}