30 12 2015

//上传语音
 public function  yuyin(){


  $token=$_GET["token"];
  $server_id=$_POST["mediaId"];
  $access_token = $this->access_token;
  $url="http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=".$access_token."&media_id=".$server_id;
  
  $fileInfo = downloadWeixinFile($url);
 

  
  $datestr = date("Y-m-d",time());
  $dir = $_SERVER['DOCUMENT_ROOT']."/uploads/shop/".$datestr;
  if(!is_dir($dir)){
   mkdir($dir, 0777, true);
  }
  
  $name=time().rand(10000,99999).".mp3";
  $filename=$dir."/".$name;
  $local_file = fopen($filename, 'w');
  if (false !== $local_file){
   if (false !== fwrite($local_file, $fileInfo["body"])) {
    fclose($local_file);
   }
  }
  $sr="/uploads/shop/".$datestr."/".$name;
  
  saveWeixinFile($filename, $fileInfo["body"]);
  $src=trim($sr);
  LOG::write("AjaxProductAction.class.php, uploadwximage(..), src: $src");
  $data['imgUrl']=$src;
  $this->ajaxReturn($src);
  /* } */
  // print_r($jsapi_ticketObj);
   
  
    
  

  
  
  
  
  
  
  
  
  
  
  
  
  
 }
 
 
 
 public function downloadWeixinFile($url)
 {
  $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;
 }
 
 public function saveWeixinFile($filename, $filecontent)
 {
  $local_file = fopen($filename, 'w');
  if (false !== $local_file){
   if (false !== fwrite($local_file, $filecontent)) {
    fclose($local_file);
   }
  }
 }
 

发表评论