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.

30 lines
1.0 KiB

3 months ago
<?php
namespace app\home\service;
use app\model\UserModel;
class NoticeService extends BaseHomeService
{
3 months ago
// 生成Beams Token, 注意:返回结果的格式必须是 {"token": "xxx"} 因为这个接口是当作回调函数给Pusher IOS SDK调用的
3 months ago
public function generateToken($param): array
{
try {
3 months ago
if (!isset($param['user_id'])) {
return [
3 months ago
'token' => "缺少user_id",
];
}
$user = UserModel::where(['user_id'=>$param['user_id']])->find();
if (empty($user)) {
return [
'token' => "无效用户ID",
3 months ago
];
3 months ago
}
// 生成Beams身份验证令牌
$token = (new \app\utility\Pusher())->generateToken($param['user_id']);
3 months ago
return $token;
3 months ago
} catch (\Exception $exception) {
return $this->toData('500', lang('system_busy'), [$exception->getMessage(), $exception->getTrace()]);
}
}
}