PHP微信开发之如何实现二维码生成类
小编给大家分享一下PHP微信开发之如何实现二维码生成类,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
我们拥有十年网页设计和网站建设经验,从网站策划到网站制作,我们的网页设计师为您提供的解决方案。为企业提供网站制作、成都做网站、微信开发、重庆小程序开发、手机网站制作、H5响应式网站、等业务。无论您有什么样的网站设计或者设计方案要求,我们都将富于创造性的提供专业设计服务并满足您的需求。
where(array('id'=> $wechatid))->find(); $appid = $wechat['appid']; $secret = $wechat['secret']; $ACCESS_TOKEN = $this->getToken($appid,$secret); $url = $this->getQrcodeurl($ACCESS_TOKEN,$fqid,1); return DownLoadQr($url,time()); } protected function getQrcodeurl($ACCESS_TOKEN,$fqid,$type = 1){ $url = self::$qrcode_url.'access_token='.$ACCESS_TOKEN; if($type == 1){ //生成永久二维码 $qrcode= '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": '.$fqid.'}}}'; }else{ //生成临时二维码 $qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": '.$fqid.'}}}'; } $result = $this->http_post_data($url,$qrcode); $oo = json_decode($result[1]); if(!$oo->ticket){ $this->ErrorLogger('getQrcodeurl falied. Error Info: getQrcodeurl get failed'); exit(); } $url = self::$qrcode_get_url.'ticket='.$oo->ticket.''; return $url; } protected function getToken($appid,$secret){ $ACCESS_TOKEN = file_get_contents(self::$token_url."appid=$appid&secret=$secret"); $ACCESS_TOKEN = json_decode($ACCESS_TOKEN); $ACCESS_TOKEN = $ACCESS_TOKEN->access_token; return $ACCESS_TOKEN; } protected function http_post_data($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data_string)) ); ob_start(); curl_exec($ch); if (curl_errno($ch)) { $this->ErrorLogger('curl falied. Error Info: '.curl_error($ch)); } $return_content = ob_get_contents(); ob_end_clean(); $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); return array($return_code, $return_content); } //下载二维码到服务器 protected function DownLoadQr($url,$filestring){ if($url == ""){ return false; } $filename = $filestring.'.jpg'; ob_start(); readfile($url); $img=ob_get_contents(); ob_end_clean(); $size=strlen($img); $fp2=fopen('./Uploads/qrcode/'.$filename,"a"); if(fwrite($fp2,$img) === false){ $this->ErrorLogger('dolwload image falied. Error Info: 无法写入图片'); exit(); } fclose($fp2); return './Uploads/qrcode/'.$filename; } private function ErrorLogger($errMsg){ $logger = fopen('./ErrorLog.txt', 'a+'); fwrite($logger, date('Y-m-d H:i:s')." Error Info : ".$errMsg."\r\n"); } }
看完了这篇文章,相信你对“PHP微信开发之如何实现二维码生成类”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
分享题目:PHP微信开发之如何实现二维码生成类
分享URL:http://pwwzsj.com/article/jdppjo.html