Merge commit '96106498d8c480c3ea7ec493bfb063450e11b7b5' into pro

This commit is contained in:
kuaifan 2025-11-03 08:00:22 +08:00
commit 720438fd91
5 changed files with 88 additions and 2 deletions

View File

@ -258,6 +258,7 @@ class IndexController extends InvokeController
Task::deliver(new DeleteTmpTask('file')); Task::deliver(new DeleteTmpTask('file'));
Task::deliver(new DeleteTmpTask('tmp_file', 24)); Task::deliver(new DeleteTmpTask('tmp_file', 24));
Task::deliver(new DeleteTmpTask('user_device', 24)); Task::deliver(new DeleteTmpTask('user_device', 24));
Task::deliver(new DeleteTmpTask('umeng_log', 24 * 3));
// 删除机器人消息 // 删除机器人消息
Task::deliver(new DeleteBotMsgTask()); Task::deliver(new DeleteBotMsgTask());
// 周期任务 // 周期任务

View File

@ -70,6 +70,9 @@ class UmengAlias extends AbstractModel
return; return;
} }
$instance = null;
$responsePayload = null;
try { try {
switch ($first['platform']) { switch ($first['platform']) {
case 'ios': case 'ios':
@ -81,8 +84,11 @@ class UmengAlias extends AbstractModel
default: default:
return; return;
} }
$instance->send($first['data']); $responsePayload = $instance->send($first['data']);
} catch (\Exception $e) { } catch (\Exception $e) {
$responsePayload = [
'error' => $e->getMessage(),
];
$first['retry'] = intval($first['retry'] ?? 0) + 1; $first['retry'] = intval($first['retry'] ?? 0) + 1;
if ($first['retry'] > 3) { if ($first['retry'] > 3) {
info("[PushMsg] fail: " . $e->getMessage()); info("[PushMsg] fail: " . $e->getMessage());
@ -91,6 +97,12 @@ class UmengAlias extends AbstractModel
self::$waitSend[] = $first; self::$waitSend[] = $first;
} }
} finally { } finally {
if ($instance !== null) {
UmengLog::create([
'request' => Base::array2json($first['data']),
'response' => Base::array2json($responsePayload),
]);
}
self::sendTask(); self::sendTask();
} }
} }
@ -153,7 +165,7 @@ class UmengAlias extends AbstractModel
$description = $array['description'] ?: 'no description'; // 描述 $description = $array['description'] ?: 'no description'; // 描述
$extra = is_array($array['extra']) ? $array['extra'] : []; // 额外参数 $extra = is_array($array['extra']) ? $array['extra'] : []; // 额外参数
$seconds = intval($array['seconds']) ?: 86400; // 有效时间(单位:秒) $seconds = intval($array['seconds']) ?: 86400; // 有效时间(单位:秒)
$badge = intval($array['badge']) ?: 0; // 角标数iOS $badge = intval($array['badge']) ?: 0; // 角标数
// //
switch ($platform) { switch ($platform) {
case 'ios': case 'ios':
@ -203,6 +215,7 @@ class UmengAlias extends AbstractModel
'title' => $title, 'title' => $title,
'after_open' => 'go_app', 'after_open' => 'go_app',
'play_sound' => true, 'play_sound' => true,
'set_badge' => min(99, $badge),
], ],
], $extra), ], $extra),
'type' => 'customizedcast', 'type' => 'customizedcast',
@ -215,12 +228,17 @@ class UmengAlias extends AbstractModel
], ],
'category' => 1, 'category' => 1,
'channel_properties' => [ 'channel_properties' => [
'main_activity' => 'com.dootask.task.WelcomeActivity',
'oppo_channel_id' => 'dootask', 'oppo_channel_id' => 'dootask',
'vivo_category' => 'IM', 'vivo_category' => 'IM',
'huawei_channel_importance' => 'NORMAL', 'huawei_channel_importance' => 'NORMAL',
'huawei_channel_category' => 'IM', 'huawei_channel_category' => 'IM',
'channel_fcm' => 0, 'channel_fcm' => 0,
], ],
'local_properties' => [
'importance' => 'IMPORTANCE_DEFAULT',
'category' => 'CATEGORY_MESSAGE',
]
] ]
]); ]);
break; break;

32
app/Models/UmengLog.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace App\Models;
/**
* App\Models\UmengLog
*
* @property int $id
* @property string|null $request 请求参数
* @property string|null $response 推送返回
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelAppend()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelHidden()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel change($array)
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel getKeyValue()
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog query()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel remove()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel saveOrIgnore()
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereRequest($value)
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereResponse($value)
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereUpdatedAt($value)
* @mixin \Eloquent
*/
class UmengLog extends AbstractModel
{
protected $guarded = [];
}

View File

@ -6,6 +6,7 @@ use App\Models\File;
use App\Models\TaskWorker; use App\Models\TaskWorker;
use App\Models\Tmp; use App\Models\Tmp;
use App\Models\UserDevice; use App\Models\UserDevice;
use App\Models\UmengLog;
use App\Models\WebSocketTmpMsg; use App\Models\WebSocketTmpMsg;
use App\Module\Base; use App\Module\Base;
use Carbon\Carbon; use Carbon\Carbon;
@ -103,6 +104,17 @@ class DeleteTmpTask extends AbstractTask
} }
}); });
break; break;
case 'umeng_log':
UmengLog::where('created_at', '<', Carbon::now()->subHours($this->hours))
->orderBy('id')
->chunk(500, function ($logs) {
/** @var UmengLog $log */
foreach ($logs as $log) {
$log->delete();
}
});
break;
} }
} }

View File

@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('umeng_logs', function (Blueprint $table) {
$table->id();
$table->text('request')->nullable()->comment('请求参数');
$table->text('response')->nullable()->comment('推送返回');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('umeng_logs');
}
};