no message

This commit is contained in:
kuaifan 2025-04-23 14:47:09 +08:00
parent 41ab11e7b4
commit 0f0b9c5551
5 changed files with 153 additions and 87 deletions

View File

@ -119,7 +119,7 @@ git pull
``` ```
* Please try again if the upgrade fails across a large version. * Please try again if the upgrade fails across a large version.
* If 502 after the upgrade please run `./cmd restart` restart the service. * If 502 after the upgrade please run `./cmd reup` restart the service.
## Transfer ## Transfer

View File

@ -120,7 +120,7 @@ git pull
``` ```
* 跨越大版本升级失败时请重试执行一次。 * 跨越大版本升级失败时请重试执行一次。
* 如果升级后出现502请运行 `./cmd restart` 重启服务即可。 * 如果升级后出现502请运行 `./cmd reup` 重启服务即可。
## 迁移项目 ## 迁移项目
@ -133,7 +133,7 @@ git pull
./cmd mysql backup ./cmd mysql backup
``` ```
2、将`数据库备份文件``public/uploads`目录拷贝至新项目 2、将 `数据库备份文件` `public/uploads` 目录拷贝至新项目
3、还原数据库至新项目 3、还原数据库至新项目
```bash ```bash

View File

@ -47,6 +47,54 @@ class UmengAlias extends AbstractModel
{ {
protected $table = 'umeng_alias'; protected $table = 'umeng_alias';
private static $waitSend = [];
/**
* 推送消息
* @param $push
* @return void
*/
private static function sendTask($push = null)
{
if ($push) {
self::$waitSend[] = $push;
}
if (!self::$waitSend) {
return;
}
$first = array_shift(self::$waitSend);
if (empty($first)) {
return;
}
try {
switch ($first['platform']) {
case 'ios':
$instance = new IOS($first['config']);
break;
case 'android':
$instance = new Android($first['config']);
break;
default:
return;
}
$instance->send($first['data']);
} catch (\Exception $e) {
$first['retry'] = intval($first['retry'] ?? 0) + 1;
if ($first['retry'] > 3) {
info("[PushMsg] fail: " . $e->getMessage());
} else {
info("[PushMsg] retry ({$first['retry']}): " . $e->getMessage());
self::$waitSend[] = $first;
}
} finally {
self::sendTask();
}
}
/** /**
* 推送内容处理 * 推送内容处理
* @param $string * @param $string
@ -90,13 +138,13 @@ class UmengAlias extends AbstractModel
* @param string $alias * @param string $alias
* @param string $platform * @param string $platform
* @param array $array [title, subtitle, body, description, extra, seconds, badge] * @param array $array [title, subtitle, body, description, extra, seconds, badge]
* @return array|false * @return void
*/ */
public static function pushMsgToAlias($alias, $platform, $array) private static function pushMsgToAlias($alias, $platform, $array)
{ {
$config = self::getPushConfig(); $config = self::getPushConfig();
if ($config === false) { if ($config === false) {
return false; return;
} }
// //
$title = self::specialCharacters($array['title'] ?: ''); // 标题 $title = self::specialCharacters($array['title'] ?: ''); // 标题
@ -110,65 +158,70 @@ class UmengAlias extends AbstractModel
switch ($platform) { switch ($platform) {
case 'ios': case 'ios':
if (!isset($config['iOS'])) { if (!isset($config['iOS'])) {
return false; return;
} }
$ios = new IOS($config); self::sendTask([
return $ios->send([ 'platform' => $platform,
'description' => $description, 'config' => $config,
'payload' => array_merge([ 'data' => [
'aps' => [ 'description' => $description,
'alert' => [ 'payload' => array_merge([
'title' => $title, 'aps' => [
'subtitle' => $subtitle, 'alert' => [
'body' => $body, 'title' => $title,
'subtitle' => $subtitle,
'body' => $body,
],
'sound' => 'default',
'badge' => $badge,
], ],
'sound' => 'default', ], $extra),
'badge' => $badge, 'type' => 'customizedcast',
'alias_type' => 'userid',
'alias' => $alias,
'policy' => [
'expire_time' => Carbon::now()->addSeconds($seconds)->toDateTimeString(),
], ],
], $extra), ]
'type' => 'customizedcast',
'alias_type' => 'userid',
'alias' => $alias,
'policy' => [
'expire_time' => Carbon::now()->addSeconds($seconds)->toDateTimeString(),
],
]); ]);
break;
case 'android': case 'android':
if (!isset($config['Android'])) { if (!isset($config['Android'])) {
return false; return;
} }
$android = new Android($config); self::sendTask([
return $android->send([ 'platform' => $platform,
'description' => $description, 'config' => $config,
'payload' => array_merge([ 'data' => [
'display_type' => 'notification', 'description' => $description,
'body' => [ 'payload' => array_merge([
'ticker' => $title, 'display_type' => 'notification',
'text' => $body, 'body' => [
'title' => $title, 'ticker' => $title,
'after_open' => 'go_app', 'text' => $body,
'play_sound' => true, 'title' => $title,
'after_open' => 'go_app',
'play_sound' => true,
],
], $extra),
'type' => 'customizedcast',
'alias_type' => 'userid',
'alias' => $alias,
'mipush' => true,
'mi_activity' => 'app.eeui.umeng.activity.MfrMessageActivity',
'policy' => [
'expire_time' => Carbon::now()->addSeconds($seconds)->toDateTimeString(),
], ],
], $extra), 'channel_properties' => [
'type' => 'customizedcast', 'vivo_category' => 'IM',
'alias_type' => 'userid', 'huawei_channel_importance' => 'NORMAL',
'alias' => $alias, 'huawei_channel_category' => 'IM',
'mipush' => true, 'channel_fcm' => 0,
'mi_activity' => 'app.eeui.umeng.activity.MfrMessageActivity', ],
'policy' => [ ]
'expire_time' => Carbon::now()->addSeconds($seconds)->toDateTimeString(),
],
'channel_properties' => [
'vivo_category' => 'IM',
'huawei_channel_importance' => 'NORMAL',
'huawei_channel_category' => 'IM',
'channel_fcm' => 0,
],
]); ]);
break;
default:
return false;
} }
} }

View File

@ -457,34 +457,30 @@ class ZincSearchDialogMsg
return false; return false;
} }
// 用户不存在,同步消息 // 用户不存在,同步消息 todo 应该使用异步进程
if (empty($hits)) { if (empty($hits)) {
go(function () use ($dialogUser) { $lastId = 0; // 上次同步的最后ID
Coroutine::sleep(0.1); $batchSize = 500; // 每批处理的消息数量
$lastId = 0; // 上次同步的最后ID // 分批同步消息
$batchSize = 500; // 每批处理的消息数量 do {
// 获取一批
$dialogMsgs = WebSocketDialogMsg::whereDialogId($dialogUser->dialog_id)
->where('id', '>', $lastId)
->orderBy('id')
->limit($batchSize)
->get();
// 分批同步消息 if ($dialogMsgs->isEmpty()) {
do { break;
// 获取一批 }
$dialogMsgs = WebSocketDialogMsg::whereDialogId($dialogUser->dialog_id)
->where('id', '>', $lastId)
->orderBy('id')
->limit($batchSize)
->get();
if ($dialogMsgs->isEmpty()) { // 同步数据
break; ZincSearchDialogMsg::batchSync($dialogMsgs);
}
// 同步数据 // 更新最后ID
ZincSearchDialogMsg::batchSync($dialogMsgs); $lastId = $dialogMsgs->last()->id;
} while (count($dialogMsgs) == $batchSize);
// 更新最后ID
$lastId = $dialogMsgs->last()->id;
} while (count($dialogMsgs) == $batchSize);
});
} }
return true; return true;

35
cmd
View File

@ -525,9 +525,9 @@ if [ $# -gt 0 ]; then
success "卸载完成" success "卸载完成"
elif [[ "$1" == "reinstall" ]]; then elif [[ "$1" == "reinstall" ]]; then
shift 1 shift 1
./cmd uninstall $@ ./cmd uninstall "$@"
sleep 3 sleep 3
./cmd install $@ ./cmd install "$@"
elif [[ "$1" == "port" ]]; then elif [[ "$1" == "port" ]]; then
shift 1 shift 1
env_set APP_PORT "$1" env_set APP_PORT "$1"
@ -557,10 +557,10 @@ if [ $# -gt 0 ]; then
run_compile prod run_compile prod
elif [[ "$1" == "appbuild" ]] || [[ "$1" == "buildapp" ]]; then elif [[ "$1" == "appbuild" ]] || [[ "$1" == "buildapp" ]]; then
shift 1 shift 1
run_electron app $@ run_electron app "$@"
elif [[ "$1" == "electron" ]]; then elif [[ "$1" == "electron" ]]; then
shift 1 shift 1
run_electron $@ run_electron "$@"
elif [[ "$1" == "eeui" ]]; then elif [[ "$1" == "eeui" ]]; then
shift 1 shift 1
cli="$@" cli="$@"
@ -573,9 +573,9 @@ if [ $# -gt 0 ]; then
docker run -it --rm -v ${cur_path}/resources/mobile:/work -w /work ${por} kuaifan/eeui-cli:0.0.1 eeui ${cli} docker run -it --rm -v ${cur_path}/resources/mobile:/work -w /work ${por} kuaifan/eeui-cli:0.0.1 eeui ${cli}
elif [[ "$1" == "npm" ]]; then elif [[ "$1" == "npm" ]]; then
shift 1 shift 1
npm $@ npm "$@"
pushd electron || exit pushd electron || exit
npm $@ npm "$@"
popd || exit popd || exit
docker run --rm -it -v ${cur_path}/resources/mobile:/work -w /work --entrypoint=/bin/bash node:16 -c "npm $@" docker run --rm -it -v ${cur_path}/resources/mobile:/work -w /work --entrypoint=/bin/bash node:16 -c "npm $@"
elif [[ "$1" == "doc" ]]; then elif [[ "$1" == "doc" ]]; then
@ -648,10 +648,27 @@ if [ $# -gt 0 ]; then
shift 1 shift 1
$COMPOSE stop "$@" $COMPOSE stop "$@"
$COMPOSE start "$@" $COMPOSE start "$@"
else elif [[ "$1" == "reup" ]]; then
if [[ "$1" == "down" ]]; then shift 1
run_mysql rm-port run_mysql rm-port
$COMPOSE down --remove-orphans
$COMPOSE up -d --remove-orphans
elif [[ "$1" == "down" ]]; then
shift 1
run_mysql rm-port
if [[ $# -eq 0 ]]; then
$COMPOSE down --remove-orphans
else
$COMPOSE down "$@"
fi fi
elif [[ "$1" == "up" ]]; then
shift 1
if [[ $# -eq 0 ]]; then
$COMPOSE up -d --remove-orphans
else
$COMPOSE up "$@"
fi
else
$COMPOSE "$@" $COMPOSE "$@"
fi fi
else else