|
|
@ -13,8 +13,8 @@ class Notice extends AdminBaseController |
|
|
|
return json($returnData); |
|
|
|
} |
|
|
|
|
|
|
|
// 使用Pusher服务推送系统消息 |
|
|
|
public function pushMessage() |
|
|
|
// 向一个或多个设备兴趣推送通知 |
|
|
|
public function publishToInterest() |
|
|
|
{ |
|
|
|
$param = $this->request->post(); |
|
|
|
if (empty($param['title']) || empty($param['body'])) { |
|
|
@ -25,10 +25,38 @@ class Notice extends AdminBaseController |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
$interestName = ["admin-popup-push"]; // 订阅兴趣的名称, 一次推送最多100个兴趣名称 |
|
|
|
$title = ""; |
|
|
|
$body = ""; |
|
|
|
$res = (new \app\utility\Pusher())->publishToInterest($interestName, $title, $body); |
|
|
|
$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', |
|
|
|