page - 1) * $this->limit; $wechat = Wechat::getWechat(); if (!is_array($wechat) || !isset($wechat['code'])) { return $wechat->broadcast->getRooms($start, $this->limit); } else { return [ 'errcode' => 1 ]; } } public function deleteRoom() { $wechat = Wechat::getWechat(); return $wechat->broadcast->deleteLiveRoom([ 'id' => $this->roomId, ]); } public function getHuifang() { $wechat = Wechat::getWechat(); return $wechat->broadcast->getPlaybacks($this->roomid, 0, 10); } public function getMedia() { $file = $this->file; $root_url = $this->saveTempImage($file); $wechat = Wechat::getWechat(); return $wechat->media->upload('image', $root_url); } public function submitLive() { set_time_limit(0); $wechat = Wechat::getWechat(); $coverImg = trim($this->data['coverImg']); $coverImgPath = $this->saveTempImage($coverImg); $coverImgMedia = $wechat->media->upload('image', $coverImgPath); if (isset($coverImgMedia['errcode'])) { return $coverImgMedia; } $shareImg = trim($this->data['shareImg']); $shareImgPath = $this->saveTempImage($shareImg); $shareImgMedia = $wechat->media->upload('image', $shareImgPath); if (isset($shareImgMedia['errcode'])) { return $shareImgMedia; } $feedsImg = trim($this->data['feedsImg']); $feedsImgPath = $this->saveTempImage($feedsImg); $feedsImgMedia = $wechat->media->upload('image', $feedsImgPath); if (isset($feedsImgMedia['errcode'])) { return $feedsImgMedia; } $postData = [ 'type' => 1, 'name' => trim($this->data['name']), 'coverImg' => $coverImgMedia['media_id'], 'shareImg' => $shareImgMedia['media_id'], 'feedsImg' => $feedsImgMedia['media_id'], 'startTime' => strtotime(trim($this->data['startTime'])), 'endTime' => strtotime(trim($this->data['endTime'])), 'anchorName' => trim($this->data['anchorName']), 'anchorWechat' => trim($this->data['anchorWechat']), 'closeComment' =>intval( $this->data['closeComment']), 'closeLike' => intval($this->data['closeLike']), 'closeGoods' => intval($this->data['closeGoods']), 'closeReplay' => intval($this->data['closeReplay']), 'closeShare' => intval($this->data['closeShare']), 'closeKf' => intval($this->data['closeKf']), ]; $wechat = Wechat::getWechat(); return $wechat->broadcast->createLiveRoom($postData); } public function addGoods() { if (empty($this->goods_id)) { return [ 'code' => 1, 'msg' => '请选择商品' ]; } $goods_id = $this->goods_id; $postData = [ 'ids' => $goods_id, 'roomId' => trim($this->roomId) ]; $wechat = Wechat::getWechat(); return $wechat->broadcast->addGoods($postData); } //获取网络图片到临时目录 private function saveTempImage($url) { if (strpos($url,'http') === false) { $url = 'http:'. trim($url); } if (!is_dir(\Yii::$app->runtimePath . '/image')) { mkdir(\Yii::$app->runtimePath . '/image'); } $save_path = \Yii::$app->runtimePath . '/image/' . md5($url) . '.jpg'; CurlHelper::download($url, $save_path); return $save_path; } /** * 获取已经审核通过的商品列表 * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function getGoodsList() { $wechat = Wechat::getWechat(); $start = ($this->page - 1) * $this->limit; return $wechat->broadcast->getApproved([ 'offset' => $start, 'limit' => $this->limit, 'status' => 2 ]); } }