Browse Source

讲解设置直播间属性

lizhen_gitee 2 months ago
parent
commit
97f79be638

+ 25 - 2
addons/shopro/controller/goods/Liveroom.php

@@ -5,6 +5,7 @@ namespace addons\shopro\controller\goods;
 use addons\shopro\controller\Common;
 use addons\shopro\service\goods\GoodsService;
 use think\Db;
+use app\utils\Service\Tencent\TencentIm;
 
 class Liveroom extends Common
 {
@@ -194,8 +195,15 @@ class Liveroom extends Common
             $this->error('该商品已下架');
         }
 
-        $goods = collection($goods)->toArray();
-        $goods = info_domain_image($goods,['image']);//主图
+        //精简商品
+        $goods = json_decode(json_encode($goods),true);
+        $goods = [
+            'id'    => $goods['id'],
+            'title' => $goods['title'],
+            'image' => localpath_to_netpath($goods['image']),
+            'price' => $goods['price'],
+            'is_sku'=> $goods['is_sku'],
+        ];
 
         //其他取消讲解,讲解这个
         $goods_id = input('goods_id',0,'intval');
@@ -203,10 +211,25 @@ class Liveroom extends Common
         Db::name('live_room_goods')->where('room_no',$room_no)->where('goods_id',$goods_id)->update(['is_top'=>1]);
 
         //修改房间属性
+        $top_good[] = [
+            'key' => 'top_good',
+            'value' => json_encode($goods),
+        ];
+        $im = new TencentIm();
+        $im->modify_group_attr($room_no,$top_good);
 
 
         $this->success('操作成功');
 
     }
 
+    //获取属性
+    public function get_room_attr(){
+        $room_no = input('room_no','','trim');
+
+        $im = new TencentIm();
+        $im->get_group_attr($room_no);
+        dump($im->getData());
+    }
+
 }

+ 4 - 4
application/config.php

@@ -339,14 +339,14 @@ return [
 
     //腾讯云 IM
     'tencent_im' => [
-        'sdkappid' => '',
-        'identifier' => '',
+        'sdkappid' => '1600058971',
+        'identifier' => 'administrator',
         //trtc回调秘钥
         'callback_secret' => '',
-        'key' => '',
+        'key' => '0adf5557cf0b52ff0e3acc0c4c6a52100b0ae86a5cf97b758e1ff1ed68f8e969',
         'SecretId' => '',
         'SecretKey' => '',
-        'chat_prefix' => Env::get('tencent_im.IM_CHAT_PREFIX','im'),
+        'chat_prefix' => Env::get('tencent_im.IM_CHAT_PREFIX','xiaoshan'),
     ],
 
     //阿里云短信配置

+ 37 - 0
application/utils/Service/Tencent/TencentIm.php

@@ -502,6 +502,43 @@ class TencentIm extends Module
         return "rtmp://".$domain."/live/".$streamName;
     }
 
+    /**
+     * 设置群属性
+     * @param int $room_no
+     * @param array $attr
+     * @return bool
+     */
+    public function modify_group_attr( $room_no, array $attr)
+    {
+        $data     = [
+            'GroupId'   => (string)$room_no,// 群组 ID
+            'GroupAttr' => $attr
+        ];
+        $res  = $this->postJson('/v4/group_open_http_svc/modify_group_attr', $data);
+        if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
+            return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
+        }
+
+        return $this->success('获取成功', $res);
+    }
+
+    /**
+     * 获取群属性
+     * @param int $room_no
+     */
+    public function get_group_attr( $room_no)
+    {
+        $data     = [
+            'GroupId'   => (string)$room_no,// 群组 ID
+        ];
+        $res  = $this->postJson('/v4/group_open_attr_http_svc/get_group_attr', $data);
+        if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
+            return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
+        }
+
+        return $this->success('获取成功', $res);
+    }
+
     // 下载最近消息记录
     public function get_history($MsgTime,$ChatType = 1)
     {