stanley-king 6 éve
szülő
commit
35cd43bb93

+ 0 - 13
helper/push_helper.php

@@ -166,18 +166,6 @@ class push_helper
     {
         $amount = intval($money * 100 + 0.5) / 100;
         return "{$amount}元";
-
-//        $discount = 100 - $rate;
-//        if($discount == 0) {
-//            $desc = "全抵";
-//        } else {
-//            $tmp = $discount / 10;
-//            $desc = "{$tmp}折";
-//        }
-//
-//        $desc = "可抵扣";
-//        $amount = intval($money * 100 + 0.5) / 100;
-//        return "{$amount}元{$desc}";
     }
 
     private static function push($alias, $push_param, $sms_type='',$sms_param=[], $fQueue=false)
@@ -838,7 +826,6 @@ class push_helper
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function poor_user_bonus($user, $money, $rate, $type_sn, $fQueue=false)
     {
-//      $url = self::pushurl() . "&op=bonus&type_sn={$type_sn}";
         $desc = self::money_rate_desc($money,$rate);
         $text = "您的红包余额不足,好心人紧急为您充值{$desc}红包~";
 

+ 4 - 6
helper/room/factory_client.php

@@ -162,24 +162,23 @@ class factory_client extends tcp_client
         }
     }
 
-    public function notice_all($type,$content)
+    public function notice_all($type,$content,$msg)
     {
-        $param = ["act" => 'fcgi','op' => 'notice_all','type' => $type,'content' => $content];
+        $param = ["act" => 'fcgi','op' => 'notice_all','type' => $type,'content' => $content,'msg' => $msg];
         $result = $this->request($param);
         if(empty($result)) return false;
 
         $code = intval($result['code']);
         if($code != 200) {
-
             return false;
         } else {
             return true;
         }
     }
 
-    public function notice_user($user,$type,$content)
+    public function notice_users($users,$type,$content,$msg)
     {
-        $param = ["act" => 'fcgi','op' => 'notice_user','user' => $user,'type' => $type,'content' => $content];
+        $param = ["act" => 'fcgi','op' => 'notice_users','users' => $users,'type' => $type,'content' => $content,'msg' => $msg];
         $result = $this->request($param);
         if(empty($result)) return false;
 
@@ -204,7 +203,6 @@ class factory_client extends tcp_client
             return true;
         }
     }
-
     //////////////////////////////////////access////////////////////////////////////////////////////////////////////////
     public function access()
     {

+ 25 - 5
helper/room/factory_processor.php

@@ -242,18 +242,23 @@ class factory_processor implements IProcessor
         {
             $content = $input['content'];
             $type = $input['type'];
+            $msg = $input['msg'];
 
-            $ret = $this->push($content);
+            $ret = $this->notice_all($type,$content,$msg);
             if($ret != false) {
                 return $this->success(NULL);
             } else {
                 return $this->error(errcode::ErrRoomPush);
             }
         }
-        elseif($op == 'notice_user')
+        elseif($op == 'notice_users')
         {
             $content = $input['content'];
-            $ret = $this->push($content);
+            $type = $input['type'];
+            $users = $input['users'];
+            $msg = $input['msg'];
+
+            $ret = $this->notice_users($users,$type,$content,$msg);
             if($ret != false) {
                 return $this->success(NULL);
             } else {
@@ -400,14 +405,29 @@ class factory_processor implements IProcessor
         }
     }
 
-    private function push($content)
+    private function notice_all($type,$content,$msg)
+    {
+        $bufid = $this->room_bufid();
+        if($bufid != false)
+        {
+            $client = $this->mBufidRooms[$bufid];
+            $this->block($bufid);
+            $client->notice_all($type,$content,$msg);
+            $this->unblock($bufid);
+            return true;
+        }
+
+        return false;
+    }
+
+    private function notice_users($users,$type,$content,$msg)
     {
         $bufid = $this->room_bufid();
         if($bufid != false)
         {
             $client = $this->mBufidRooms[$bufid];
             $this->block($bufid);
-            $ret = $client->push($content);
+            $client->notice_users($users,$type,$content,$msg);
             $this->unblock($bufid);
             return true;
         }

+ 9 - 0
helper/room/proto_type.php

@@ -49,6 +49,11 @@ class proto_type
     const acc_native_type = "native";
     const acc_all_type = "all";
 
+    //push消息分类
+    const push_command   = 1;
+    const push_notify    = 2;
+    const push_apply     = 3;
+
 
     //[1,20) 基本的消息
     const msg_stype_text  = 'text';
@@ -78,6 +83,10 @@ class proto_type
     const msg_type_bargain    = 20;
     const msg_type_shakebonus = 21;
 
+    const msg_type_command = 50;
+    const msg_type_nofity  = 51;
+    const msg_type_apply   = 52;
+
     static public function to_msgtype($type)
     {
         $stype = strtolower($type);

+ 94 - 0
helper/room/pusher.php

@@ -0,0 +1,94 @@
+<?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);
+        }
+    }
+
+    //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);
+        }
+    }
+
+    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);
+    }
+
+
+}

+ 28 - 0
helper/room/room_client.php

@@ -178,6 +178,34 @@ class room_client extends tcp_client
         }
     }
 
+    public function notice_all($type,$content,$msg)
+    {
+        $param = ["act" => 'factory','op' => 'notice_all','type' => $type,'content' => $content,'msg' => $msg];
+        $result = $this->request($param);
+        if(empty($result)) return false;
+
+        $code = intval($result['code']);
+        if($code != 200) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public function notice_users($users,$type,$content,$msg)
+    {
+        $param = ["act" => 'factory','op' => 'notice_users','users' => $users,'type' => $type,'content' => $content,'msg' => $msg];
+        $result = $this->request($param);
+        if(empty($result)) return false;
+
+        $code = intval($result['code']);
+        if($code != 200) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
     public function message($room,$user,$type,$content)
     {
         $param = ["act" => 'room','op' => 'message','room' => $room,'user' => $user,'type' => $type,'content' => $content];

+ 80 - 4
helper/room/room_processor.php

@@ -95,8 +95,8 @@ class room_processor implements IProcessor
         elseif($op == 'notice_room') {
             return $this->factory_notice_room($bufid,$input);
         }
-        elseif($op == 'notice_user') {
-            return $this->factory_notice_user($bufid,$input);
+        elseif($op == 'notice_users') {
+            return $this->factory_notice_users($bufid,$input);
         }
         elseif($op == 'notice_all') {
             return $this->factory_notice_all($bufid,$input);
@@ -300,20 +300,68 @@ class room_processor implements IProcessor
         return $this->error(errcode::ErrRoomChange);
     }
 
-    private function factory_notice_user($bufid, $input)
+    ///Push消息处理区/////////////////////////////////////////////////////////////////////////////////////////////////////
+    private function factory_notice_users($bufid, $input)
     {
+        $content = $input['content'];
+        $msg = $input['msg'];
+        $users = $input['users'];
+
+        $type = $input['type'];
+        if($type === proto_type::push_command) {
+            $pushid = 1;
+            $msg_type = proto_type::msg_type_command;
+            $send = $content;
+        }
+        elseif($type === proto_type::push_notify) {
+            $pushid = 2;
+            $msg_type = proto_type::msg_type_nofity;
+            $send = $msg;
+        }
+        elseif($type === proto_type::push_apply) {
+            $pushid = 3;
+            $msg_type = proto_type::msg_type_apply;
+            $send = $msg;
+        }
+        else {
+            return $this->error(errcode::ErrParamter);
+        }
+
+        if($msg_type != proto_type::msg_type_command)
+        {
+            $mod_room = Model('room');
 
+            $orgmsg = json_encode($content);
+            foreach ($users as $user) {
+                $mod_room->addRoomMsg(['room_id' => 0,'member_id' => $user, 'type' => $msg_type,'msg' => $msg, 'orgmsg' => $orgmsg, 'add_time' => time(),'msg_type' => 1]);
+            }
+        }
+
+        $this->write_push_users($pushid,$users,$send);
+
+        return $this->success(NULL);
     }
 
     private function factory_notice_all($bufid, $input)
     {
         $content = $input['content'];
         $type = $input['type'];
+        if($type === proto_type::push_command) {
+            $pushid = 1;
+        }
+        elseif($type === proto_type::push_notify) {
+            $pushid = 2;
+        }
+        elseif($type === proto_type::push_apply) {
+            $pushid = 3;
+        }
+        else {
+            return $this->error(errcode::ErrParamter);
+        }
 
         $this->write_push($content);
         return $this->success(NULL);
     }
-
     ////////////////////////////////////////Access Message Handler//////////////////////////////////////////////////////
     private function onAccess($bufid,$input)
     {
@@ -377,6 +425,30 @@ class room_processor implements IProcessor
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    private function write_push_users($pushid,$users,$content)
+    {
+        $msg = [];
+
+        $msg['act']  = "room";
+        $msg['op']   = "relay";
+        $msg['relay_type'] = "users";
+        $msg['receivers'] = $users;
+        $msg['room'] = 0;
+        $msg['receiver_type'] = proto_type::sroom_push;
+        $msg['msgtype'] = "message";
+
+
+        $msg['body']['act']  = proto_type::act_push;
+        $msg['body']['op']   = 'message';
+        $msg['body']['push']   = $pushid;
+        $msg['body']['content'] = $content;
+        $msg['body']['msgtype'] = "message";
+
+        $body = json_encode($msg);
+        foreach ($this->mAccConnes as $conn) {
+            process_looper::instance()->write($conn,$body);
+        }
+    }
     private function write_push($content)
     {
         $msg = [];
@@ -387,10 +459,14 @@ class room_processor implements IProcessor
         $msg['receivers'] = [];
         $msg['room'] = 0;
         $msg['receiver_type'] = proto_type::sroom_push;
+        $msg['msgtype'] = "message";
+
 
         $msg['body']['act']  = proto_type::act_push;
         $msg['body']['op']   = 'message';
+        $msg['body']['push']   = 0;
         $msg['body']['content'] = $content;
+        $msg['body']['msgtype'] = "message";
 
         $body = $this->success($msg);
         foreach ($this->mAccConnes as $conn) {

+ 1 - 1
helper/room/util.php

@@ -103,8 +103,8 @@ class talks_helper
         $chatwo_list = $this->chatwo_list($chatid_others,$chatwo_msgs,$params['chatwos']);
 
         $talk_list = [];
-        $talk_list[] = ['talk_type' => 'push','talk_id' => 1,'count' => 0,'msg_id' => 0];
         $talk_list[] = ['talk_type' => 'push','talk_id' => 2,'count' => 0,'msg_id' => 0];
+        $talk_list[] = ['talk_type' => 'push','talk_id' => 3,'count' => 0,'msg_id' => 0];
 
         $talks = array_merge($room_list,$chatwo_list);
         usort($talks,['room\sorter','msgid_desc']);

+ 1 - 0
helper/room_helper.php

@@ -20,6 +20,7 @@ require_once(BASE_ROOT_PATH . '/helper/room/room_client.php');
 require_once(BASE_ROOT_PATH . '/helper/room/bargain_manager.php');
 require_once(BASE_ROOT_PATH . '/helper/room/room_parts.php');
 require_once(BASE_ROOT_PATH . '/helper/room/room_avatar.php');
+require_once(BASE_ROOT_PATH . '/helper/room/pusher.php');
 
 class room_helper
 {

+ 7 - 6
mobile/control/game.php

@@ -25,19 +25,20 @@ class gameControl extends mbMemberControl
         global $config;
         $room_id = $config['special_rooms']['shake_bonus'];
         $webaddr = $config['access_addr'];
+        $userid = session_helper::memberid();
+
         $creator = self::shake_creator($room_id);
-        $ret = room\factory_client::instance()->invite($room_id,$creator,[session_helper::memberid()]);
+        $ret = room\factory_client::instance()->invite($room_id,$creator,[$userid]);
 
         $result = [];
         if($ret != false) {
             $result['addr'] = $webaddr;
-            $result['token'] = room\author::sign_web($room_id,session_helper::memberid());
-            $result['room'] = $room_id;
-            $result['user'] = session_helper::memberid();
+            $result['token'] = room\author::sign_web($room_id,$userid);
+            $result['room'] = intval($room_id);
+            $result['user'] = $userid;
         }
 
-        $_SESSION['client_type'] = "wap";
-        return self::outsuccess($result,"game/shake_bonus");
+        return self::outsuccess($result);
     }
 
     public function test_shakeOp()

+ 0 - 34
mobile/control/member_talk.php

@@ -42,40 +42,6 @@ class member_talkControl extends mbMemberControl
         return self::outsuccess($result);
     }
 
-    public function authon_webOp()
-    {
-        global $config;
-        $room_id = $config['special_rooms']['shake_bonus'];
-        $webaddr = $config['access_addr'];
-        $userid = session_helper::memberid();
-
-        $creator = self::shake_creator($room_id);
-        $ret = room\factory_client::instance()->invite($room_id,$creator,[$userid]);
-
-        $result = [];
-        if($ret != false) {
-            $result['addr'] = $webaddr;
-            $result['token'] = room\author::sign_web($room_id,$userid);
-            $result['room'] = intval($room_id);
-            $result['user'] = $userid;
-        }
-
-        return self::outsuccess($result);
-    }
-
-    static private function shake_creator($room_id)
-    {
-        $mod_room = Model('room');
-        $params = $mod_room->getRoom($room_id);
-        if (!empty($params)) {
-            $rinfo = new room\room_info($params);
-            return $rinfo->creator();
-        }
-        else {
-            return false;
-        }
-    }
-
     public function talksOp()
     {
         $talks_helper = new room\talks_helper();

+ 10 - 0
test/TestRoomFactory.php

@@ -139,6 +139,7 @@ class TestRoomFactory extends PHPUnit_Framework_TestCase
     {
         $ret = room\factory_client::instance()->notice_room(291,\room\proto_type::msg_stype_donate,['user' => 39653,'steps' => 100,'amount' => 1]);
     }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     private function creator($room_id)
     {
@@ -147,4 +148,13 @@ class TestRoomFactory extends PHPUnit_Framework_TestCase
         $rinfo = new room\room_info($params);
         return $rinfo->creator();
     }
+
+    public function testNotifyCommand()
+    {
+        room\pusher::instance()->new_friend(39623,39668);
+    }
+    public function testApplyFriend()
+    {
+        room\pusher::instance()->apply_friend(39623,39668);
+    }
 }