20,398
社区成员




class WxloginController extends Controller{
public $user_info;//微信账号信息
public function actionIndex(){
$class =new wxlogin();
$redirect_url = "http://域名/wxlogin/callback";
$state = "STATE";
$data = $class->get_authorize_url($redirect_url,$state);
}
public function actionCallback(){
$class = new wxlogin();
$code = $_GET['code'];
if(!$code)
$this->redirect('/');
$arr = $class->get_access_token('','',$code);
if(!$arr)
$this->redirect('/');
$userinfo = $class->get_user_info($arr['access_token'],$arr['openid']);//获得微信用户信息
if(!$userinfo)
$this->redirect('/');
//nickname,openid,sex,language,city,province,country,headimageurl,微信用户参数
//echo "<script>alert('您使用微信账号登陆成功!');window.location.href='/'</script>";
}
wxlogin这个类 就是企鹅提供的SDK类 改$app_id,$app_secret即可