微信公众平台PHP上传临时素材

发布时间:2017年07月07日 阅读:521 次

//上传临时素材
		$upurl='https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=image';
  		function https_request($url,$type="get",$res="json",$data = ''){
        //1.初始化curl
        $curl = curl_init();
        //2.设置curl的参数
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,2);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        if ($type == "post"){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        //3.采集
        $output = curl_exec($curl);
        //4.关闭
        curl_close($curl);
        if ($res == 'json') {
            return json_decode($output,true);
        }
    	}   
		$loimg=realpath(dirname(__FILE__).'/../../../')."/Public/qrcode/kBylFKIBR.jpg";
     	$josn2= array("media"=>"@".$loimg);
		//$josn2= new CURLFile($loimg);
		//echo $loimg;
        $res=https_request( $upurl ,'post', 'json', $josn2);
        dump($res);
Tag:
相关文章
发表评论

发表评论: