'text' , 'name'=>'APP_KEY', 'value'=>''), array('type'=>'text' , 'name' => 'APP_SECRET' , 'value' => ''), ); } if (!defined('WEBSITE')) { include_once(dirname(__FILE__).'/oath2.class.php'); class website extends oath2 { function website() { $this->app_key = APP_KEY; $this->app_secret = APP_SECRET; $this->scope = 'snsapi_login'; //by tiandi authorizeURL是用来PHP打开微信登录时用,JS调用则不用authorizeURL。 $this->authorizeURL = 'https://open.weixin.qq.com/connect/qrconnect'; $this->tokenURL = 'https://api.weixin.qq.com/sns/oauth2/access_token'; $this->refreshtokenURL = 'https://api.weixin.qq.com/sns/oauth2/refresh_token'; $this->userURL = 'https://api.weixin.qq.com/sns/userinfo'; $this->meth = 'GET'; } function Code2Token($code) { $params = 'appid='.$this->app_key.'&secret='.$this->app_secret.'&code='.$code. '&grant_type=authorization_code'; $tokenurl = $this->tokenURL."?". $params; $token = $this->http($tokenurl, 'GET'); $token = json_decode($token , true); return $token; } function GetRefreshToken($token) { $params = 'appid='.$this->app_key.'&grant_type=refresh_token&refresh_token='.$token; $tokenurl = $this->refreshtokenURL."?". $params; $token = $this->http($tokenurl, 'GET'); $token = json_decode($token , true); return $token; } function Getinfo($token,$openid) { $params = 'access_token='.$token.'&openid='.$openid; $userurl = $this->userURL."?". $params; $userinfo = $this->http($userurl, 'GET'); return json_decode($userinfo , true); } } }