如果您想訂閱本博客內(nèi)容,每天自動(dòng)發(fā)到您的郵箱中, 請點(diǎn)這里
    
    
        在微信登錄中,如何和獲取網(wǎng)頁授權(quán)。
    
    
        一、登錄微信測試公眾品平臺,修改網(wǎng)頁授權(quán)基本信息,輸入授權(quán)回調(diào)頁面域名(自己的域名)。
    
    
         
    
    
         
    
    
        然后重新建立一個(gè)tp框架 編寫方法如圖:
    
    
        
        
            - 
                <?php  
            
- 
                namespace Home\Controller;  
            
- 
                use Think\Controller;  
            
- 
                class IndexController extends Controller {  
            
- 
                    public function index(){  
            
- 
                       $appid='wx27f664ab15ecb71d';  
            
- 
                       $redirect_uri=urlencode('http://www.crimson1.top/vote/index.php/home/index/getcode');  
            
- 
                       $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";  
            
- 
                  
            
- 
                             header("Location:".$url);  
            
- 
                    }  
            
- 
                  
            
- 
                    public function getcode(){  
            
- 
                        $code=$_GET["code"];  
            
- 
                         $json=$this->access_token($code);  
            
- 
                         echo $json;  
            
- 
                    }  
            
- 
                    public function access_token($code){  
            
- 
                        $appid="wx27f664ab15ecb71d";  
            
- 
                        $appsecret="015756334f2982ed1189c6d66dbc0353";  
            
- 
                        $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";  
            
- 
                  
            
- 
                        $ret=https_request($url);  
            
- 
                        return $ret;  
            
- 
                    }  
            
- 
                }  
            
 
    
        在公共模塊中新建function.php
    
    
        
        
            - 
                <?php  
            
- 
                function https_request($url){  
            
- 
                    $curl=curl_init();  
            
- 
                    curl_setopt($curl, CURLOPT_URL, $url);  
            
- 
                    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);  
            
- 
                    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);  
            
- 
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  
            
- 
                    $data=curl_exec($curl);  
            
- 
                    if(curl_errno($curl)){  
            
- 
                        return 'ERROR'.curl_error($curl);  
            
- 
                    }  
            
- 
                    curl_close($curl);  
            
- 
                    return $data;  
            
- 
                }  
            
 
    
        在自己的手機(jī)端訪問,就能獲取access_token;
    
藍(lán)藍(lán)設(shè)計(jì)( m.monmeltingpot.net )是一家專注而深入的界面設(shè)計(jì)公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設(shè)計(jì)、BS界面設(shè)計(jì) 、 cs界面設(shè)計(jì) 、 ipad界面設(shè)計(jì) 、 包裝設(shè)計(jì) 、 圖標(biāo)定制 、 用戶體驗(yàn) 、交互設(shè)計(jì)、 網(wǎng)站建設(shè) 、平面設(shè)計(jì)服務(wù)