feat(develop): 移除极光推送,微信推送
Showing
8 changed files
with
1 additions
and
218 deletions
app/Actions/ActivityPublishApply.php
deleted
100644 → 0
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Actions; | ||
| 4 | |||
| 5 | use App\Jobs\WechatTemplateMessageJob; | ||
| 6 | use App\Models\Activity; | ||
| 7 | use App\Models\SystemRole; | ||
| 8 | use App\Models\User; | ||
| 9 | use Carbon\Carbon; | ||
| 10 | use Lorisleiva\Actions\Concerns\AsAction; | ||
| 11 | use Lorisleiva\Actions\Concerns\AsJob; | ||
| 12 | |||
| 13 | class ActivityPublishApply | ||
| 14 | { | ||
| 15 | use AsAction, AsJob; | ||
| 16 | |||
| 17 | protected string $template = 'o9i6qtgr4ghtGvU-piimB9_mAaSOAXDDMzqx9zXYkss'; | ||
| 18 | |||
| 19 | public function handle(Activity $activity): void | ||
| 20 | { | ||
| 21 | $activity->loadMissing('user:id,nick_name,real_name'); | ||
| 22 | |||
| 23 | $roleIds = SystemRole::query() | ||
| 24 | ->whereRelation('permissions', fn($query) => $query->where('guard', 'Admin')->where('system_permissions.name', 'audition-activity-audit-audit')) | ||
| 25 | ->where('system_roles.status', 1) | ||
| 26 | ->pluck('system_roles.id')->toArray(); | ||
| 27 | |||
| 28 | |||
| 29 | User::query() | ||
| 30 | ->join('user_has_roles', 'user_has_roles.user_id', 'users.id') | ||
| 31 | ->whereIn('user_has_roles.role_id', $roleIds) | ||
| 32 | ->where('users.status', 1)->where('users.official_status', 1) | ||
| 33 | ->distinct()->pluck('users.official_id') | ||
| 34 | ->each(fn($item) => WechatTemplateMessageJob::dispatch($item, $this->template, [ | ||
| 35 | 'first' => '厂牌提交试唱发布申请', | ||
| 36 | 'keyword1' => '海星试唱提交了上架申请', | ||
| 37 | 'keyword2' => sprintf('%s(%s)', data_get($activity, 'user.nick_name'), data_get($activity, 'user.real_name')), | ||
| 38 | 'keyword3' => (string)data_get($activity, 'created_at', Carbon::now()->toDateTimeString()), | ||
| 39 | 'keyword4' => sprintf('【%s】活动上架需要您的审核', $activity->getAttribute('song_name')), | ||
| 40 | 'remark' => '' | ||
| 41 | ])); | ||
| 42 | } | ||
| 43 | } |
| ... | @@ -2,24 +2,14 @@ | ... | @@ -2,24 +2,14 @@ |
| 2 | 2 | ||
| 3 | namespace App\Channels; | 3 | namespace App\Channels; |
| 4 | 4 | ||
| 5 | use App\Jobs\WechatTemplateMessageJob; | ||
| 6 | use App\Models\User; | 5 | use App\Models\User; |
| 7 | use Illuminate\Notifications\Notification; | 6 | use Illuminate\Notifications\Notification; |
| 8 | use Illuminate\Support\Arr; | ||
| 9 | 7 | ||
| 10 | class WechatNotificationChannel | 8 | class WechatNotificationChannel |
| 11 | { | 9 | { |
| 12 | public function send(User $notifiable, Notification $notification): void | 10 | public function send(User $notifiable, Notification $notification): void |
| 13 | { | 11 | { |
| 14 | // @phpstan-ignore-next-line | 12 | // @phpstan-ignore-next-line |
| 15 | $message = $notification->toWechat($notifiable); | 13 | $notification->toWechat($notifiable); |
| 16 | |||
| 17 | WechatTemplateMessageJob::dispatchSync( | ||
| 18 | openId: Arr::get($message, 'openId', ''), | ||
| 19 | template: Arr::get($message, 'template', ''), | ||
| 20 | data: Arr::get($message, 'data', []), | ||
| 21 | url: Arr::get($message, 'url', ''), | ||
| 22 | page: Arr::get($message, 'page', '') | ||
| 23 | ); | ||
| 24 | } | 14 | } |
| 25 | } | 15 | } | ... | ... |
| ... | @@ -3,7 +3,6 @@ | ... | @@ -3,7 +3,6 @@ |
| 3 | namespace App\Http\Container\AppSection\Controllers; | 3 | namespace App\Http\Container\AppSection\Controllers; |
| 4 | 4 | ||
| 5 | use App\Helpers\JsonResource; | 5 | use App\Helpers\JsonResource; |
| 6 | use App\Jobs\JPushMessageJob; | ||
| 7 | use App\Models\Activity; | 6 | use App\Models\Activity; |
| 8 | use App\Models\ActivityShareUser; | 7 | use App\Models\ActivityShareUser; |
| 9 | use App\Models\Pivots\UserActivityCollectionPivot; | 8 | use App\Models\Pivots\UserActivityCollectionPivot; |
| ... | @@ -184,19 +183,6 @@ public function sub(Request $request) | ... | @@ -184,19 +183,6 @@ public function sub(Request $request) |
| 184 | $resp = Http::asJson()->post($url, $req_data)->json(); | 183 | $resp = Http::asJson()->post($url, $req_data)->json(); |
| 185 | } | 184 | } |
| 186 | } | 185 | } |
| 187 | |||
| 188 | # 极光推送-歌手收藏 | ||
| 189 | $j_title = "您的歌手收藏了试唱"; | ||
| 190 | $j_content = "您的歌手".$user->nick_name."收藏了试唱活动《".$song_name."》"; | ||
| 191 | $jdata = ["title"=> $j_title, "content"=>$j_content, "content_type"=>"text", | ||
| 192 | "receiver_value"=> [$business_id], | ||
| 193 | "extras"=> ["type"=>"ToTaCollection", "value"=>""]]; | ||
| 194 | JPushMessageJob::dispatch( | ||
| 195 | $business_id, | ||
| 196 | $j_title, | ||
| 197 | $j_content, | ||
| 198 | $jdata | ||
| 199 | ); | ||
| 200 | } | 186 | } |
| 201 | 187 | ||
| 202 | return JsonResource::success('收藏成功'); | 188 | return JsonResource::success('收藏成功'); | ... | ... |
| ... | @@ -5,12 +5,9 @@ | ... | @@ -5,12 +5,9 @@ |
| 5 | use App\Exceptions\TestCallbackException; | 5 | use App\Exceptions\TestCallbackException; |
| 6 | use App\Helpers\IMHelper; | 6 | use App\Helpers\IMHelper; |
| 7 | use App\Jobs\ImMessageSaveJob; | 7 | use App\Jobs\ImMessageSaveJob; |
| 8 | use App\Jobs\WechatTemplateMessageJob; | ||
| 9 | use App\Models\ActivityGroup; | 8 | use App\Models\ActivityGroup; |
| 10 | use App\Models\ActivityGroupUser; | 9 | use App\Models\ActivityGroupUser; |
| 11 | use App\Models\SystemConfig; | ||
| 12 | use App\Models\User; | 10 | use App\Models\User; |
| 13 | use Carbon\Carbon; | ||
| 14 | use GuzzleHttp\Promise\PromiseInterface; | 11 | use GuzzleHttp\Promise\PromiseInterface; |
| 15 | use Hikoon\LaravelApi\Support\ApiController; | 12 | use Hikoon\LaravelApi\Support\ApiController; |
| 16 | use Illuminate\Http\Client\Response; | 13 | use Illuminate\Http\Client\Response; |
| ... | @@ -84,46 +81,12 @@ protected function stateStateChange(array $data): JsonResponse | ... | @@ -84,46 +81,12 @@ protected function stateStateChange(array $data): JsonResponse |
| 84 | */ | 81 | */ |
| 85 | protected function c2CCallbackAfterSendMsg(array $data): JsonResponse | 82 | protected function c2CCallbackAfterSendMsg(array $data): JsonResponse |
| 86 | { | 83 | { |
| 87 | $toId = Arr::get($data, 'To_Account'); | ||
| 88 | $formId = Arr::get($data, 'From_Account'); | 84 | $formId = Arr::get($data, 'From_Account'); |
| 89 | $online = Arr::get($data, 'OnlineOnlyFlag', 0); | ||
| 90 | $time = Arr::get($data, 'MsgTime', Carbon::now()->getTimestamp()); | ||
| 91 | 85 | ||
| 92 | throw_unless($this->gate($formId), TestCallbackException::class); | 86 | throw_unless($this->gate($formId), TestCallbackException::class); |
| 93 | 87 | ||
| 94 | $hashKey = 'imOfflineMsg'; | ||
| 95 | $sendTime = Carbon::createFromTimestamp($time)->toDateTimeString(); | ||
| 96 | $toId = IMHelper::accountToUserKey($toId); | ||
| 97 | $formId = IMHelper::accountToUserKey($formId); | ||
| 98 | |||
| 99 | |||
| 100 | ImMessageSaveJob::dispatch($data); | 88 | ImMessageSaveJob::dispatch($data); |
| 101 | 89 | ||
| 102 | $openId = User::query() | ||
| 103 | ->where('id', $toId) | ||
| 104 | ->where('audit_status', 1) | ||
| 105 | ->where('status', 1) | ||
| 106 | ->where('im_client', 'Web') | ||
| 107 | ->where('im_status', 0) | ||
| 108 | ->value('official_id'); | ||
| 109 | |||
| 110 | if ($openId && (int)$online === 0 && !Redis::client()->hExists($hashKey, $formId)) { | ||
| 111 | Redis::client()->hSet($hashKey, $formId, 0); | ||
| 112 | $customerId = SystemConfig::query()->where('identifier', 'customer_service')->value('remark'); | ||
| 113 | $formUser = User::with('artTags:id,name')->find($formId, ['id', 'nick_name']); | ||
| 114 | $formName = $formUser->getAttribute('nick_name'); | ||
| 115 | $formTag = $formUser->getRelation('artTags') ? $formUser->getRelation('artTags')->implode('name', ',') : '无'; | ||
| 116 | |||
| 117 | $data = $customerId === $formId ? | ||
| 118 | ['first' => '您收到平台客服发来的消息', 'keyword1' => $formName, 'keyword2' => '平台客服', 'keyword3' => '平台官方', 'keyword4' => $sendTime, 'remark' => '点击查看'] : | ||
| 119 | ['first' => '您收到新的私聊消息', 'keyword1' => $formName, 'keyword2' => $formTag, 'keyword3' => '私聊消息', 'keyword4' => $sendTime, 'remark' => '点击查看']; | ||
| 120 | |||
| 121 | |||
| 122 | WechatTemplateMessageJob::dispatch($openId, 'HTRAwaRoJksSGCiSeVCyvpF9vXdeQhC6R4PbSYnO8NM', $data); | ||
| 123 | } | ||
| 124 | |||
| 125 | Redis::client()->hIncrBy($hashKey, $formId, 1); | ||
| 126 | |||
| 127 | return new JsonResponse(['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0]); | 90 | return new JsonResponse(['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0]); |
| 128 | } | 91 | } |
| 129 | 92 | ... | ... |
| ... | @@ -2,7 +2,6 @@ | ... | @@ -2,7 +2,6 @@ |
| 2 | 2 | ||
| 3 | namespace App\Http\Service; | 3 | namespace App\Http\Service; |
| 4 | 4 | ||
| 5 | use App\Actions\ActivityPublishApply; | ||
| 6 | use App\Actions\ActivityWorkAuditFail; | 5 | use App\Actions\ActivityWorkAuditFail; |
| 7 | use App\Actions\ActivityWorkAuditSuccess; | 6 | use App\Actions\ActivityWorkAuditSuccess; |
| 8 | use App\Enums\ActivityAuditStatusEnum; | 7 | use App\Enums\ActivityAuditStatusEnum; |
| ... | @@ -160,7 +159,6 @@ public function createActivityApply(array $attribute, bool $checkConfig = true): | ... | @@ -160,7 +159,6 @@ public function createActivityApply(array $attribute, bool $checkConfig = true): |
| 160 | return DB::transaction(static function () use ($attribute) { | 159 | return DB::transaction(static function () use ($attribute) { |
| 161 | $activity = Activity::query()->create(array_merge($attribute, ['song_type' => ActivitySongTypeEnum::SONG->value])); | 160 | $activity = Activity::query()->create(array_merge($attribute, ['song_type' => ActivitySongTypeEnum::SONG->value])); |
| 162 | OperationLog::guard()->subject($activity)->createAction()->content('歌曲《%s》,申请上架', $activity->getAttribute('song_name')); | 161 | OperationLog::guard()->subject($activity)->createAction()->content('歌曲《%s》,申请上架', $activity->getAttribute('song_name')); |
| 163 | ActivityPublishApply::dispatch($activity); | ||
| 164 | return $activity; | 162 | return $activity; |
| 165 | }); | 163 | }); |
| 166 | } | 164 | } | ... | ... |
| ... | @@ -41,26 +41,6 @@ public function __construct(array $jPushMessage, array $wechatMessage) | ... | @@ -41,26 +41,6 @@ public function __construct(array $jPushMessage, array $wechatMessage) |
| 41 | */ | 41 | */ |
| 42 | public function handle(): void | 42 | public function handle(): void |
| 43 | { | 43 | { |
| 44 | User::query()->where('status', 1) | ||
| 45 | ->whereIn('id', explode(',', SystemConfig::query()->where('identifier', 'DBYsQqJrvuPf_d_zMR4va')->value('content') ?? '')) | ||
| 46 | ->select(['id', 'nick_name', 'real_name', 'official_id', 'official_status', 'area_code', 'phone']) | ||
| 47 | ->eachById(function (User $user) { | ||
| 48 | JPushMessageJob::dispatch( | ||
| 49 | $user->getKey(), | ||
| 50 | Arr::get($this->jPushMessage, 'title', ''), | ||
| 51 | Arr::get($this->jPushMessage, 'content', ''), | ||
| 52 | Arr::get($this->jPushMessage, 'data', []) | ||
| 53 | ); | ||
| 54 | 44 | ||
| 55 | if ($user->getAttribute('official_status') === UserOfficialStatusEnum::SUBSCRIBE) { | ||
| 56 | WechatTemplateMessageJob::dispatch($user->getAttribute('official_id'), 'GFJxUXdJs37HX2hYB_jdOeR2FQHj2RpkJo57q24Lkkc', [ | ||
| 57 | 'keyword1' => '歌手额度上限提醒', | ||
| 58 | 'keyword2' => Arr::get($this->wechatMessage, 'title', ''), | ||
| 59 | 'keyword3' => Arr::get($this->wechatMessage, 'content', ''), | ||
| 60 | 'keyword4' => Arr::get($this->wechatMessage, 'limit', $this->defaultLimit), | ||
| 61 | 'keyword5' => Arr::get($this->wechatMessage, 'limit', $this->defaultLimit), | ||
| 62 | ]); | ||
| 63 | } | ||
| 64 | }); | ||
| 65 | } | 45 | } |
| 66 | } | 46 | } | ... | ... |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Jobs; | ||
| 4 | |||
| 5 | use App\Helpers\ServiceHelper; | ||
| 6 | use Illuminate\Bus\Queueable; | ||
| 7 | use Illuminate\Contracts\Queue\ShouldQueue; | ||
| 8 | use Illuminate\Foundation\Bus\Dispatchable; | ||
| 9 | use Illuminate\Queue\InteractsWithQueue; | ||
| 10 | use Illuminate\Queue\SerializesModels; | ||
| 11 | use function array_key_exists; | ||
| 12 | |||
| 13 | class WechatTemplateMessageJob implements ShouldQueue | ||
| 14 | { | ||
| 15 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
| 16 | |||
| 17 | // private const API_URI = 'cgi-bin/message/template/send'; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @var array<string,mixed> | ||
| 21 | */ | ||
| 22 | private array $data; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * Create a new job instance. | ||
| 26 | * | ||
| 27 | * @param string $openId | ||
| 28 | * @param string $template | ||
| 29 | * @param array<string,mixed> $data | ||
| 30 | * @param string $url | ||
| 31 | * @param string $page | ||
| 32 | */ | ||
| 33 | public function __construct(string $openId, string $template, array $data = [], string $url = '', string $page = '') | ||
| 34 | { | ||
| 35 | $this->data = ['openId' => $openId, 'template' => $template, 'data' => $this->formatData($data), 'page' => $page, 'url' => $url]; | ||
| 36 | } | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Execute the job. | ||
| 40 | * | ||
| 41 | * @return void | ||
| 42 | * @throws \JsonException | ||
| 43 | */ | ||
| 44 | public function handle(): void | ||
| 45 | { | ||
| 46 | //Access_Token 问题,暂时访问Admin服务推送接口 | ||
| 47 | ServiceHelper::sendWechatOfficial($this->data); | ||
| 48 | } | ||
| 49 | |||
| 50 | /** | ||
| 51 | * @param array<string,mixed> $data | ||
| 52 | * @return array<string,array<string,string>> | ||
| 53 | */ | ||
| 54 | protected function formatData(array $data): array | ||
| 55 | { | ||
| 56 | $formatted = []; | ||
| 57 | |||
| 58 | foreach ($data as $key => $value) { | ||
| 59 | if (is_array($value)) { | ||
| 60 | if (array_key_exists('value', $value)) { | ||
| 61 | $formatted[$key] = $value; | ||
| 62 | continue; | ||
| 63 | } | ||
| 64 | |||
| 65 | if (count($value) >= 2) { | ||
| 66 | $value = [ | ||
| 67 | 'value' => $value[0], | ||
| 68 | 'color' => $value[1], | ||
| 69 | ]; | ||
| 70 | } | ||
| 71 | } else { | ||
| 72 | $value = ['value' => (string)$value,]; | ||
| 73 | } | ||
| 74 | |||
| 75 | $formatted[$key] = $value; | ||
| 76 | } | ||
| 77 | |||
| 78 | return $formatted; | ||
| 79 | } | ||
| 80 | |||
| 81 | /** | ||
| 82 | * @param string $page | ||
| 83 | * @return array<string,string> | ||
| 84 | */ | ||
| 85 | protected function formatMiniPage(string $page): array | ||
| 86 | { | ||
| 87 | return ['appid' => config('easywechat.mini_app.default.app_id'), 'pagepath' => $page]; | ||
| 88 | } | ||
| 89 | } |
| ... | @@ -120,9 +120,7 @@ | ... | @@ -120,9 +120,7 @@ |
| 120 | */ | 120 | */ |
| 121 | 121 | ||
| 122 | 'silenced' => [ | 122 | 'silenced' => [ |
| 123 | \App\Jobs\JPushMessageJob::class, | ||
| 124 | \App\Jobs\SmsMessageJob::class, | 123 | \App\Jobs\SmsMessageJob::class, |
| 125 | \App\Jobs\WechatTemplateMessageJob::class, | ||
| 126 | ], | 124 | ], |
| 127 | 125 | ||
| 128 | /* | 126 | /* | ... | ... |
-
Please register or sign in to post a comment