public function WeiboCallback() { session_start(); $_config = $this->_WBconfig; $weibo = new WeiboModel($_config['WB_AKEY'], $_config['WB_SKEY']); if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = $_config['WB_CALLBACK_URL']; $token = $weibo->getAccessToken('code', $keys); } if ($token) { $accessToken = $token['access_token']; $list = new WeiboClientModel($_config['WB_AKEY'], $_config['WB_SKEY'], $accessToken); $uid_get = $list->get_uid(); $uid = $uid_get['uid']; $user_message = $list->show_user_by_id($uid); //根据ID获取用户等基本信息 $res = array(); $res['nickname'] = $user_message['name']; $res['img'] = $user_message['avatar_large']; $res['location'] = $user_message['location']; $res['IP'] = get_client_ip(); $res['weibo_id'] = (int) $user_message['id']; $_SESSION['weibo'] = $res; //将用户信息存入数据库 $obj = new CommentuserModel(); //查找该用户是否绑定过 $one = $obj->findUserByWeiboId($res['weibo_id']); if ($one) { //如果已经登陆,判断用户信息是否有变更,如果有就更新数据库 if ($one['img'] != $res['img'] || $one['nickname'] != $res['nickname'] || $one['location'] != $res['location']) { $obj->updateUserByWeiboId($user_message['id'], $res); } } else { //没有绑定过进行绑定 $res['join_time'] = time(); $obj->addUser($res); } //如果传入的url为空,值跳转到前两页 if (empty($_SESSION['url'])) { echo '<script>window.history.go(-2);</script>'; } else { header("location:" . $_SESSION['url']); } // echo '<script>window.opener.location.href = window.opener.location.href;window.close();</script>'; } else { echo '登录失败,请重试'; } }
public function shareComment() { $id = (int) doSafe($_POST['articleId']); $comment_info = doSafe($_POST['info']); if (empty($id) || empty($comment_info)) { echo json_encode(0); exit; } //根据微博id找到userID $commentUser = new CommentuserModel(); $user = $commentUser->findUserByWeiboId($_SESSION['weibo']['weibo_id']); $userId = $user['comment_user_id']; $addArr = array('comment_user_id' => $userId, 'article_id' => $id, 'comment_info' => $comment_info, 'comment_time' => time()); $comment = new CommentModel(); if ($comment->addComment($addArr)) { echo json_encode(2); exit; } else { echo json_encode(1); exit; } }