首页 / 二维码 / 微信公众平台生成带参数二维码
微信公众平台生成带参数二维码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了微信公众平台生成带参数二维码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4551字,纯文字阅读大概需要7分钟。
内容图文
![微信公众平台生成带参数二维码](/upload/InfoBanner/zyjiaocheng/1325/3161e0e8f41e4d239d068fa02ffdec9b.jpg)
<?php // +---------------------------------------------------------------------- // | 获取微信公众带参数二维码 // | Author: wzb 312967328@qq.com // +---------------------------------------------------------------------- namespace Mob\Controller; use Think\Controller; class BinController extends Controller{ private$appId; private$appSecret; private$type; // private $logo_img;/********************** * 微信获取 access_token *********************/protectedfunction _initialize($uid=0){ $config = api(‘Config/lists‘); C($config); //添加配置$this->appId = C(‘WX_APPID‘); $this->appSecret = C(‘WX_SECRET‘); $this->type=0; $site_url = ‘./Uploads/images/‘; $store_path = date(‘Y‘).‘/‘.date(‘m‘).‘/‘.date(‘d‘) ; //分目录存放 zkf 2015-7-31if(!is_dir($site_url.$store_path)) { @mkdir($site_url.$store_path, 0777 , true) ; } $this->logo_img = $site_url.$store_path.‘/user_uid‘.$uid.‘.png‘; } /********************** * 微信获取 access_token *********************/privatefunction getAccessToken() { $m_appact = M(‘Appact‘,‘ot_‘,DB_GY); $data = $m_appact -> where(array(‘appid‘=> $this ->appId)) -> field(‘access_token,expire_time‘) -> find(); if ($data[‘expire_time‘] < time()) { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret"; $res = json_decode($this->httpGet($url)); $access_token = $res->access_token; if ($access_token) { $data[‘expire_time‘] = time() + 7000; $data[‘access_token‘] = $access_token; $r = $m_appact -> where(array(‘appid‘=> $this->appId)) -> find(); $save_arr = array(‘access_token‘=> $data[‘access_token‘],‘expire_time‘=> $data[‘expire_time‘]); $add_arr = array(‘appid‘=>$this->appId,‘access_token‘=> $data[‘access_token‘],‘expire_time‘=> $data[‘expire_time‘]); $r ? $m_appact -> where(array(‘appid‘=> $this->appId)) -> save($save_arr) : $m_appact -> add($add_arr); } } else { $access_token = $data[‘access_token‘]; } return$access_token; } /********************** * 获取微信二维码 *********************/function get_erma(){ $access_token = $this->getAccessToken(); if(max(0,$this->$type) == 0){ //临时$qrcode = array( "expire_seconds" => 1800, "action_name" => "QR_SCENE", "action_info" => array( "scene" => array( "scene_id" => 10000 ) ) ); }else{ //永久$qrcode = array( "action_name"=> "QR_LIMIT_SCENE", "action_info" =>array( "scene"=>array( "scene_id"=> 1000 ) ) ); } //创建二维码ticket$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$access_token"; $result = $this->https_post($url,json_encode($qrcode)); $jsoninfo = json_decode($result, true); $ticket = $jsoninfo["ticket"]; // 下载二维码$get_img_url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket); $imageInfo = $this->downloadImageFromWeiXin($get_img_url); $filename = $this->logo_img; $local_file = fopen($filename, ‘w‘); if (false !== $local_file){ if (false !== fwrite($local_file, $imageInfo["body"])) { fclose($local_file); } } } /********************** * 下载图片函数 *********************/function downloadImageFromWeiXin($url){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); //只取body头 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $package = curl_exec($ch); $httpinfo = curl_getinfo($ch); curl_close($ch); returnarray_merge(array(‘body‘ => $package), array(‘header‘ => $httpinfo)); } /********************** * POST 数据函数 *********************/function https_post($post_url, $post_data){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $post_url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_POST, 1 ); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/4.0"); $result = curl_exec($curl); $error = curl_error($curl); curl_close($curl); return$error ? $error : $result; } /********************** * GET 数据函数 *********************/privatefunction httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $res = curl_exec($curl); curl_close($curl); return$res; } }
原文:http://www.cnblogs.com/binblogs/p/5192805.html
内容总结
以上是互联网集市为您收集整理的微信公众平台生成带参数二维码全部内容,希望文章能够帮你解决微信公众平台生成带参数二维码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。