Downloads the generic permanent media item into the given destination.

@param string               $mediaID
@param string|null|resource $into

@return resource
553376
private function doPermanentFetchToStream ($mediaID, $into)
    {
        $body = $this->client->send(
            new Request(
                'POST',
                'https://api.weixin.qq.com/cgi-bin/material/get_material',
                [],
                json_encode([
                    'media_id' => $mediaID,
                ])
            ),
            [
                RequestOptions::SINK => $this->createWritableStream($into),
            ]
        )->getBody();

        if ($body->isSeekable()) {
            $body->seek(0);
        }

        return $body->detach();
    }
974547
public function downloadAction($id, $format = MediaProviderInterface::FORMAT_REFERENCE)
    {
        $media = $this->getMedia($id);

        if (!$media) {
            throw new NotFoundHttpException(sprintf('unable to find the media with the id : %s', $id));
        }

        if (!$this->get('sonata.media.pool')->getDownloadSecurity($media)->isGranted($media, $this->getCurrentRequest())) {
            throw new AccessDeniedException();
        }

        $response = $this->getProvider($media)->getDownloadResponse($media, $format, $this->get('sonata.media.pool')->getDownloadMode($media));

        if ($response instanceof BinaryFileResponse) {
            $response->prepare($this->getCurrentRequest());
        }

        return $response;
    }
1299862
public function saveMediaCategoryAssignments(int $mediaId, array $categoryIds = null)
    {
        // Delete current category assignments for this media ID
        $this->deleteMediaCategoryAssignments($mediaId);

        // Insert all assignments, if the category ID's array is not empty
        if (null !== $categoryIds) {
            $this->sql = 'insert into media_category_map (media_id, category_id) values ';
            foreach ($categoryIds as $id) {
                $this->sql .= '(?, ?),';
                $this->bindValues[] = $mediaId;
                $this->bindValues[] = $id;
            }
            $this->sql = rtrim($this->sql, ',') . ';';
            $this->execute();
        }
    }
182545
public function get($media_id)
    {
        if (!is_string($media_id)) {
            $this->setError('参数错误,媒体ID参数错误');

            return false;
        }

        $queryStr = [
            'media_id' => $media_id,
        ];

        $res = $this->_post('get_material', $queryStr);

        return $res;
    }
532535
public function withMediaByGuid(): self
    {
        if ($this->byGuid) {
            return $this;
        }

        $url = clone $this;
        $url->byGuid = true;

        return $url;
    }
1099441
public function downloadMedia($mediaId, $filePath)
    {
        $url    = $this->getMediaUrl($mediaId);
        $client = $this->getHttpClient();
        $client->setUrl($url);
        if (!$client->exec()) {
            throw new Exception("call download Media fail");
        }

        return $this->getFileSystem()->put($filePath, $client->getResponse()) > 0;
    }
315850
public function getMediaSource($mediaSourceId)
    {
        $sources = $this->getMediaSources();
        if (!isset($sources[$mediaSourceId])) {
            throw new \common_Exception('Media Sources Configuration for source '.$mediaSourceId.' not found');
        }
        return $sources[$mediaSourceId];
    }
1262965
public static function media_get($access_token, $media_id)
    {
        $url = static::cgi_media_uri($access_token, $media_id);

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_NOBODY, 0);    //只取body头
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $package = curl_exec($ch);
        $httpinfo = curl_getinfo($ch);
        curl_close($ch);
        $imageAll = array_merge(array('header' => $httpinfo), array('body' => $package));

        return $imageAll;

    }
471218
public GetMediaSourceDownloadResponse getMediaSourceDownload(String mediaId, long expiredInSeconds) {
        GetMediaSourceDownloadRequest request = new GetMediaSourceDownloadRequest()
                .withMediaId(mediaId)
                .withExpiredInSeconds(expiredInSeconds);
        return getMediaSourceDownload(request);
    }
373640
public function download($mediaId, $filename = '')
    {
        $params = array('media_id' => $mediaId, 'agentid' => $this->agentId);

        $api = $this->forever ? self::API_FOREVER_GET : self::API_TEMPORARY_GET;

        $contents = $this->http->get($api, $params);

        $filename = $filename ? $filename : $mediaId;

        if (!is_array($contents)) {
            $ext = File::getStreamExt($contents);

            file_put_contents($filename.$ext, $contents);

            return $filename.$ext;
        } else {
            return $contents;
        }
    }
944957
def download(self, media_id, as_stream=False):
        
        response = self.__app.native_api_call('media', 'd/' + media_id, {}, self.__options, False, None, as_stream, http_path="/api/meta/v1/", http_method='GET')
        return response
502979
public function download($media_id)
    {
        $url = 'https://api.weixin.qq.com/cgi-bin/media/get?'.$this->access_token.'&media_id='.$media_id;

        return $this->curl->get($url);
    }
223266
public function getStream($mediaId)
    {
        $response = $request = $this->getHttpClient()->createRequest()
            ->setUrl([
                self::API_GET,
                'media_id' => $mediaId
            ])
            ->setMethod('GET')
            ->send();
        if ($response->isOk) {
            $json = json_decode($response->content, true);
            if (JSON_ERROR_NONE === json_last_error()) {
                $this->checkAndThrow($json);
            }
        }
        return $response->content;
    }
637575
public function sendVideo($openId, $mediaId, $thumbMediaId, $title = null, $description = null)
    {
        return $this->sendCustomMessage([
            'touser' => $openId,
            'msgtype' => 'video',
            'video' => [
                'media_id' => $mediaId,
                'thumb_media_id' => $thumbMediaId,
                'title' => $title,
                'description' => $description
            ]
        ]);
    }
640448
public static File downloadMedia(String accessToken, String mediaId) {
        String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token="
                     + accessToken
                     + "&media_id="
                     + mediaId;
        File mf = null;
        for (int i = 0; i < 3; i++) {
            InputStream in = null;
            OutputStream out = null;
            try {
                Response resp = Http.get(url, 60 * 1000);
                if (resp.isOK()) {
                    in = resp.getStream();
                    mf = File.createTempFile(mediaId, ".wxmedia");
                    out = new FileOutputStream(mf);
                    Streams.writeAndClose(out, in);
                    // 检查一下是不是报错
                    if (mf.length() < 128) {
                        byte[] data = Files.readBytes(mf);
                        if (data[0] == '{') { // 看上去是个json,悲催了...
                            // 多媒体文件怎么可能是{开头,抛错吧
                            throw new IllegalArgumentException("mediaId="
                                                               + mediaId
                                                               + ","
                                                               + new String(data));
                        }
                    }
                    log.debugf("media download success mediaId=" + mediaId);
                    break;
                } else {}
            }
            catch (Throwable e) {
                log.infof("download %s fail", mediaId, e);
            }
            finally {
                Streams.safeClose(in);
                Streams.safeClose(out);
            }
        }
        return mf;
    }
132489
public function getItemStatus($id, $mediaId, array $parameters = [], array $headers = [])
    {
        return $this->getFactory()->createItemStatus(
            $this->getApi()->getItemStatus($id, $mediaId, $parameters, $headers)
        );
    }
359201
public function download($mediaId, $directory, $filename = '')
    {
        if (!is_dir($directory) || !is_writable($directory)) {
            throw new InvalidArgumentException("Directory does not exist or is not writable: '$directory'.");
        }
        $filename = $filename ?: $mediaId;
        $stream = $this->getStream($mediaId);
        $finfo = new finfo(FILEINFO_MIME);
        $mime = strstr($finfo->buffer($stream), ';', true);
        $extensions = FileHelper::getExtensionsByMimeType($mime);
        $filename .= '.' . array_pop($extensions);
        $filePath = $directory . '/' . $filename;
        file_put_contents($filePath, $stream);
        return $filePath;
    }