php 小程序生成带参数的二维码
public function getCode()
{
$appid = '';
$appsecret = '';
$access_token = $this->accessToken($appid, $appsecret);
$width = 430;
$page = '';
$scene = '';
$wx_api = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token;
$data = [
'page' => $page,
'scene' => $scene,
'width' => $width,
];
$post_data = json_encode($data);
$result = $this->api_notice_increment($wx_api, $post_data);
if(!$result){
return false;
}
$img_base64 = base64_encode($result);
echo '<img src="' . $img_base64 . '">';
}
public function accessToken($APP_ID, $SECRET)
{
$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $APP_ID . "&secret=" . $SECRET;
$res = file_get_contents($token_access_url);
$result = json_decode($res, true);
$access_token = $result['access_token'];
return $access_token;
}
function api_notice_increment($url, $data)
{
$ch = curl_init();
$header = array("Accept-Charset: utf-8");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
return false;
}else{
return $tmpInfo;
}
}