Commit 9a7926e8 9a7926e8a5a9b64e2a749550e29dc55a6096ee97 by 杨俊

fix(develop): 修复报错

1 parent 326d99ba
<?php
namespace App\Helpers;
use Carbon\Carbon;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
class ServiceHelper
{
/**
* @return string
*/
public static function getServiceHost(): string
{
return config('services.provider.service_host', '');
}
/**
* @return string
*/
public static function getServiceSecret(): string
{
return config('services.provider.service_secret', '');
}
/**
* 推送微信服务号
* @param array<string,mixed> $data
* @return \Illuminate\Http\Client\Response
* @throws \JsonException
*/
public static function sendWechatOfficial(array $data): Response
{
return self::send('WechatOfficialMessage', $data);
}
/**
* 推送微信小程序
* @param array<string,mixed> $data
* @return \Illuminate\Http\Client\Response
* @throws \JsonException
*/
public static function sendWechatApp(array $data): Response
{
return self::send('WechatAppMessage', $data);
}
/**
* 推送极光消息
* @param array<string,mixed> $data
* @return \Illuminate\Http\Client\Response
* @throws \JsonException
*/
public static function sendJPush(array $data): Response
{
return self::send('JPushMessage', $data);
}
/**
* @param string $channel
* @param array<string,mixed> $data
* @return \Illuminate\Http\Client\Response
* @throws \JsonException
*/
public static function send(string $channel, array $data): Response
{
$payload = ['time' => Carbon::now()->timestamp, 'channel' => $channel, 'data' => $data];
$payload['sign'] = self::getSign($payload);
return Http::asJson()->post(self::getServiceHost() . '/api/provider', $payload);
}
/**
* @param array<string,mixed> $payload
* @return string
* @throws \JsonException
*/
private static function getSign(array $payload): string
{
$payload['data'] = json_encode($payload['data'], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
$payload['secret'] = self::getServiceSecret();
ksort($payload);
return md5(base64_encode(implode('&', $payload)));
}
}
......@@ -18,7 +18,6 @@
use App\Http\Service\ActivityService;
use App\Jobs\ActivityChangeStatusJob;
use App\Jobs\ActivityMakeMediaJob;
use App\Jobs\ActivityPublishJob;
use App\Models\Activity;
use App\Models\ActivityShareUser;
use App\Models\Pivots\UserActivityCollectionPivot;
......@@ -34,7 +33,6 @@
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiCode;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
......@@ -81,11 +79,7 @@ public function store(ActivityCreateRequest $request, ActivityService $service):
}
OperationLog::admin()->subject($activity)->createAction()->content('歌曲《%s》', $activity->getAttribute('song_name'));
Bus::chain([
new ActivityMakeMediaJob($activity, ActivityStatusEnum::UP, true),
new ActivityPublishJob($activity, data_get($activity, 'expand.push_type', []), data_get($activity, 'expand.push_user', [])),
])->dispatch();
ActivityMakeMediaJob::dispatch($activity, ActivityStatusEnum::UP, true);
return $activity->loadMissing('user:id,nick_name,real_name');
});
......@@ -267,8 +261,8 @@ public function likeUser(Request $request, Activity $activity): Response
}
/**
* @param \Illuminate\Http\Request $request
* @param \App\Models\Activity $activity
* @param \Illuminate\Http\Request $request
* @param \App\Models\Activity $activity
* @return \Hikoon\LaravelApi\Facades\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function submitUser(Request $request, Activity $activity): Response|BinaryFileResponse
......@@ -340,7 +334,7 @@ public function manageUser(Request $request, Activity $activity): Response
*/
public function sendNotify(Request $request, Activity $activity): Response
{
$attributes = $request->validate([
$request->validate([
'push_type' => 'bail|required_if:is_push,1|array',
'push_user' => 'bail|array',
'push_user.*' => 'bail|sometimes|numeric'
......@@ -351,14 +345,6 @@ public function sendNotify(Request $request, Activity $activity): Response
'push_user.*.numeric' => '推送歌手参数错误'
]);
$pushType = Arr::get($attributes, 'push_type', []);
$pushUser = Arr::get($attributes, 'push_user', []);
ActivityPublishJob::dispatch($activity, $pushType, $pushUser, true);
OperationLog::admin()->createAction()->subject($activity)
->content('歌曲《%s》推送通知', $activity->getAttribute('song_name'));
return $this->success(ApiCode::UPDATE_SUCCESS);
}
......
......@@ -11,7 +11,6 @@
use App\Http\Container\ManageSection\Requests\Audition\ApplyUpdateRequest;
use App\Http\Service\ActivityService;
use App\Jobs\ActivityMakeMediaJob;
use App\Jobs\ActivityPublishJob;
use App\Models\Activity;
use App\Models\ActivityApplyRecord;
use App\Notifications\ActivityApplyFailNotification;
......@@ -115,12 +114,7 @@ public function audit(ApplyAuditRequest $request, Activity $apply, ActivityServi
}
OperationLog::admin()->statusAction()->subject($apply)->content('歌曲《%s》,审核通过%s', $apply->getAttribute('song_name'), $change->format(',修改了:'));
Bus::chain([
new ActivityMakeMediaJob($apply, ActivityStatusEnum::UP, true),
new ActivityPublishJob($apply, data_get($apply, 'expand.push_type', []), data_get($apply, 'expand.push_user', [])),
])->dispatch();
ActivityMakeMediaJob::dispatch($apply, ActivityStatusEnum::UP, true);
//推送申请人通知
Notification::send($apply->getAttribute('user'), new ActivityApplySuccessNotification($apply));
});
......
<?php
namespace App\Jobs;
use App\Helpers\ServiceHelper;
use App\Models\Activity;
use App\Models\UserHasTag;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Redis;
class ActivityPublishJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public Activity $activity;
public array $pushType;
public array $pushUser;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Activity $activity, array $pushType, array $pushUser = [])
{
$this->activity = $activity;
$this->pushType = $pushType;
$this->pushUser = $pushUser;
}
/**
* @return int[]
*/
protected function getTagUserIds(): array
{
return UserHasTag::query()
->whereIn('tag_id', data_get($this->activity, 'expand.tag_ids', []))
->pluck('user_id')->toArray();
}
/**
* Execute the job.
*
* @return void
* @throws \JsonException
* @throws \RedisException
*/
public function handle(): void
{
$userIds = [];
foreach ($this->pushType as $item) {
if ($item === 'tag') {
$userIds += $this->getTagUserIds();
}
if ($item === 'user') {
$userIds += $this->pushUser;
}
}
$userIds = array_values(array_unique($userIds, SORT_NUMERIC));
Redis::client()->hSet('activity_publish', $this->activity->getKey(), json_encode($userIds, JSON_THROW_ON_ERROR));
ServiceHelper::send('ActivityPublish', ['activityId' => $this->activity->getKey()]);
}
}
......@@ -83,9 +83,5 @@
'default' => env('OSS_MTS_DEFAULT_PIPELINE', '')
]
]
],
'provider' => [
'service_host' => env('PROVIDER_SERVER_HOST', ''),
'service_secret' => env('PROVIDER_SERVER_SECRET', '')
],
]
];
......