微信小程序 最全 生成带参数二维码
摸索了幾天終于完成了,接口A B C 通用 ,接口B只能生成已發(fā)布的小程序 ?
?
$appid='APPid';
$secret='你的小程序秘鑰';
$tokenUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
$html = file_get_contents($tokenUrl); ?
$arr =json_decode($html,true);
// echo $arr['access_token'];
$access_token=$arr['access_token'];
? ? //場(chǎng)景1
? ? // $path="pages/index/index?id=1";
? ? // $width='430';
? ? // $post_data='{"path":"'.$path.'","width":'.$width.'}';
? ? // $url="https://api.weixin.qq.com/wxa/getwxacode?access_token=".$access_token;
? ? // 場(chǎng)景2
? ? // $page="pages/index/index";
? ? // $scene="id=1";
? ? // $width='430';
? ? // $post_data='{"scene":"'.$scene.'","page":"'.$page.'","width":'.$width.'}';
? ? // $url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token;
? ? // 場(chǎng)景3
? ? // $path="pages/index/index?id=1";
? ? // $width='430';
? ? // $post_data='{"path":"'.$path.'","width":'.$width.'}';
? ? // $url="https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=".$access_token;
? ? $result=api_notice_increment($url,$post_data);
// print_r($result);
// exit();
$base64_image_content =data_uri($result,'image/png'); ?
//匹配出圖片的格式
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)){
$type = $result[2];
$new_file = "nusoap/".date('Ymd',time())."/";
if(!file_exists($new_file))
{
//檢查是否有該文件夾,如果沒有就創(chuàng)建,并給予最高權(quán)限
mkdir($new_file, 0700);
}
$new_file = $new_file.time().".{$type}";
if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))){
echo '新文件保存成功:', $new_file;
}else{
echo '新文件保存失敗';
}
}
? exit();
function api_notice_increment($url,$data){
? ? $ch = curl_init();
? ? $header = "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($curl, 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);
? ? ? ?// return $tmpInfo;
? ? // // ? ? var_dump($tmpInfo);
? ? // // ? ?exit;
? ? if (curl_errno($ch)) {
? ? ? return false;
? ? }else{
? ? ? // var_dump($tmpInfo);
? ? ? return $tmpInfo;
? ? }
? }
function data_uri($contents, $mime) ?
{ ?
??
? ? $base64 ? = base64_encode($contents); ?
? ? ??
? ? return ('data:' . $mime . ';base64,' . $base64); ?
} ?
?
?
?
?
y有問題 可以留言 或者 加微信 ai_002
總結(jié)
以上是生活随笔為你收集整理的微信小程序 最全 生成带参数二维码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 王者荣耀大师要达到什么条件
- 下一篇: 实现抢红包算法?如此简单