zoukankan      html  css  js  c++  java
  • thinkphp 把小程序码二进制流存储到本地

     1 public function getxcxm(){
     2         $id = input('id');
     3         $astk = json_decode($this->getasstk())->access_token;
     4         $url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=".$astk;
     5         $data = array(
     6             'path' => "pages/app/querytest?id=".$id,
     7             'width' => 430,
     8             'is_hyaline' => true
     9         );
    10         $xcxm = $this->http_request($url,json_encode($data));
    11         $path = ROOT_PATH . 'public/upload/'.date("Ymd/");
    12         if(!is_dir($path)){
    13             mkdir($path,0755,true);
    14         }
    15         $filepath = $path.time().".png";
    16         $file = fopen($filepath,"w");
    17         fwrite($file,$xcxm);
    18         fclose($file);
    19         return $filepath;    
    20     }

    实际开发中 我这样写的:

     1 //获取小程序码
     2     public function getxcxm(){
     3         $id = input('id');
     4         //先从本地读取,本地没有再向微信提取
     5         $ckname = ROOT_PATH . 'public/upload/recode/'.$id.".png";
     6         if(file_exists($ckname)){
     7             return str_replace("/www/wwwroot/","https://",$ckname);
     8         }else{
     9             $astk = json_decode($this->getasstk())->access_token;
    10             $url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=".$astk;
    11             $data = array(
    12                 'path' => "pages/app/querytest?id=".$id,
    13                 'width' => 430,
    14                 'is_hyaline' => true
    15             );
    16             $xcxm = $this->http_request($url,json_encode($data));
    17             $path = ROOT_PATH . 'public/upload/recode/';
    18             if(!is_dir($path)){
    19                 mkdir($path,0755,true);
    20             }
    21             $filepath = $path.$id.".png";
    22             $file = fopen($filepath,"w");
    23             fwrite($file,$xcxm);
    24             fclose($file);
    25             return str_replace("/www/wwwroot/","https://",$filepath);
    26         }
    27     }
  • 相关阅读:
    002 课程导学
    006 实例1-温度转换
    003 Python基本语法元素
    PHP读取文件头(2字节)判断文件类型(转)
    常见的浏览器Hack技巧总结(转)
    晨曦之光 linux Crontab 使用(转)
    实用技巧:简单而有用的nohup命令介绍(转)
    shell之“>/dev/null 2>&1” 详解(转)
    phpmailer邮件类下载(转)
    PHP拦截器的使用(转)
  • 原文地址:https://www.cnblogs.com/lijea/p/9336802.html
Copyright © 2011-2022 走看看