博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信公众平台生成带参数二维码
阅读量:4986 次
发布时间:2019-06-12

本文共 5391 字,大约阅读时间需要 17 分钟。

 

 

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-31 if(!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 *********************/ private function 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); return array_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 数据函数 *********************/ private function 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; }}

 

扫描二维码

private function receiveEvent($object){    $contentStr = "";    switch ($object->Event)    {        case "subscribe":            $contentStr = "欢迎关注 ";            if (isset($object->EventKey)){                $contentStr = "关注二维码场景 ".$object->EventKey;            }            break;        case "SCAN":            $contentStr = "扫描 ".$object->EventKey;            break;        default:            break;           }    $resultStr = $this->transmitText($object, $contentStr);    return $resultStr;}

 

转载于:https://www.cnblogs.com/binblogs/p/5192805.html

你可能感兴趣的文章
(十)、iptables进行转发使内网能上网
查看>>
python之路《八》装饰器
查看>>
maven 打包前 Junit 测试
查看>>
spring boot 添加druid
查看>>
SQL联合查询
查看>>
dev 控件之 gridcontrid 应用
查看>>
什么是同一网段
查看>>
温故而知新
查看>>
c# 菱形,三角形
查看>>
java之MD5加密
查看>>
Codeforces Round #432 (Div. 2) ABC
查看>>
python跨行 print:多用(),换行符\要小心,少用+或者不用(其它程序代码跨行用\就行,不能用括号)...
查看>>
自己不懂的SQL语句用法
查看>>
C++ 函数指针
查看>>
.NET调用新浪微博开放平台接口的代码示例(转)
查看>>
四种百度文库资源直接下载的方法!不用代码,不用券!一键搞定!
查看>>
数据库-包和包体
查看>>
软件的知识产权保护
查看>>
7.20-7.24
查看>>
Bower前端包管理器
查看>>