小程序生成带参数的二维码

发布时间:2020-02-23 14:50:48 热度: 511 ℃ 评论数: 3

首先获取access_token

其次

$ACCESS_TOKEN = $_POST['access_token'];
$qcode ="https://api.weixin.qq.com/wxa/getwxacode?access_token=$ACCESS_TOKEN";
$param = json_encode(array("path"=>"pages/nuobtel/nuobtel?scene=","width"=>$width));
$result = httpRequest( $qcode, $param,"POST");
$echo $result;

$now = strtotime(date("H:i:s",time())); //当前时间的时间戳
//生成二维码
file_put_contents("ewm/".$now.".png", $result);
$base64_image ="data:image/jpeg;base64,".base64_encode( $result );


//把请求发送到微信服务器换取二维码

  function httpRequest($url, $data='', $method='GET'){

    $curl = curl_init();  

    curl_setopt($curl, CURLOPT_URL, $url);  

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);  

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);  

    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);  

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);  

    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);  

    if($method=='POST')

    {

        curl_setopt($curl, CURLOPT_POST, 1); 

        if ($data != '')

        {

            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);  

        }

    }



    curl_setopt($curl, CURLOPT_TIMEOUT, 30);  

    curl_setopt($curl, CURLOPT_HEADER, 0);  

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  

    $result = curl_exec($curl);  

    curl_close($curl);  

    return $result;

  } 

生成的二维码保存路径

ewm/.png

小程序生成带参数的二维码

吐槽一下
  • 消灭零回复

手机扫码访问