微信小程序指定页面生成二维码
文档:
php
public function index() { $access_token = $this->getAccessToken('appid','secret'); $tk = json_decode($access_token)->access_token; $urlss = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk; $_pageData = [ "page"=> 'pages/yarn/yarn', //例如:pages/home/index "scene"=>"&a=1", //参数绑定 "width" => 430 //宽度 ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $urlss); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($_pageData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); $data = curl_exec($ch); curl_close($ch); header("Content-Type: image/jpeg;text/html; charset=utf-8"); echo $data; } public function getAccessToken($appid,$secret){ $urlss = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret; return file_get_contents($urlss); }
html
<img src="/index/index/index">
小程序页面接收扫码传参,例:接收传入id
onLoad(e) { const scene = decodeURIComponent(e.scene) if(scene){ let data = this.str2Obj(scene); if(data.id){ this.id = data.id; } } } methods: { str2Obj(t) { const params = {}; t.split('&').forEach(item => { const [key, value] = item.split('='); params[key] = value; }); return params } }