'el-icon-s-comment', ]; const STATUS_UNREAD = 0; //未读 const STATUS_READ = 1; //已读 const READ_STATUS = [ self::STATUS_UNREAD => '未读', self::STATUS_READ => '已读', ]; const PLATFORM_LIST = [ self::PLAT_FORM_ADMIN => '管理后台', self::PLAT_FORM_PINGAN => '平安', self::PLAT_FORM_WXAPP => '微信小程序', ]; // 系统账号 const SEND_UID_SYS = 8888888; public function __construct() { parent::__construct($this->table_name, 'default'); } /** * 添加系统通知 * @param Array $params platform,uid,content,type,url * @param $sendPlatform * @param $sendUid * @param $showWssErr * @return MyResponse */ public function addNotice($params, $sendPlatform, $sendUid = self::SEND_UID_SYS, $showWssErr = false) { $logPath = 'websocket'; $logFile = 'sendError.txt'; try { if (!$params['platform'] || !$params['uid'] || !$params['content'] || !$sendPlatform) { throw new Exception('参数错误'); } $addData = [ 'platform' => $params['platform'], 'uid' => $params['uid'], 'content' => $params['content'], 'type' => $params['type'] ?: 0, 'url' => $params['url'] ?: '', 'c_time' => time(), 'send_platform' => $sendPlatform, 'send_uid' => $sendUid ]; $addData['icon'] = self::ICON_TYPE[$params['type']] ?: self::ICON_DEFAULT; $req = $this->add($addData); if (!is_numeric($req)) { throw new Exception('添加失败'); } $this->load->model('ws/ws_conn_model'); $this->load->library('websocket/wsClient', ['platform' => $sendPlatform, 'uid' => $sendUid]); //websocket推送 $requestId = uniqid(); $data = [ 'id' => $req, 'icon' => $addData['icon'], 'url' => $addData['url'], 'type' => $addData['type'], 'read' => 0, 'content' => $addData['content'], 'c_time' => date('Y-m-d H:i:s') ]; /** @var MyResponse $websocketRes */ $websocketRes = $this->wsclient->sendMessage($requestId, $addData['platform'], $addData['uid'], $data); if (!$websocketRes->isSuccess()) { if ($showWssErr) { throw new Exception("发送socket消息失败:{$websocketRes->getMessage()}"); } debug_log($websocketRes->getMessage(), $logFile, $logPath); } return new MyResponse(EXIT_SUCCESS, 'success'); } catch (Exception $e) { return new MyResponse(EXIT_ERROR, $e->getMessage()); } } }