林琦海 hace 5 años
padre
commit
7f1d1734b4
Se han modificado 2 ficheros con 21 adiciones y 3 borrados
  1. 9 3
      biz-ghs/ws/services/WsService.php
  2. 12 0
      common/components/oss.php

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

@@ -5,6 +5,7 @@ namespace bizGhs\ws\services;
 use common\components\baiduAip;
 use common\components\dict;
 use common\components\goWs;
+use common\components\oss;
 use common\components\util;
 use GatewayClient\Gateway;
 use Yii;
@@ -16,10 +17,16 @@ class WsService
         $msg = '微信到账'.$money;
         $audio = baiduAip::transfer($msg,4,0);
         Yii::info("触发到账通知:".$adminId. " ".$money);
+
         if(!is_array($audio)){
             try{
-                $audio = base64_encode($audio);
-                $data = ['type' => 'money','url'=>'data:audio/wav;base64,'.$audio, 'msg' => $msg,'money'=>$money];
+                //上传到oss
+                $file =time().rand(10000,999999).'.mp3';
+                $filePath = 'tmp/arrival/money/'.$file;
+                oss::uploadTmpAudio($filePath,$audio);
+                $url = 'https://oss-cn-hangzhou.aliyuncs.com/'.$filePath;
+                // $audio = base64_encode($audio);
+                $data = ['type' => 'money','url'=>$url, 'msg' => $msg,'money'=>$money];
                 $dataString = json_encode($data);
                 goWs::sendToUid($adminId,$dataString);
                 //判断是否在线
@@ -32,7 +39,6 @@ class WsService
                 Yii::warning("ws arrivalNotice error ". $exception->getMessage());
             }
         }else{
-
             Yii::warning("到账通知 语音获取失败" .json_encode($audio));
         }
 

+ 12 - 0
common/components/oss.php

@@ -61,4 +61,16 @@ class oss
     {
         return Yii::$app->params['hdImgHost']. $object . "?x-oss-process=image/watermark,". implode('/watermark,', $process);
     }
+
+    //上传语音
+    public static function uploadTmpAudio($object, $filePath,$bucket = 'hhb-tmp-audio')
+    {
+        $ossClient = self::getOssClient();
+        try {
+            $ossClient->putObject($bucket, $object, $filePath);
+        } catch (OssException $e) {
+            util::fail($e->getMessage());
+        }
+        return true;
+    }
 }