sendError('文件不存在.', 404); } return $this->upload($file, 'image'); } /** * @param $file * @return bool|mixed|Result */ public function VoiceUpload($file) { if (!file_exists($file)) { return $this->sendError('文件不存在.', 404); } return $this->upload($file, 'voice'); } /** * @param $file * @return bool|mixed|Result */ public function VideoUpload($file) { if (!file_exists($file)) { return $this->sendError('文件不存在.', 404); } return $this->upload($file, 'video'); } /** * @param $file * @return bool|mixed|Result */ public function ThumbUpload($file) { if (!file_exists($file)) { return $this->sendError('文件不存在.', 404); } return $this->upload($file, 'thumb'); } /** * @param $media_id * @return array|mixed|Result */ public function MediaGet($media_id) { $client = HttpClient::NewRequest(); $accessToken = $this->config->getAccessToken(); return $client->get($this->getUploadUrl, ['access_token' => $accessToken, 'media_id' => $media_id]); } /** * @param $file * @param $type * @return bool|mixed */ private function upload($file, $type) { $uploadInfo['media'] = new \CURLFile($file); $uploadInfo['form-data[filename]'] = $uploadInfo['media']->getFilename(); $uploadInfo['form-data[content-type]'] = $uploadInfo['media']->getMimeType(); $accessToken = $this->config->getAccessToken(); $url = $this->uploadUrl . 'access_token=' . $accessToken . '&type=' . $type; $result = $this->request->post($url, $uploadInfo); if (!$result->isResultsOK()) { return false; } return $result->getData(); } }