PHP微信開發(fā)之二維碼生成類
<?php /** * Created by PhpStorm. * User: bin * Date: 15-1-16 * Time: 上午9:48 */ namespace Home\Common; // 微信處理類 set_time_limit(30); class Weixin{ //構(gòu)造方法 static $qrcode_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?"; static $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&"; static $qrcode_get_url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?"; //生成二維碼 public function getEwm($wechatid,$fqid,$type = 1){ $wechat = M('Member_public')->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{ //生成臨時(shí)二維碼 $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); } //下載二維碼到服務(wù)器 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實(shí)現(xiàn)微信公眾平臺賬號自定義菜單類
- php微信公眾平臺開發(fā)類實(shí)例
- php實(shí)現(xiàn)微信公眾平臺賬號自定義菜單類
- Java微信公眾平臺開發(fā)(3) 接收消息的分類及實(shí)體的創(chuàng)建
- PHP封裝的微信公眾平臺接口開發(fā)操作類完整示例
- Java微信公眾平臺開發(fā)(4) 回復(fù)消息的分類及實(shí)體的創(chuàng)建
- 微信公眾號開發(fā)之微信公共平臺消息回復(fù)類實(shí)例
- Java微信二次開發(fā)(三) Java微信各類型消息封裝
- PHP 微信支付類 demo
- PHP微信API接口類
- 微信公眾平臺開發(fā)教程⑥ 微信開發(fā)集成類的使用圖文詳解
相關(guān)文章
laravel配置Redis多個(gè)庫的實(shí)現(xiàn)方法
這篇文章主要介紹了laravel配置Redis多個(gè)庫的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04使用composer安裝使用thinkphp6.0框架問題【視頻教程】
這篇文章主要介紹了使用composer安裝使用thinkphp6.0框架問題,通過一個(gè)小視頻給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10php redis 處理websocket聊天記錄的實(shí)例代碼
本文通過實(shí)例代碼給大家介紹了php redis 處理websocket聊天記錄的相關(guān)知識,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-07-07laravel框架數(shù)據(jù)庫配置及操作數(shù)據(jù)庫示例
這篇文章主要介紹了laravel框架數(shù)據(jù)庫配置及操作數(shù)據(jù)庫,結(jié)合實(shí)例形式分析了Laravel數(shù)據(jù)庫的基本配置與操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-10-10PHP 數(shù)據(jù)結(jié)構(gòu)隊(duì)列(SplQueue)和優(yōu)先隊(duì)列(SplPriorityQueue)簡單使用實(shí)例
這篇文章主要介紹了PHP 數(shù)據(jù)結(jié)構(gòu)隊(duì)列(SplQueue)和優(yōu)先隊(duì)列(SplPriorityQueue)簡單使用實(shí)例,需要的朋友可以參考下2015-05-05淺談thinkphp5 instance 的簡單實(shí)現(xiàn)
本篇文章主要介紹了淺談thinkphp5 instance 的簡單實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07CodeIgniter分頁類pagination使用方法示例
這篇文章主要介紹了CodeIgniter分頁類pagination使用方法,結(jié)合實(shí)例形式簡單分析了CodeIgniter框架中的分頁類pagination基本的配置與使用技巧,需要的朋友可以參考下2016-03-03php實(shí)現(xiàn)的百度搜索某地天氣的小偷代碼
這篇文章主要介紹了php實(shí)現(xiàn)的百度搜索某地天氣的小偷代碼,有關(guān)php顯示天氣預(yù)報(bào)信息的方法,需要的朋友可以參考下2014-04-04Laravel5.5 支付寶手機(jī)網(wǎng)站支付的教程
這篇文章主要介紹了Laravel5.5 支付寶手機(jī)網(wǎng)站支付的教程,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07