PHP 携带参数的二维码
//带二维码的海报
public function shopqrcode() {
header('content-type:text/html;charset=utf-8');
//配置APPID、APPSECRET
$id=$_GET['uid'];
$APPID = C('WX_APPID');
$APPSECRET =C('WX_SECRET');
//获取access_token
$access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$APPID&secret=$APPSECRET";
//缓存access_token
session_start();
$_SESSION['access_token'] = "";
$_SESSION['expires_in'] = 0;
$ACCESS_TOKEN = "";
if(!isset($_SESSION['access_token']) || (isset($_SESSION['expires_in']) && time() > $_SESSION['expires_in'])){
$json =$this->httpRequest($access_token);
$json = json_decode($json,true);
// var_dump($json);
$_SESSION['access_token'] = $json['access_token'];
$_SESSION['expires_in'] = time()+7200;
$ACCESS_TOKEN = $json["access_token"];
}else{
$ACCESS_TOKEN = $_SESSION["access_token"];
}
$qcode = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$ACCESS_TOKEN;
$data = array();
$data['scene'] =$id;
$data['page'] = 'pages/login/welcome';
$data['width'] = "150";
$param = json_encode($data);
//POST参数
$result = $this->httpRequest($qcode, $param,"POST");
//生成二维码
//$filename="/mnt/data/wwwroot/bzl/Qrcode/$id".".png"; //保存
$filename="./Qrcode/$id".".png";
$aa=file_put_contents($filename, $result);
if($aa){
$img="https://".$_SERVER[SERVER_NAME]."/Qrcode/$id".".png";//返回二维码
return $img;
}else{
$img="";
return $img;
}
}