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.
58 lines
2.1 KiB
58 lines
2.1 KiB
<?php
|
|
namespace app\home\service;
|
|
|
|
use app\model\PusherLogModel;
|
|
use app\model\UserModel;
|
|
|
|
class NoticeService extends BaseHomeService
|
|
{
|
|
// 生成Beams Token, 注意:返回结果的格式必须是 {"token": "xxx"} 因为这个接口是当作回调函数给Pusher IOS SDK调用的
|
|
public function generateToken($param): array
|
|
{
|
|
try {
|
|
if (!isset($param['user_id'])) {
|
|
return [
|
|
'token' => "缺少user_id",
|
|
];
|
|
}
|
|
$user = UserModel::where(['user_id'=>$param['user_id']])->find();
|
|
if (empty($user)) {
|
|
return [
|
|
'token' => "无效用户ID",
|
|
];
|
|
}
|
|
// 生成Beams身份验证令牌
|
|
$token = (new \app\utility\Pusher())->generateToken($param['user_id']);
|
|
return $token;
|
|
} catch (\Exception $exception) {
|
|
return $this->toData('500', lang('system_busy'), [$exception->getMessage(), $exception->getTrace()]);
|
|
}
|
|
}
|
|
public function pusherLog($param, $userId): array
|
|
{
|
|
try {
|
|
if (empty($param['page']) || !is_numeric($param['page'])) {
|
|
return $this->toData('400', lang('parameter_error'));
|
|
}
|
|
if (empty($param['limit']) || !is_numeric($param['limit'])) {
|
|
return $this->toData('400', lang('parameter_error'));
|
|
}
|
|
// 获取pusher推送记录
|
|
$list = PusherLogModel::where(['user_id'=>$userId])->order('id', 'desc')->paginate([
|
|
'list_rows' => $param['limit'],
|
|
'page' => $param['page'],
|
|
]);
|
|
return $this->toData('0', 'successful', [
|
|
'list' => $list->items(),
|
|
'total' => $list->total(),
|
|
'page' => $list->currentPage(),
|
|
'last_page' => $list->lastPage(),
|
|
'user_id' => $userId,
|
|
]);
|
|
|
|
} catch (\Exception $exception) {
|
|
return $this->toData('500', lang('system_busy'), [$exception->getMessage(), $exception->getTrace()]);
|
|
}
|
|
}
|
|
|
|
}
|