zoukankan      html  css  js  c++  java
  • php 小程序获取渠道二维码 保存

    function ppost($url,$arr){
       $post_data = json_encode($arr);
       $url=$url;
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_URL,$url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//这里也是那个是否接收返回值的设置
    
       curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    // https请求 不验证证书和hosts
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
         $result = curl_exec($ch);
         curl_close($ch);
         return $result;
    }
    //将二进制以图片存入硬盘
    function toimg($aa,$path,$filename){
          //将二进制转为图片
    $imgDir = $path;  
    $filename=$filename;///要生成的图片名字  
      
    $xmlstr =  $aa;  
    if(empty($xmlstr)) {  
        $xmlstr = file_get_contents('php://input');  
    }  
       
    $jpg = $xmlstr;//得到post过来的二进制原始数据  
    if(empty($jpg))  
    {  
        echo 'nostream';  
        exit();  
    }  
      
    $file = fopen("./".$imgDir."/".$filename,"w");//打开文件准备写入  
    fwrite($file,$jpg);//写入  
    fclose($file);//关闭  
      
    $filePath = './'.$imgDir."/".$filename;  
      
    //图片是否存在  
    if(!file_exists($filePath))  
    {  
        echo 'createFail'."---".$filePath;  
        exit();  
    }
    }
      $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=TOKEN";
      $data['scene'] = "666";    //二维码参数
      $data['width'] = "100";
    //$data['page'] = "pages/index/index";
      $aa = ppost($url,$data);
      toimg($aa,'Public/tk_qrcode',time().".jpg");
  • 相关阅读:
    Python基础(2)
    Python基础(3)
    Python基础(1)
    [日本语]单词1
    【.Net】 C#参数数组与函数重载
    pyenv
    Pip批量安装/卸载包
    Xcode中模拟器慢
    iPhone的设备名转换
    在python命令行执行sudo命令
  • 原文地址:https://www.cnblogs.com/zonglonglong/p/7340204.html
Copyright © 2011-2022 走看看