fix(develop): 修复报错
Showing
5 changed files
with
6 additions
and
187 deletions
app/Helpers/ServiceHelper.php
deleted
100644 → 0
1 | <?php | ||
2 | |||
3 | namespace App\Helpers; | ||
4 | |||
5 | use Carbon\Carbon; | ||
6 | use Illuminate\Http\Client\Response; | ||
7 | use Illuminate\Support\Facades\Http; | ||
8 | |||
9 | class ServiceHelper | ||
10 | { | ||
11 | /** | ||
12 | * @return string | ||
13 | */ | ||
14 | public static function getServiceHost(): string | ||
15 | { | ||
16 | return config('services.provider.service_host', ''); | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * @return string | ||
21 | */ | ||
22 | public static function getServiceSecret(): string | ||
23 | { | ||
24 | return config('services.provider.service_secret', ''); | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * 推送微信服务号 | ||
29 | * @param array<string,mixed> $data | ||
30 | * @return \Illuminate\Http\Client\Response | ||
31 | * @throws \JsonException | ||
32 | */ | ||
33 | public static function sendWechatOfficial(array $data): Response | ||
34 | { | ||
35 | return self::send('WechatOfficialMessage', $data); | ||
36 | } | ||
37 | |||
38 | /** | ||
39 | * 推送微信小程序 | ||
40 | * @param array<string,mixed> $data | ||
41 | * @return \Illuminate\Http\Client\Response | ||
42 | * @throws \JsonException | ||
43 | */ | ||
44 | public static function sendWechatApp(array $data): Response | ||
45 | { | ||
46 | return self::send('WechatAppMessage', $data); | ||
47 | } | ||
48 | |||
49 | /** | ||
50 | * 推送极光消息 | ||
51 | * @param array<string,mixed> $data | ||
52 | * @return \Illuminate\Http\Client\Response | ||
53 | * @throws \JsonException | ||
54 | */ | ||
55 | public static function sendJPush(array $data): Response | ||
56 | { | ||
57 | return self::send('JPushMessage', $data); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * @param string $channel | ||
62 | * @param array<string,mixed> $data | ||
63 | * @return \Illuminate\Http\Client\Response | ||
64 | * @throws \JsonException | ||
65 | */ | ||
66 | public static function send(string $channel, array $data): Response | ||
67 | { | ||
68 | $payload = ['time' => Carbon::now()->timestamp, 'channel' => $channel, 'data' => $data]; | ||
69 | $payload['sign'] = self::getSign($payload); | ||
70 | return Http::asJson()->post(self::getServiceHost() . '/api/provider', $payload); | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * @param array<string,mixed> $payload | ||
75 | * @return string | ||
76 | * @throws \JsonException | ||
77 | */ | ||
78 | private static function getSign(array $payload): string | ||
79 | { | ||
80 | $payload['data'] = json_encode($payload['data'], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR); | ||
81 | $payload['secret'] = self::getServiceSecret(); | ||
82 | ksort($payload); | ||
83 | return md5(base64_encode(implode('&', $payload))); | ||
84 | } | ||
85 | } |
... | @@ -18,7 +18,6 @@ | ... | @@ -18,7 +18,6 @@ |
18 | use App\Http\Service\ActivityService; | 18 | use App\Http\Service\ActivityService; |
19 | use App\Jobs\ActivityChangeStatusJob; | 19 | use App\Jobs\ActivityChangeStatusJob; |
20 | use App\Jobs\ActivityMakeMediaJob; | 20 | use App\Jobs\ActivityMakeMediaJob; |
21 | use App\Jobs\ActivityPublishJob; | ||
22 | use App\Models\Activity; | 21 | use App\Models\Activity; |
23 | use App\Models\ActivityShareUser; | 22 | use App\Models\ActivityShareUser; |
24 | use App\Models\Pivots\UserActivityCollectionPivot; | 23 | use App\Models\Pivots\UserActivityCollectionPivot; |
... | @@ -34,7 +33,6 @@ | ... | @@ -34,7 +33,6 @@ |
34 | use Hikoon\LaravelApi\Facades\Response; | 33 | use Hikoon\LaravelApi\Facades\Response; |
35 | use Hikoon\LaravelApi\Support\ApiCode; | 34 | use Hikoon\LaravelApi\Support\ApiCode; |
36 | use Illuminate\Http\Request; | 35 | use Illuminate\Http\Request; |
37 | use Illuminate\Support\Facades\Bus; | ||
38 | use Illuminate\Support\Facades\Cache; | 36 | use Illuminate\Support\Facades\Cache; |
39 | use Symfony\Component\HttpFoundation\BinaryFileResponse; | 37 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
40 | 38 | ||
... | @@ -81,11 +79,7 @@ public function store(ActivityCreateRequest $request, ActivityService $service): | ... | @@ -81,11 +79,7 @@ public function store(ActivityCreateRequest $request, ActivityService $service): |
81 | } | 79 | } |
82 | 80 | ||
83 | OperationLog::admin()->subject($activity)->createAction()->content('歌曲《%s》', $activity->getAttribute('song_name')); | 81 | OperationLog::admin()->subject($activity)->createAction()->content('歌曲《%s》', $activity->getAttribute('song_name')); |
84 | 82 | ActivityMakeMediaJob::dispatch($activity, ActivityStatusEnum::UP, true); | |
85 | Bus::chain([ | ||
86 | new ActivityMakeMediaJob($activity, ActivityStatusEnum::UP, true), | ||
87 | new ActivityPublishJob($activity, data_get($activity, 'expand.push_type', []), data_get($activity, 'expand.push_user', [])), | ||
88 | ])->dispatch(); | ||
89 | 83 | ||
90 | return $activity->loadMissing('user:id,nick_name,real_name'); | 84 | return $activity->loadMissing('user:id,nick_name,real_name'); |
91 | }); | 85 | }); |
... | @@ -267,8 +261,8 @@ public function likeUser(Request $request, Activity $activity): Response | ... | @@ -267,8 +261,8 @@ public function likeUser(Request $request, Activity $activity): Response |
267 | } | 261 | } |
268 | 262 | ||
269 | /** | 263 | /** |
270 | * @param \Illuminate\Http\Request $request | 264 | * @param \Illuminate\Http\Request $request |
271 | * @param \App\Models\Activity $activity | 265 | * @param \App\Models\Activity $activity |
272 | * @return \Hikoon\LaravelApi\Facades\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse | 266 | * @return \Hikoon\LaravelApi\Facades\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse |
273 | */ | 267 | */ |
274 | public function submitUser(Request $request, Activity $activity): Response|BinaryFileResponse | 268 | public function submitUser(Request $request, Activity $activity): Response|BinaryFileResponse |
... | @@ -340,7 +334,7 @@ public function manageUser(Request $request, Activity $activity): Response | ... | @@ -340,7 +334,7 @@ public function manageUser(Request $request, Activity $activity): Response |
340 | */ | 334 | */ |
341 | public function sendNotify(Request $request, Activity $activity): Response | 335 | public function sendNotify(Request $request, Activity $activity): Response |
342 | { | 336 | { |
343 | $attributes = $request->validate([ | 337 | $request->validate([ |
344 | 'push_type' => 'bail|required_if:is_push,1|array', | 338 | 'push_type' => 'bail|required_if:is_push,1|array', |
345 | 'push_user' => 'bail|array', | 339 | 'push_user' => 'bail|array', |
346 | 'push_user.*' => 'bail|sometimes|numeric' | 340 | 'push_user.*' => 'bail|sometimes|numeric' |
... | @@ -351,14 +345,6 @@ public function sendNotify(Request $request, Activity $activity): Response | ... | @@ -351,14 +345,6 @@ public function sendNotify(Request $request, Activity $activity): Response |
351 | 'push_user.*.numeric' => '推送歌手参数错误' | 345 | 'push_user.*.numeric' => '推送歌手参数错误' |
352 | ]); | 346 | ]); |
353 | 347 | ||
354 | $pushType = Arr::get($attributes, 'push_type', []); | ||
355 | $pushUser = Arr::get($attributes, 'push_user', []); | ||
356 | |||
357 | ActivityPublishJob::dispatch($activity, $pushType, $pushUser, true); | ||
358 | |||
359 | OperationLog::admin()->createAction()->subject($activity) | ||
360 | ->content('歌曲《%s》推送通知', $activity->getAttribute('song_name')); | ||
361 | |||
362 | 348 | ||
363 | return $this->success(ApiCode::UPDATE_SUCCESS); | 349 | return $this->success(ApiCode::UPDATE_SUCCESS); |
364 | } | 350 | } | ... | ... |
... | @@ -11,7 +11,6 @@ | ... | @@ -11,7 +11,6 @@ |
11 | use App\Http\Container\ManageSection\Requests\Audition\ApplyUpdateRequest; | 11 | use App\Http\Container\ManageSection\Requests\Audition\ApplyUpdateRequest; |
12 | use App\Http\Service\ActivityService; | 12 | use App\Http\Service\ActivityService; |
13 | use App\Jobs\ActivityMakeMediaJob; | 13 | use App\Jobs\ActivityMakeMediaJob; |
14 | use App\Jobs\ActivityPublishJob; | ||
15 | use App\Models\Activity; | 14 | use App\Models\Activity; |
16 | use App\Models\ActivityApplyRecord; | 15 | use App\Models\ActivityApplyRecord; |
17 | use App\Notifications\ActivityApplyFailNotification; | 16 | use App\Notifications\ActivityApplyFailNotification; |
... | @@ -115,12 +114,7 @@ public function audit(ApplyAuditRequest $request, Activity $apply, ActivityServi | ... | @@ -115,12 +114,7 @@ public function audit(ApplyAuditRequest $request, Activity $apply, ActivityServi |
115 | } | 114 | } |
116 | 115 | ||
117 | OperationLog::admin()->statusAction()->subject($apply)->content('歌曲《%s》,审核通过%s', $apply->getAttribute('song_name'), $change->format(',修改了:')); | 116 | OperationLog::admin()->statusAction()->subject($apply)->content('歌曲《%s》,审核通过%s', $apply->getAttribute('song_name'), $change->format(',修改了:')); |
118 | 117 | ActivityMakeMediaJob::dispatch($apply, ActivityStatusEnum::UP, true); | |
119 | Bus::chain([ | ||
120 | new ActivityMakeMediaJob($apply, ActivityStatusEnum::UP, true), | ||
121 | new ActivityPublishJob($apply, data_get($apply, 'expand.push_type', []), data_get($apply, 'expand.push_user', [])), | ||
122 | ])->dispatch(); | ||
123 | |||
124 | //推送申请人通知 | 118 | //推送申请人通知 |
125 | Notification::send($apply->getAttribute('user'), new ActivityApplySuccessNotification($apply)); | 119 | Notification::send($apply->getAttribute('user'), new ActivityApplySuccessNotification($apply)); |
126 | }); | 120 | }); | ... | ... |
app/Jobs/ActivityPublishJob.php
deleted
100644 → 0
1 | <?php | ||
2 | |||
3 | namespace App\Jobs; | ||
4 | |||
5 | use App\Helpers\ServiceHelper; | ||
6 | use App\Models\Activity; | ||
7 | use App\Models\UserHasTag; | ||
8 | use Illuminate\Bus\Queueable; | ||
9 | use Illuminate\Contracts\Queue\ShouldQueue; | ||
10 | use Illuminate\Foundation\Bus\Dispatchable; | ||
11 | use Illuminate\Queue\InteractsWithQueue; | ||
12 | use Illuminate\Queue\SerializesModels; | ||
13 | use Illuminate\Support\Facades\Redis; | ||
14 | |||
15 | class ActivityPublishJob implements ShouldQueue | ||
16 | { | ||
17 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
18 | |||
19 | public Activity $activity; | ||
20 | |||
21 | public array $pushType; | ||
22 | |||
23 | public array $pushUser; | ||
24 | |||
25 | /** | ||
26 | * Create a new job instance. | ||
27 | * | ||
28 | * @return void | ||
29 | */ | ||
30 | public function __construct(Activity $activity, array $pushType, array $pushUser = []) | ||
31 | { | ||
32 | $this->activity = $activity; | ||
33 | $this->pushType = $pushType; | ||
34 | $this->pushUser = $pushUser; | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * @return int[] | ||
39 | */ | ||
40 | protected function getTagUserIds(): array | ||
41 | { | ||
42 | return UserHasTag::query() | ||
43 | ->whereIn('tag_id', data_get($this->activity, 'expand.tag_ids', [])) | ||
44 | ->pluck('user_id')->toArray(); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Execute the job. | ||
49 | * | ||
50 | * @return void | ||
51 | * @throws \JsonException | ||
52 | * @throws \RedisException | ||
53 | */ | ||
54 | public function handle(): void | ||
55 | { | ||
56 | $userIds = []; | ||
57 | |||
58 | foreach ($this->pushType as $item) { | ||
59 | if ($item === 'tag') { | ||
60 | $userIds += $this->getTagUserIds(); | ||
61 | } | ||
62 | if ($item === 'user') { | ||
63 | $userIds += $this->pushUser; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | $userIds = array_values(array_unique($userIds, SORT_NUMERIC)); | ||
68 | |||
69 | Redis::client()->hSet('activity_publish', $this->activity->getKey(), json_encode($userIds, JSON_THROW_ON_ERROR)); | ||
70 | ServiceHelper::send('ActivityPublish', ['activityId' => $this->activity->getKey()]); | ||
71 | } | ||
72 | } |
... | @@ -83,9 +83,5 @@ | ... | @@ -83,9 +83,5 @@ |
83 | 'default' => env('OSS_MTS_DEFAULT_PIPELINE', '') | 83 | 'default' => env('OSS_MTS_DEFAULT_PIPELINE', '') |
84 | ] | 84 | ] |
85 | ] | 85 | ] |
86 | ], | 86 | ] |
87 | 'provider' => [ | ||
88 | 'service_host' => env('PROVIDER_SERVER_HOST', ''), | ||
89 | 'service_secret' => env('PROVIDER_SERVER_SECRET', '') | ||
90 | ], | ||
91 | ]; | 87 | ]; | ... | ... |
-
Please register or sign in to post a comment