//得到获取二维码的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; }