欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

PHP獲取小程序碼,小程序帶參數(shù)跳轉(zhuǎn) - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們在追求其視覺表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏壧峁┍憬莸闹С郑?

您當(dāng)前位置>首頁 » 新聞資訊 » 小程序相關(guān) >

PHP獲取小程序碼,小程序帶參數(shù)跳轉(zhuǎn)

發(fā)表時(shí)間:2020-11-20

發(fā)布人:葵宇科技

瀏覽次數(shù):46

PHP獲取小程序碼,小程序帶參數(shù)跳轉(zhuǎn)

獲取小程序碼首先需要獲取Accesstoken ,下面是獲取Accesstoken,注意超時(shí)時(shí)間所有我把時(shí)間往前提了一下,生成小程序碼的時(shí)候先調(diào)取獲取Accesstoken的方法

 //獲取accesstokn 并保存
    public function getAccessToken(){

        //$file_path = VENDOR_PATH.'wchat/access_token';
        $file_path = '../application/common/access_token';

        if(is_file($file_path)){
            $connect = file_get_contents($file_path);
            if($connect!=''){
                $ret = json_decode($connect,true);
                //已存在
                if($ret['access_token'] && time()-$ret['time'] <7000){
                    $this->access_token = $ret['access_token'];
                    return true;
                }
            }
        }

        $wx_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->wxAppId}&secret={$this->wxAppSecret}";
        $ret = httpUtil($wx_url);
        $ret = json_decode($ret,true);
        if($ret['access_token']){
            $data = array(
                'access_token'=>$ret['access_token'],
                'time'=>time()
            );
            file_put_contents($file_path, json_encode($data));
            $this->access_token = $ret['access_token'];
            return true;
        }
    }
//獲取小程序碼
    public function getQrCode($openid){
        $this->getAccessToken();//更新accesstoken
        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$this->access_token";//官方獲取小程序碼url
        $data['page']='pages/index/index';//小程序的跳轉(zhuǎn)頁面地址
        $data['scene'] = "$openid";  //請求參數(shù)
       
        $res = httpUtil($url,json_encode($data),'POST');
        if(!empty($res['errcode'])){
            return false;
        }
        $file ="qrcode/$openid.jpg";
        file_put_contents('./'.$file,$res);
        if (file_exists($file)) {
            //return $_SERVER ['HTTP_HOST'].'/'.$file;
            return '/'.$file;
        }else{
            return false;
        }
    }

相關(guān)案例查看更多