Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
PaoPao
/
serviceWork
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
c47dcb22
...
c47dcb221045506731a1c5fa24335d61343b5e11
authored
2024-05-27 14:59:54 +0800
by
杨俊
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat(develop): 屏蔽极光推送
1 parent
f2b381e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 additions
and
119 deletions
app/Channels/JPushNotificationChannel.php
app/Jobs/JPushMessageJob.php
app/Channels/JPushNotificationChannel.php
View file @
c47dcb2
...
...
@@ -2,23 +2,14 @@
namespace
App\Channels
;
use
App\Jobs\JPushMessageJob
;
use
App\Models\User
;
use
Illuminate\Notifications\Notification
;
use
Illuminate\Support\Arr
;
class
JPushNotificationChannel
{
public
function
send
(
User
$notifiable
,
Notification
$notification
)
:
void
{
// @phpstan-ignore-next-line
$message
=
$notification
->
toJPush
(
$notifiable
);
JPushMessageJob
::
dispatchSync
(
Arr
::
get
(
$message
,
'user'
,
[]),
Arr
::
get
(
$message
,
'title'
,
''
),
Arr
::
get
(
$message
,
'content'
,
''
),
Arr
::
get
(
$message
,
'data'
,
[])
);
$notification
->
toJPush
(
$notifiable
);
}
}
...
...
app/Jobs/JPushMessageJob.php
deleted
100644 → 0
View file @
f2b381e
<?php
namespace
App\Jobs
;
use
Arr
;
use
Illuminate\Bus\Queueable
;
use
Illuminate\Contracts\Queue\ShouldQueue
;
use
Illuminate\Foundation\Bus\Dispatchable
;
use
Illuminate\Queue\InteractsWithQueue
;
use
Illuminate\Queue\SerializesModels
;
use
JPush\Client
;
use
JPush\Exceptions\APIRequestException
;
use
JPush\Exceptions\ServiceNotAvaliable
;
use
Log
;
class
JPushMessageJob
implements
ShouldQueue
{
use
Dispatchable
,
InteractsWithQueue
,
Queueable
,
SerializesModels
;
/**
* @var \JPush\Client
*/
protected
Client
$client
;
protected
array
$user
;
protected
string
$title
;
protected
string
$content
;
protected
array
$extras
;
protected
array
$config
;
/**
* Create a new job instance.
* @param array<int,string>|string $user
* @param string $title
* @param string $content
* @param array<string,mixed> $extras
*/
public
function
__construct
(
array
|
string
$user
,
string
$title
,
string
$content
,
array
$extras
=
[])
{
$this
->
config
=
config
(
'services.jpush'
);
$this
->
client
=
new
Client
(
$this
->
getConfig
(
'key'
),
$this
->
getConfig
(
'secret'
),
NULL
);
$this
->
user
=
Arr
::
map
(
Arr
::
wrap
(
$user
),
fn
(
$item
)
=>
$this
->
getConfig
(
'prefix'
)
.
$item
);
[
$this
->
title
,
$this
->
content
,
$this
->
extras
]
=
[
$title
,
$content
,
$extras
];
}
/**
* Execute the job.
*
* @return void
* @throws \Random\RandomException
*/
public
function
handle
()
:
void
{
try
{
$response
=
$this
->
send
();
}
catch
(
APIRequestException
|
ServiceNotAvaliable
$exception
)
{
$response
=
[
'http_code'
=>
$exception
->
getHttpCode
(),
'body'
=>
$exception
->
getMessage
()];
}
Log
::
channel
(
'jpush'
)
->
info
(
'JPush Message Status['
.
$response
[
'http_code'
]
.
']: '
.
PHP_EOL
,
[
'user'
=>
$this
->
user
,
'request'
=>
[
'title'
=>
$this
->
title
,
'content'
=>
$this
->
content
,
'extras'
=>
$this
->
extras
],
'response'
=>
$response
[
'body'
]
]);
}
/**
* @param string $key
* @return mixed
*/
private
function
getConfig
(
string
$key
)
:
mixed
{
return
Arr
::
get
(
$this
->
config
,
$key
);
}
/**
* @return array
* @throws \Random\RandomException
*/
private
function
send
()
:
array
{
return
$this
->
client
->
push
()
->
setPlatform
(
'all'
)
->
addAlias
(
$this
->
user
)
->
iosNotification
([
'title'
=>
$this
->
title
,
'body'
=>
$this
->
content
],
[
'extras'
=>
$this
->
extras
])
->
androidNotification
(
$this
->
content
,
[
'title'
=>
$this
->
title
,
'alert_type'
=>
7
,
'extras'
=>
$this
->
extras
])
->
options
([
'apns_production'
=>
$this
->
getConfig
(
'apns_production'
),
'time_to_live'
=>
86400
*
3
,
'sendno'
=>
random_int
(
100
,
99999999
),
'third_party_channel'
=>
[
'xiaomi'
=>
[
'importance'
=>
'HIGH'
],
'huawei'
=>
[
'importance'
=>
'HIGH'
],
'honor'
=>
[
'importance'
=>
'NORMAL'
],
'meizu'
=>
[
'importance'
=>
'HIGH'
],
'oppo'
=>
[
'importance'
=>
'HIGH'
],
'vivo'
=>
[
'importance'
=>
'HIGH'
],
]
])
->
send
();
}
}
Please
register
or
sign in
to post a comment