• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP微信开发之二维码生成类_php实例

php 搞代码 3年前 (2022-01-25) 12次浏览 已收录 0个评论
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.'';<strong>+本文来源gao@daima#com搞(%代@#码网</strong><pre>搞代gaodaima码

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”); }}


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP微信开发之二维码生成类_php实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址