Server : nginx/1.22.1
System : Linux iZwz9daxib3w3i063fw434Z 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64
User : www ( 1000)
PHP Version : 7.2.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Directory :  /www/wwwroot/www.jkmold.com/phpcms/modules/member/classes/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : /www/wwwroot/www.jkmold.com/phpcms/modules/member/classes/qqapi.class.php
<?php



class qqapi{



	private $appid,$appkey,$callback,$access_token,$openid;



        public function __construct($appid, $appkey, $callback){

            $this->appid = $appid;

            $this->appkey = $appkey;

            $this->callback = $callback;

            $this->access_token= '';

            $this->openid = '';

        }



        public function redirect_to_login() {

            //跳转到QQ登录页的接口地址, 不要更改!!

            $redirect = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=$this->appid&scope=&redirect_uri=".rawurlencode($this->callback);

            header("Location:$redirect");

        }

        

        

        //获得登录的 openid

        public function get_openid($code){

            $url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=$this->appid&client_secret=$this->appkey&code=$code&redirect_uri=".rawurlencode($this->callback);

            $content = file_get_contents( $url);

            if (stristr($content,'access_token=')) {

                $params = explode('&',$content);

                $tokens = explode('=',$params[0]);

                $token  = $tokens[1];

                $this->access_token=$token;

                if ($token) {

                     $url="https://graph.qq.com/oauth2.0/me?access_token=$token";

                     $content=file_get_contents($url);

                     $content=str_replace('callback( ','',$content);

                     $content=str_replace(' );','',$content);

                     $returns = json_decode($content);

                     $openid = $returns->openid;

                     $this->openid = $openid;

                     $_SESSION["token2"]  = $openid;

                } else {

                    $openid='';

                }

            } elseif (stristr($content,'error')) {

                $openid='';

            }

            return $openid;

        }

        

        /**

        * 返回用户信息

        * 

        */

        public function get_user_info(){

            $url = "https://graph.qq.com/user/get_user_info?access_token=$this->access_token&oauth_consumer_key=$this->appid&openid=$this->openid";

            $content=file_get_contents($url);

            $result = json_decode($content);

            return $result->nickname;

        }

}

?>