public function testAdd() { $media = new Media(Config::APPID, Config::APPSECRET); $banner = $media->forever()->lists('image'); $shelfData = $this->shelf(); $shelf = new Shelf(Config::get()); $response = $shelf->add(function (ShelfData $shelf) use($shelfData) { return $shelfData; }, file_get_contents('/home/pjxh/图片/pic_logo_1082168b92.png'), 'test'); $this->assertTrue($response); return $response; }
/** * 下载素材到本地. * * @param AccountModel $account 公众号 * @param string $type 素材类型 * @param string $mediaId 素材 * * @return mixed */ private function downloadMaterial($account, $type, $mediaId) { $dateDir = date('Ym') . '/'; $dir = config('material.' . $type . '.storage_path') . $dateDir; $mediaService = new MediaService($account->app_id, $account->app_secret); $name = md5($mediaId); is_dir($dir) || mkdir($dir, 0755, true); //如果属于视频类型 if ($type == 'video') { $videoInfo = $mediaService->forever()->download($mediaId); //取消下载Mp4文件 return ['title' => $videoInfo['title'], 'description' => $videoInfo['description'], 'local_url' => '', 'media_id' => $mediaId]; } else { $dirFilename = $mediaService->forever()->download($mediaId, $dir . $name); $fileName = explode('/', $dirFilename); $fileName = array_pop($fileName); return config('material.' . $type . '.prefix') . '/' . $dateDir . $fileName; } }