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     }
  • 相关阅读:
    leetcode53. Maximum Subarray(动态规划)
    MinGW中没有gdb.exe解决办法
    POJ
    POJ 3614 (贪心)
    bzoj 1057 (悬线法求最大子矩阵)
    bzoj1 218 激光炸弹(二位前缀和)
    POJ 2299(归并求逆序对)
    HDU 1394(归并求逆序对)
    POJ1523 Targin求关节点
    HDU6299 贪心
  • 原文地址:https://www.cnblogs.com/lijea/p/9336802.html
Copyright © 2011-2022 走看看