Browse Source

切换新ws

林琦海 5 năm trước cách đây
mục cha
commit
801652e2e2

+ 3 - 1
app-hd/controllers/WsController.php

@@ -7,6 +7,7 @@
 namespace hd\controllers;
 
 use bizGhs\ws\services\WsService;
+use common\components\goWs;
 use common\components\util;
 use Yii;
 use GatewayClient\Gateway;
@@ -22,7 +23,8 @@ class WsController extends BaseController
         $post = Yii::$app->request->post();
         $clientId = isset($post['clientId']) ? $post['clientId'] : '';
         $shopAdminId = $this->shopAdminId;
-        Gateway::bindUid($clientId, $shopAdminId);
+        // Gateway::bindUid($clientId, $shopAdminId);
+        goWs::bindUid($shopAdminId,$clientId);
         util::complete();
     }
 

+ 9 - 4
biz-ghs/ws/services/WsService.php

@@ -4,6 +4,7 @@ namespace bizGhs\ws\services;
 
 use common\components\baiduAip;
 use common\components\dict;
+use common\components\goWs;
 use common\components\util;
 use GatewayClient\Gateway;
 use Yii;
@@ -19,11 +20,13 @@ class WsService
             try{
                 $audio = base64_encode($audio);
                 $data = ['type' => 'money','url'=>'data:audio/mp3;base64,'.$audio, 'msg' => $msg,'money'=>$money];
+                $dataString = json_encode($data);
+                goWs::sendToUid($adminId,$dataString);
                 //判断是否在线
                 // $online = Gateway::isUidOnline($adminId);
-                Gateway::sendToUid($adminId, json_encode($data));
-                $client = Gateway::getClientIdByUid($adminId);
-                Yii::info("getClientIdByUid res :".json_encode($client));
+                //Gateway::sendToUid($adminId, json_encode($data));
+                //$client = Gateway::getClientIdByUid($adminId);
+                //Yii::info("getClientIdByUid res :".json_encode($client));
 
             }catch (\Exception $exception){
                 Yii::warning("ws arrivalNotice error ". $exception->getMessage());
@@ -61,7 +64,9 @@ class WsService
         try{
             //判断是否在线
             //$online = Gateway::isUidOnline($shopAdminId);
-            Gateway::sendToUid($shopAdminId, json_encode($data));
+            $dataString = json_encode($data);
+            goWs::sendToUid($shopAdminId,$dataString);
+            //Gateway::sendToUid($shopAdminId, json_encode($data));
 //            if($online){
 //
 //            }else{

+ 2 - 2
common/components/freight.php

@@ -17,8 +17,8 @@ class freight
      * 10km < d <=50  每新增5km 加6
      *
      * 重量
-     * 0 <w <=5 kg  不加价
-     * 2kg < 2 <= 10 kg  每增1 kg 加2
+     * 0 <w <=2 kg  不加价
+     * 2kg < w <= 10 kg  每增1 kg 加2
      * 10 kg < w <= 50kg  每新增 5kg 加6
     */
     /**

+ 35 - 0
common/components/goWs.php

@@ -0,0 +1,35 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/5/29 22:25
+ */
+
+namespace common\components;
+
+use linslin\yii2\curl;
+class goWs
+{
+    public static function bindUid($uid,$clientId)
+    {
+        $path = '/bind?uid='.$uid.'&clientId='.$clientId;
+        self::request($path);
+    }
+
+    public static function sendToUid($uid,$msg){
+        $path = '/send?uid='.$uid.'&msg='.$msg;
+        self::request($path);
+    }
+
+    public static function request($path)
+    {
+        //暂时先写死
+        $url = '127.0.0.1:7777';
+        $url = $url.$path;
+        $curl = new curl\Curl();
+        $curl->setOptions([
+            CURLOPT_TIMEOUT => 2,
+            CURLOPT_CONNECTTIMEOUT => 2,
+        ]);
+        $curl->get($url);
+    }
+}