获取临时素材.

@see   https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738727

@param  $media_id

@return mixed
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);
    }
446437
public function getMedia($media_id, $is_video = false)
    {
        if (!$this->access_token && !$this->getAccessToken()) {
            return false;
        }
        $result = Tools::httpGet(self::API_URL_PREFIX . self::MEDIA_GET_URL . "access_token={$this->access_token}" . '&media_id=' . $media_id);
        if ($result) {
            if (is_string($result)) {
                $json = json_decode($result, true);
                if (isset($json['errcode'])) {
                    $this->errCode = $json['errcode'];
                    $this->errMsg = $json['errmsg'];
                    return $this->checkRetry(__FUNCTION__, func_get_args());
                }
            }
            return $result;
        }
        return false;
    }
283682
public function deleteMedia()
    {
        $mediaMapper = ($this->container->dataMapper)('MediaMapper');

        // Get the media record
        if (null !== $id = $this->request->getParsedBodyParam('id')) {
            $mediaFile = $mediaMapper->findById($id);

            if (is_string($mediaFile->file)) {
                $rootDir = substr($mediaFile->file, 0, 2);
                $this->deleteRecursive(ROOT_DIR . 'public/media/' . $rootDir);

                $mediaMapper->delete($mediaFile);
            }
        }

        // Set the response type
        if ($this->request->isXhr()) {
            $r = $this->response->withHeader('Content-Type', 'application/json');
            return $r->write(json_encode(["status" => "success"]));
        }

        return $this->redirect('adminShowMedia');
    }
1354561
public function mediaGet($media_id){
        $param = array(
            'access_token' => $this->accessToken,
            'media_id'     => $media_id
        );

        $url = "{$this->mediaURL}/media/get?";
        return $url . http_build_query($param);
    }
1156480
public function media()
    {
        $query =  $this->customHasManyThrough('App\Models\Media', 'App\Models\MediaRelation', 'postID', 'mediaID', 'postID', 'mediaID', $this->getTable()."_media");

        if($this->mediaField) {
            $query->where($this->getTable().'_media.field', $this->mediaField);
        }

        // We also need 'field' from media relations, so we can select media based on field name
        $query->select(['media.*',$this->getTable().'_media.field']);

        return $query;
    }
1014537
public function getMaterial($media_id) {
		$data = $this->getData('/cgi-bin/material/get_material', [
			'access_token' => $this->getAccessToken(),
		], Json::encode(['media_id' => $media_id]));

		return $this->errcode == 0 ? (isset($data['content']) && isset($data['extension']) ? $this->saveFile($data) : $data) : null;
	}
816066
public function getMediaId(): \Psr\Http\Message\UriInterface
    {
        if (!$this->mediaId) {
            return new Uri();
        }

        return $this->mediaId;
    }
1296447
public function updateNews($media_id, $articles, $index = 0)
    {
        if (!is_string($media_id)) {
            $this->setError('参数错误,媒体ID参数错误');

            return false;
        }

        $queryStr = [
            "media_id" => $media_id,
            "index"    => intval($index),
            "articles" => $articles,
        ];

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

        return $res;
    }
931332
public function download($mediaId)
    {
        $response = $this->curl->post(self::DOWNLOAD.$this->access_token, json_encode([
                    'media_id' => $mediaId,
                ]
            )
        );
        $is_json = json_decode($response);
        if ($is_json) {
            return Response::json($is_json);
        } else {
            return $response;
        }
    }
117707
public function getForeverMedia($media_id, $is_video = false)
    {
        if (!$this->access_token && !$this->getAccessToken()) {
            return false;
        }
        $data = array('media_id' => $media_id);
        $result = Tools::httpPost(self::API_URL_PREFIX . self::MEDIA_FOREVER_GET_URL . "access_token={$this->access_token}", Tools::json_encode($data));
        if ($result) {
            if (is_string($result) && ($json = json_decode($result, true))) {
                if (isset($json['errcode'])) {
                    $this->errCode = $json['errcode'];
                    $this->errMsg = $json['errmsg'];
                    return $this->checkRetry(__FUNCTION__, func_get_args());
                }
                return $json;
            }
            return $result;
        }
        return false;
    }
51772
public MediaItem getMediaItem(String id) {
		
		DailyMotionUrl url = new DailyMotionUrl(requestPrefix + id);
		
		HttpRequest request;
		try {
			request = requestFactory.buildGetRequest(url);
			DailyMotionVideo video = request.execute().parseAs(DailyMotionVideo.class);
			
			if(video != null) {
				MediaItem mediaItem = new DailyMotionMediaItem(video);
				return mediaItem;
			}
			
		} catch (Exception e) {
			
		}

		return null;
	}
820438
public function deleteMediaAction(Request $request, $id)
    {
        $response = $this->getFilter($request);
        if ($response['success'] === false) {
            return $response['value'];
        }
        $filter = $response['value'];

        $mm = $this->getMediaManager();

        $media = $mm->findOneBy(array(
            'id' => $id,
            'filter' => $filter,
        ));

        if ($media !== null) {
            $media->setCryptedFilter($response['crypted']);
            $mm->delete($media);
        }

        return $this->createResponse($media);
    }
155041
public function delMaterial($media_id)
    {
        $url = "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, ['media_id' => $media_id]);
    }
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;

    }
902391
public function mediatemplate($id)
    {
        $template = $this->templateManager->find($id);

        if (!$template) {
            return [];
        }

        return $template->getParameters();
    }
1237181
public function remove($id, $mediaId)
    {
        return $this->getFactory()->createResult(
            $this->getApi()->removeMediaFromList($id, $mediaId)
        );
    }
1213770
private function getPostRelatedMedia($id, $post, $postTypeSlug, $translatableFields)
    {
        $media = array();

        $mediaRelationTable = $postTypeSlug.'_media';
        // get the media relation joining the media table and the post
        $mediaRelationsResults = DB::table($mediaRelationTable)
            ->join('media', $mediaRelationTable.'.mediaID', 'media.mediaID')
            ->join($postTypeSlug, $mediaRelationTable.'.postID', $postTypeSlug.'.postID')
            ->where($mediaRelationTable.".postID", $id)
            ->select(
                'media.title as title', 'media.mediaID', $mediaRelationTable.'.mediaRelationID',
                $mediaRelationTable.'.postID', $mediaRelationTable.'.language',
                'media.description', 'media.credit', 'media.type', 'media.extension',
                'media.url', 'media.filename', 'media.fileDirectory', 'media.filesize', 'media.dimensions', $mediaRelationTable.'.field'
            )
            ->get();


        // the object media used for the media custom fields in the front end
        if ($post->featuredImageID) {
            $featuredImage = Media::find($post->featuredImageID);
            // set feature image if it exist
            if($featuredImage) {
                $media["featuredImage"][] = $featuredImage;
            }
        }
        if ($post->featuredVideoID) {
            $featuredVideo = Media::find($post->featuredVideoID);
            $media["featuredVideo"][] = $featuredVideo;
        }

        // loop throw the media relation and construct the $media object
        foreach ($mediaRelationsResults as $relation){
            if(in_array($relation->field, $translatableFields)) {
                $langArr = json_decode($relation->language);
                foreach ($langArr as $langKey => $lang){
                    if(!isset($media[$relation->field."__lang__".$langKey])) {
                        $media[$relation->field."__lang__".$langKey] = array();
                    }
                    if ($lang) {
                        array_push($media[$relation->field."__lang__".$langKey], $relation);
                    }
                }
            }else{
                if(!isset($media[$relation->field])) {
                    $media[$relation->field] = array();
                }
                array_push($media[$relation->field], $relation);
            }
        }

        return $media;
    }