public function wxCallbackAction() { $weixin = new \Ucenter\Utils\WeixinApi($this->di); $acInfo = json_decode($weixin->getAccessToken($_REQUEST['code'], $_REQUEST['state']), true); if (isset($acInfo['errcode'])) { header('Location: /'); } $openId = $acInfo['openid']; $accessToken = $acInfo['access_token']; if ($this->session->has('uid') && isset($openId)) { $user = new Users(); if ($user->getUinfo($openId, 'wx')) { echo '<script>alert("绑定失败,该账号已绑定其他用户");window.location.href="/user/accountbind";</script>'; return; } else { if ($user->bingWX($this->session->get('uid'), $openId)) { $this->response->redirect('user/accountbind'); } else { throw new E('WX bing failed'); } } } else { $user = new Users(); if ($uinfo = $user->getUinfo($openId, 'wx')) { $cas = new \Ucenter\Utils\cas\CAServer(); $this->session->set('uid', $uinfo['u_id']); $this->session->set('uinfo', array('name' => $uinfo['u_name'], 'mobile' => $uinfo['u_mobi'])); $cas->casSave(0, 0); $this->response->redirect('user/index'); } else { //获取用户信息 $uidInfo = json_decode($weixin->getUserInfo($accessToken, $openId), true); if (!isset($uidInfo['openid'])) { header('Location: /'); } $info = array('type' => 'wx', 'name' => $uidInfo['nickname'], 'uids' => $openId, 'pic' => $uidInfo['headimgurl']); setcookie(substr(md5('tmpQqWb'), 8, 20), base64_encode(json_encode($info)), $_SERVER['REQUEST_TIME'] + 1800, '/'); $this->response->redirect('index/addUserInfo'); } } }