shish 9 ヶ月 前
コミット
53a60fa73e

+ 8 - 3
app-ghs/controllers/TestController.php

@@ -39,13 +39,17 @@ use wkhtmltox\Image\Converter;
 class TestController extends BaseController
 {
 
-    public $guestAccess = ['rabbit','recharge', 'fx', 'on', 'in', 'clear-query', 'ip', 'html', 'debt', 'apply', 'clear', 'ls-trade-query', 'ls-trade-refund', 'refund-query', 'inform', 'notice', 'order-query', 'add-order', 'index', 'get', 'trade-query', 'query', 'balance-query', 'refund', 'recharge-query', 'sim', 'push', 'code'];
+    public $guestAccess = ['rabbit', 'recharge', 'fx', 'on', 'in', 'clear-query', 'ip', 'html', 'debt', 'apply', 'clear', 'ls-trade-query', 'ls-trade-refund', 'refund-query', 'inform', 'notice', 'order-query', 'add-order', 'index', 'get', 'trade-query', 'query', 'balance-query', 'refund', 'recharge-query', 'sim', 'push', 'code'];
 
     public function actionRabbit()
     {
         $producer = Yii::$app->rabbitmq->getProducer('importDataProducer');
-        $msg = serialize(['user_id' => rand(111,999)]);
+        $msg = serialize(['user_id' => rand(111, 999)]);
         $producer->publish($msg, 'ex1', 'route1');
+
+        $producer = Yii::$app->rabbitmq->getProducer('notifyConsumer');
+        $msg = serialize(['type' => 'order_new', 'msg' => '你有新订单']);
+        $producer->publish($msg, 'notifyExchange', 'notifyRoute');
     }
 
     public function actionFx()
@@ -232,7 +236,8 @@ class TestController extends BaseController
             $ip = $_SERVER['SERVER_ADDR'] ?? '';
             echo $ip;
         } else {
-            phpinfo();die;
+            phpinfo();
+            die;
         }
     }
 

+ 20 - 17
common/components/rabbitmq/consumer/notifyConsumer.php

@@ -6,6 +6,7 @@
 
 namespace common\components\rabbitmq\consumer;
 
+use common\components\noticeUtil;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 use Yii;
@@ -14,10 +15,10 @@ class notifyConsumer implements ConsumerInterface
 {
     /**
      * 执行消费者逻辑
-     * 
+     *
      * @param AMQPMessage $msg 消息对象
      * @return string 消息处理结果
-     * 
+     *
      * ConsumerInterface::MSG_ACK - 确认消息(标记为已处理)并从队列中删除
      * ConsumerInterface::MSG_REJECT - 拒绝并从队列中删除消息
      * ConsumerInterface::MSG_REQUEUE - 拒绝并重新入队消息
@@ -27,14 +28,14 @@ class notifyConsumer implements ConsumerInterface
         try {
             // 反序列化消息体
             $data = json_decode($msg->body, true);
-            
+
             if (!is_array($data)) {
                 Yii::error("Invalid notify message format: {$msg->body}", 'rabbitmq.notify');
                 return ConsumerInterface::MSG_REJECT;
             }
-            
+
             Yii::info("Processing notify message: " . json_encode($data), 'rabbitmq.notify');
-            
+
             // 根据通知类型分发处理
             $type = $data['type'] ?? null;
             switch ($type) {
@@ -57,7 +58,7 @@ class notifyConsumer implements ConsumerInterface
                     Yii::warning("Unknown notify type: {$type}", 'rabbitmq.notify');
                     $result = false;
             }
-            
+
             if ($result) {
                 Yii::info("Notify message processed successfully", 'rabbitmq.notify');
                 return ConsumerInterface::MSG_ACK;
@@ -65,16 +66,16 @@ class notifyConsumer implements ConsumerInterface
                 Yii::error("Notify message processing failed", 'rabbitmq.notify');
                 return ConsumerInterface::MSG_REQUEUE;
             }
-            
+
         } catch (\Exception $e) {
             Yii::error("Notify consumer exception: " . $e->getMessage(), 'rabbitmq.notify');
             return ConsumerInterface::MSG_REQUEUE;
         }
     }
-    
+
     /**
      * 处理新订单通知
-     * 
+     *
      * @param array $data 消息数据,包含 order_id, customer_id 等
      * @return bool 处理结果
      */
@@ -83,12 +84,14 @@ class notifyConsumer implements ConsumerInterface
         // TODO: 实现新订单通知业务逻辑
         // 调用对应的 Service 或 Class 层处理
         // 例如: 发送短信、推送通知、邮件等
+        $msg = $data['msg'] ?? '';
+        noticeUtil::push($msg, '15280215347');
         return true;
     }
-    
+
     /**
      * 处理新客户通知
-     * 
+     *
      * @param array $data 消息数据,包含 customer_id 等
      * @return bool 处理结果
      */
@@ -99,10 +102,10 @@ class notifyConsumer implements ConsumerInterface
         // 例如: 发送欢迎短信、邮件等
         return true;
     }
-    
+
     /**
      * 处理客户充值通知
-     * 
+     *
      * @param array $data 消息数据,包含 customer_id, amount, recharge_no 等
      * @return bool 处理结果
      */
@@ -113,10 +116,10 @@ class notifyConsumer implements ConsumerInterface
         // 例如: 发送充值成功通知、更新余额等
         return true;
     }
-    
+
     /**
      * 处理客户销账通知
-     * 
+     *
      * @param array $data 消息数据,包含 customer_id, amount, writeoff_no 等
      * @return bool 处理结果
      */
@@ -127,10 +130,10 @@ class notifyConsumer implements ConsumerInterface
         // 例如: 发送销账成功通知、更新账户信息等
         return true;
     }
-    
+
     /**
      * 处理配送状态变更通知
-     * 
+     *
      * @param array $data 消息数据,包含 order_id, status, status_desc 等
      * @return bool 处理结果
      */