p2 project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.5 KiB

2 months ago
<?php
namespace app\utility;
use app\home\service\BaseHomeService;
use Pusher\PushNotifications\PushNotifications;
2 months ago
require_once __DIR__ . '/../../vendor/autoload.php';
2 months ago
class Pusher extends BaseHomeService
{
// 发送到所有订阅兴趣的客户端 $interest 必须是数组类型,可以包含多个兴趣名称
public function publishToInterest($interest, $title, $body)
{
$beamsClient = new \Pusher\PushNotifications\PushNotifications(
array(
"instanceId" => env('PUSHER.INSTANCE_ID'),
"secretKey" => env('PUSHER.SECRET_KEY'),
)
);
2 months ago
return $beamsClient->publishToInterests(
2 months ago
$interest, // 兴趣名称最多100个
2 months ago
[
"apns" => [
"aps" => [
"alert" => [
2 months ago
"title" => $title,
"body" => $body
2 months ago
]
]
],
"fcm" => [
"notification" => [
2 months ago
"title" => $title,
"body" => $body
2 months ago
]
],
"web" => [
"notification" => [
"title" => $title,
"body" => $body
]
]
]
2 months ago
);
}
2 months ago
// 发送到指定用户, 用户列表必须是数组,最大长度1000个用户
public function publishToUsers($userArr, $title, $body)
2 months ago
{
$beamsClient = new \Pusher\PushNotifications\PushNotifications(
array(
"instanceId" => env('PUSHER.INSTANCE_ID'),
"secretKey" => env('PUSHER.SECRET_KEY'),
)
);
2 months ago
return $beamsClient->publishToUsers(
// array("user-001", "user-002"),
$userArr,
2 months ago
array(
"fcm" => array(
"notification" => array(
2 months ago
"title" => $title,
"body" => $body
2 months ago
)
),
"apns" => array("aps" => array(
"alert" => array(
2 months ago
"title" => $title,
"body" => $body
2 months ago
)
)),
"web" => array(
"notification" => array(
2 months ago
"title" => $title,
"body" => $body
2 months ago
)
)
2 months ago
)
);
2 months ago
}
2 months ago
2 months ago
}