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.

79 lines
2.7 KiB

2 months ago
<?php
namespace app\utility;
use app\home\service\BaseHomeService;
use Pusher\PushNotifications\PushNotifications;
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'),
)
);
$publishResponse = $beamsClient->publishToInterests(
$interest, // 兴趣名称最多100个
array(
"fcm" => array(
"notification" => array(
"title" => $title,
"body" => $body
)
),
"apns" => array(
"aps" => array(
"alert" => array(
"title" => $title,
"body" => $body
)
)),
"web" => array(
"notification" => array(
"title" => $title,
"body" => $body
// "icon" => "", //显示同志时的图标
// "deep_link" => "https://www.pusher.com", // 深层连接,点击通知时将在新选项卡中打开此连接
)
)
)
);
return $publishResponse;
}
// 发送到指定用户
public function publishToUsers()
{
$beamsClient = new \Pusher\PushNotifications\PushNotifications(
array(
"instanceId" => env('PUSHER.INSTANCE_ID'),
"secretKey" => env('PUSHER.SECRET_KEY'),
)
);
$publishResponse = $beamsClient->publishToUsers(
array("user-001", "user-002"),
array(
"fcm" => array(
"notification" => array(
"title" => "Hi!",
"body" => "This is my first Push Notification!"
)
),
"apns" => array("aps" => array(
"alert" => array(
"title" => "Hi!",
"body" => "This is my first Push Notification!"
)
)),
"web" => array(
"notification" => array(
"title" => "Hi!",
"body" => "This is my first Push Notification!"
)
)
));
}
}