<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                thinkphp5微信公眾號二維碼掃碼關注推廣二維碼事件實現, 給出實現的全部方法: 獲取二維碼,讓微信公眾號跳轉到以下代碼的code方法即可,用戶點擊二維碼后,通過二維碼獲取關注用戶信息及二維碼推廣者信息,以及判斷用戶是否關注,具體代碼邏輯在以下代碼responseMsg方法,但需要在公眾平臺url配置接入到以下代碼的index方法,用戶關注后,則通過index方法訪問responseMsg方法。 ``` <?php namespace app\home\controller; define("TOKEN", "xieqianghui1234"); use think\Controller; use app\home\model\reIndex; class Index extends Controller{ private $appId; private $appSecret; public function __construct() { $this->appId = 'wx17aaa90e1f107245'; $this->appSecret= '8bd13c549f07c6e365f818e113dee821'; } // 獲取code public function code(){ $appid = 'wx17aaa90e1f107245'; $redirecturl = urlencode("http://www.neophiledesign.com/kfgzh/public/index.php/home/index/member"); $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$redirecturl.'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'; header('location:'.$url); } // 通過ticket換取二維碼 public function wechatcode($ticket) { $url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.urlencode($ticket); return $this->getjson($url); } // 二維碼呈現 public function member(){ $code = $_GET['code']; $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appId.'&secret='.$this->appSecret.'&code='.$code.'&grant_type=authorization_code'; $res = $this->curl_post($url); // 用戶openid $openid = $res['openid']; $recode = (new reIndex)->reselect($openid); header("Content-Type: image/jpeg;text/html; charset=utf-8"); if(!$recode){ $rand = mt_rand(0,9).mt_rand(0,9).mt_rand(0,9).mt_rand(0,9); $arr = array(); $arr = array( 'openid' => $openid, 'code' => $rand, ); (new reIndex)->readd($arr); $res = $this->reindex(); $access_token = $res['access_token']; // 獲取ticket $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token; $list = array(); $list = array( 'action_name' => 'QR_LIMIT_SCENE', 'action_info' => array( 'scene' => array( 'scene_id' => $rand, ), ), ); // 獲取ticket $res = $this->curl_post($url,json_encode($list),'POST'); // 通過ticket換取二維碼 $res = $this->wechatcode($res['ticket']); $file = fopen(dirname(dirname(dirname(__DIR__)))."/image/".$rand."upload.jpg","w"); fwrite($file,$res);//寫入 fclose($file);//關閉 $img = "http://www.neophiledesign.com/kfgzh/image/".$rand."upload.jpg"; }else{ $img = "http://www.neophiledesign.com/kfgzh/image/".$recode."upload.jpg"; } echo "<img src=$img />"; } // 獲取access_token public function reindex(){ $appid = 'wx17aaa90e1f107245'; $secret = '8bd13c549f07c6e365f818e113dee821'; $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret; $res = $this->curl_post($url); return $res; } // 獲取用戶信息及openid public function retest($access_token){ $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$access_token.'&openid=OPENID&lang=zh_CN'; return $this->getJson($url); } // token驗證 public function index(){ if ($this->checkSignature()==false) { die('非法請求'); } if (isset($_GET["echostr"])) { $echostr = $_GET["echostr"]; echo $echostr; exit(); } else { $this->responseMsg(); } } public function responseMsg(){ //get post data, May be due to the different environments $postStr = file_get_contents("php://input"); if (!empty($postStr)){ libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; // $keyword = trim($postObj->Content); $time = time(); $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; if($postObj->MsgType == 'event'){ $res = $this->reindex(); // 獲取access_token $access_token = $res['access_token']; $msgType = "text"; // 通過二維碼進入 if(isset($postObj->EventKey) && $postObj->EventKey != ''){ $tgzid = $postObj->EventKey; if(substr($tgzid,8)){ $retgzid = substr($tgzid,8); $openid = (new reIndex)->rereselect($retgzid); if($openid != $fromUsername){ $sharesum = (new reIndex)->reupdate($openid); $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$access_token.'&openid='.$fromUsername.'&lang=zh_CN'; $re = json_decode($this->getjson($url),true); $contentStr = '你好,'.$re['nickname'].'歡迎關注香港葵芳!'; $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token; $data = array(); $data = array( "touser" => $openid, "msgtype" => "text", "text" => array( "content" => "已成功分享給用戶".$re['nickname']."已成功分享".$sharesum.'次' ) ); $res = $this->getjson($url,json_encode($data,JSON_UNESCAPED_UNICODE)); var_dump($res); } }else{ $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$access_token.'&openid='.$fromUsername.'&lang=zh_CN'; $re = json_decode($this->getjson($url),true); $contentStr = '你好,'.$re['nickname'].'歡迎關注香港葵芳!'; } }else{ if($postObj->Event == 'subscribe'){ $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$access_token.'&openid='.$fromUsername.'&lang=zh_CN'; $re = json_decode($this->getjson($url),true); $contentStr = '你好,'.$re['nickname'].'歡迎關注香港葵芳!'; } } $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } }else { exit; } } // public function curl_post($url, $data=null,$method='GET', $https=true) { // 創建一個新cURL資源 $ch = curl_init(); // 設置URL和相應的選項 curl_setopt($ch, CURLOPT_URL, $url); //要訪問的網站 //啟用時會將頭文件的信息作為數據流輸出。 curl_setopt($ch, CURLOPT_HEADER, false); //將curl_exec()獲取的信息以字符串返回,而不是直接輸出。 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if($https){ //FALSE 禁止 cURL 驗證對等證書(peer's certificate)。 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //驗證主機 } if($method == 'POST'){ curl_setopt($ch, CURLOPT_POST, true); //發送 POST 請求 //全部數據使用HTTP協議中的 "POST" 操作來發送。 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } // 抓取URL并把它傳遞給瀏覽器 $content = curl_exec($ch); //關閉cURL資源,并且釋放系統資源 curl_close($ch); return json_decode($content,true); } } public function getjson($url,$data=null) { $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER,false); curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false); //不為空,使用post傳參數,否則使用get if($data){ curl_setopt($curl,CURLOPT_POST,1); curl_setopt($curl,CURLOPT_POSTFIELDS,$data); } curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); $output = curl_exec($curl); curl_close($curl); return $output; } private function checkSignature() { $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看