微信獲取二維碼開發

木子小僧發表於2015-10-29
//得到獲取二維碼的ticket,為獲取二維碼(臨時二維碼和長久二維碼)做準備
    public function _getTicket($sceneid,$type = 'temp',$expire_seconds=604800){
        if($type=='temp'){
            $data = '{"expire_seconds": %s, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": %s}}}';
            $data = sprintf($data,$expire_seconds,$sceneid);
        }else{
            $data = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": %s}}}';
            $data = sprintf($data,$sceneid);
        }
        $curl = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$this->_getAccessToken();
        $content = $this->_request($curl,true,'POST',$data);
        $content = json_decode($content);
        return $content->ticket;
    }
    //獲取二維碼
    public function _getQRCode($sceneid,$type = 'temp',$expire_seconds=604800){
        $ticket = $this->_getTicket($sceneid,$type,$expire_seconds);
        $curl = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.UrlEncode($ticket);
        $content = $this->_request($curl);
        return $content;
    }

 

相關文章