php生成微信小程序带参数的二维码,扫码后小程序端接收不到参数

前言:最开始使用‘https://api.weixin.qq.com/wxa/getwxacode?access_token=’获取小程序码,生成后的二维码携带参数后,在开发版中有时还可以获取到参数,但在正式版本中获取不到参数,搜寻无果后改为请求获取不限制的小程序码’POST https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN’,然后就成功了。。。

官方文档:
获取不限制的小程序码 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html

php代码:

// 获取小程序二维码图片
    public function get_wechat_img($organ_idno, $appid, $appSecret){
        // 获取account_token
        $access_token = $this->get_account_token($appid, $appSecret);
        if(!$access_token){
            return false;
        }
        $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$access_token;
        $data['path'] = 'pages/home/index';
        $data['scene'] = 'usertel,userid';//(string类型,必须是数字)
        $data['width'] = 430;
        $data['env_version'] = 'release'; // 正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
        $data['is_hyaline'] = true; // 默认是false,是否需要透明底色,为 true 时,生成透明底色的小程序
        // var_dump($data);

        $result = $this->curlPost($url,$data,'POST');
        // var_dump($result);

        $path = './uploads/img/'.date('Ymd');
        if(!file_exists($path)){
            mkdir($path, 0755, true);
        }
        $file_name = $organ_idno.'.png';
        $ret = file_put_contents( $path.'/'.$file_name, $result, true);
        if($ret){
            // 写入数据表
            $file= $path.'/'.$file_name;
         	...
            return $file;
        }else{
            // var_dump($ret);
            return false;
        }
        
    }
    public function curlPost($url,$data,$method){
        $ch = curl_init();   //1.初始化  
        curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址  
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式  
        //4.参数如下  
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https  
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        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_HTTPHEADER,array('Accept-Encoding: gzip, deflate'));//gzip解压内容  
            curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');  
          
        if($method=="POST"){//5.post方式的时候添加数据  
            $data = json_encode($data);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  
        }  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
        $tmpInfo = curl_exec($ch);//6.执行  
      
        if (curl_errno($ch)) {//7.如果出错  
            return curl_error($ch);  
        }  
        curl_close($ch);//8.关闭  
        return $tmpInfo;  
}  
// 获取微信小程序登录access_token
    public function get_wechat_account_token($appid, $appSecret){
        
            $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appSecret;
            $res = json_decode($this->curlPost($url, '', 'GET'), true);
            
            if($res){
               // 做缓存处理
                return $res['access_token'];
            }else{
                return false;
            }
    }

微信小程序端获取参数

Page({
  onLoad (query) {
    // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
    const scene = decodeURIComponent(query.scene)
  }
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值