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.

66 lines
1.9 KiB

<?php
namespace app\admin\controller;
use app\admin\service\NoticeService;
class Notice extends AdminBaseController
{
// 弹窗通知消息
public function popUp()
{
$returnData = (new NoticeService())->popUp($this->request->param());
return json($returnData);
}
// 向一个或多个设备兴趣推送通知
public function publishToInterest()
{
$param = $this->request->post();
if (empty($param['title']) || empty($param['body'])) {
return json([
'code' => 400,
'message' => "缺少参数",
'data' => []
]);
}
$interestName = ["interests-1"]; // 订阅兴趣的名称, 一次推送最多100个兴趣名称
$res = (new \app\utility\Pusher())->publishToInterest($interestName, $param['title'], $param['body']);
return json([
'code' => 0,
'message' => 'ok',
'data' => $res
]);
}
// 向一个或多个用户推送通知
public function publishToUsers()
{
$param = $this->request->post();
if (empty($param['users']) || empty($param['title']) || empty($param['body'])) {
return json([
'code' => 400,
'message' => "缺少参数",
'data' => []
]);
}
// 将用户ID构建为数组
$explodeUser = explode(',', $param['users']);
$buildUserArr = [];
foreach ($explodeUser as $uid) {
if (is_numeric($uid)) {
$buildUserArr[] = strval($uid);
} else {
$buildUserArr[] = $uid;
}
}
// 发送通知
$res = (new \app\utility\Pusher())->publishToUsers($buildUserArr, $param['title'], $param['body']);
return json([
'code' => 0,
'message' => 'ok',
'data' => $res
]);
}
}