123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2018/9/7
- * Time: 上午10:06
- */
- namespace room;
- use Exception;
- use Log;
- use member_info;
- class pusher
- {
- private static $stInstance;
- private function __construct()
- {
- }
- public static function instance()
- {
- if(self::$stInstance == null) {
- self::$stInstance = new pusher();
- }
- return self::$stInstance;
- }
- public function new_friend($receiver,$user)
- {
- try
- {
- $minfo = new member_info($user);
- $from = ['nickname' => $minfo->nickname(),'avatar' => $minfo->avatar(),'userid' => intval($user)];
- $content = ['type' => 'new_friend','from' => $from];
- factory_client::instance()->notice_users([$receiver],proto_type::push_command,$content,'');
- }
- catch (Exception $ex) {
- Log::record($ex->getMessage(),Log::ERR);
- }
- }
- public function kick_room($room,$kicks)
- {
- try
- {
- $content = ['type' => 'kick_room','room' => $room];
- factory_client::instance()->notice_users($kicks,proto_type::push_command,$content,'');
- }
- catch (Exception $ex) {
- Log::record($ex->getMessage(),Log::ERR);
- }
- }
- //state = pending,accept,refuse
- public function apply_friend($applicant,$friend,$note)
- {
- try
- {
- $minfo = new member_info($applicant);
- $from = ['nickname' => $minfo->nickname(),'avatar' => $minfo->avatar(),'userid' => intval($applicant)];
- $content = ['type' => 'apply_friend','from' => $from,'note' => $note,'state' => 'pending'];
- $msg = "{$minfo->nickname()} 请求加您为好友.";
- factory_client::instance()->notice_users([$friend],proto_type::push_apply,$content,$msg);
- }
- catch (Exception $ex) {
- Log::record($ex->getMessage(),Log::ERR);
- }
- }
- //state = pending,accept,refuse
- public function apply_room($applicant,$roomid,$note)
- {
- try
- {
- $minfo = new member_info($applicant);
- $from = ['nickname' => $minfo->nickname(),'avatar' => $minfo->avatar(),'userid' => intval($applicant)];
- $content = ['type' => 'apply_room','from' => $from,'note' => $note,'room_id' => $roomid,'state' => 'pending'];
- $room = $this->get_room($roomid);
- if($room == false) return;
- $msg = "{$minfo->nickname()} 申请加入 {$room->name()}";
- factory_client::instance()->notice_users([$room->creator()],proto_type::push_apply,$content,$msg);
- }
- catch (Exception $ex) {
- Log::record($ex->getMessage(),Log::ERR);
- }
- }
- public function cert_notice($roomid, $state, $note)
- {
- try
- {
- $room = $this->get_room($roomid);
- if($room == false) return;
- $name = \util::ellipsis($room->name());
- if($state) {
- $msg = "群: {$name} 申请的认证被通过";
- $state = "accept";
- } else {
- $msg = "群: {$name} 申请的认证被拒绝";
- $state = "refuse";
- }
- $from = ['nickname' => $name,'avatar' => $room->avatar(),'room_id' => intval($roomid)];
- $content = ['type' => 'cert_notice','from'=>$from,'note' => $note,'room_id' => $roomid,"state"=>$state];
- factory_client::instance()->notice_users([$room->owner()],proto_type::push_apply,$content,$msg);
- }
- catch (Exception $ex) {
- Log::record($ex->getMessage(),Log::ERR);
- }
- }
- private function get_room($roomid)
- {
- $roomid = intval($roomid);
- if($roomid <= 0) return false;
- $mod_room = Model('room');
- $item = $mod_room->getRoom($roomid);
- if(empty($item)) return false;
- return new room_info($item);
- }
- }
|