public function callback($type = null, $code = null)
 {
     (empty($type) || empty($code)) && $this->error('参数错误');
     //加载ThinkOauth类并实例化一个对象
     import("ORG.ThinkSDK.ThinkOauth");
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     $token = $sns->getAccessToken($code, $extend);
     //                echo "<pre>";
     //                var_dump($token);
     //                echo "</pre>";die;
     //获取当前登录用户信息
     if (is_array($token)) {
         //设置登陆成功
         if ($type == "sina") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "sina");
         } elseif ($type == "qq") {
             $this->qqLoginTest($token);
         } elseif ($type == "renren") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "renren");
         } elseif ($type == "weixin") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "weixin");
         }
     } else {
         header("location:?s=/Index/index");
     }
 }
Ejemplo n.º 2
0
 /**
  * callback  登陆后回调地址
  * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
  */
 public function callback()
 {
     $code = I('get.code');
     $type = I('get.type');
     $is_login = is_login();
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => I('get.openid'), 'openkey' => I('get.openkey'));
     }
     $token = $sns->getAccessToken($code, $extend);
     if (empty($token)) {
         $this->error('参数错误');
     }
     $session = array('TOKEN' => $token, 'TYPE' => $type, 'OPENID' => $token['openid'], 'ACCESS_TOKEN' => $token['access_token']);
     session('SYNCLOGIN', $session);
     if ($is_login) {
         $this->dealIsLogin($is_login);
     } else {
         $addon_config = get_addon_config('SyncLogin');
         $check = $this->checkIsSync(array('type_uid' => $token['openid'], 'type' => $type));
         if ($addon_config['bind'] && !$check) {
             redirect(addons_url('SyncLogin://Base/bind'));
         } else {
             $this->unBind();
         }
     }
 }
Ejemplo n.º 3
0
 public function callback($type = null, $code = null)
 {
     header('content-type:text/html;charset=UTF-8;');
     (empty($type) || empty($code)) && $this->error('参数错误');
     //加载ThinkOauth类并实例化一个对象
     import("ThinkSDK");
     $sns = ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => I("get.openid"), 'openkey' => I("get.openkey"));
     }
     //请妥善保管这里获取到的Token信息,方便以后API调用
     //调用方法,实例化SDK对象的时候直接作为构造函数的第二个参数传入
     //如: $qq = ThinkOauth::getInstance('qq', $token);
     $token = $sns->getAccessToken($code, $extend);
     //获取当前登录用户信息
     if (is_array($token)) {
         $user_info = A('Type', 'Event')->{$type}($token);
         if ($_SESSION["MEMBER_type"] == 'local') {
             self::_bang_handle($user_info, $type, $token);
         } else {
             self::_login_handle($user_info, $type, $token);
         }
     } else {
         $this->success('登录失败!', U("Portal/index/index"));
     }
 }
Ejemplo n.º 4
0
 public function callback($type = null, $code = null)
 {
     (empty($type) || empty($code)) && $this->error('参数错误');
     //加载ThinkOauth类并实例化一个对象
     import("ORG.ThinkSDK.ThinkOauth");
     $sns = ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => $this->_get('openid'), 'openkey' => $this->_get('openkey'));
     }
     //请妥善保管这里获取到的Token信息,方便以后API调用
     //调用方法,实例化SDK对象的时候直接作为构造函数的第二个参数传入
     //如: $qq = ThinkOauth::getInstance('qq', $token);
     $token = $sns->getAccessToken($code, $extend);
     //获取当前登录用户信息
     if (is_array($token)) {
         $user_info = A('Type', 'Event')->{$type}($token);
         echo "<h1>恭喜!使用 {$type} 用户登录成功</h1><br>";
         echo "授权信息为:<br>";
         dump($token);
         echo "当前登录用户信息为:<br>";
         dump($user_info);
     }
 }
Ejemplo n.º 5
0
 /**
  * 登陆后回调地址
  */
 public function callback()
 {
     $code = I('get.code');
     $type = I('get.type');
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => I('get.openid'), 'openkey' => I('get.openkey'));
     }
     $token = $sns->getAccessToken($code, $extend);
     //获取第三方Token
     $user_sns_info = \ThinkOauthInfo::$type($token);
     //获取第三方传递回来的用户信息
     $user_sync_info = D('Addons://SyncLogin/SyncLogin')->getUserByOpenidAndType($token['openid'], $type);
     //根据openid等参数查找同步登录表中的用户信息
     $user_sys_info = D('User')->find($user_sync_info['uid']);
     //根据UID查找系统用户中是否有此用户
     if ($user_sync_info['uid'] && $user_sys_info['id'] && $user_sync_info['uid'] == $user_sys_info['id']) {
         //曾经绑定过
         D('Addons://SyncLogin/SyncLogin')->updateTokenByTokenAndType($token, $type);
         D('User')->autoLogin($user_sys_info);
         redirect('http://' . $_SERVER['HTTP_HOST'] . __ROOT__);
     } else {
         //没绑定过,去注册页面
         session('token', $token);
         session('user_sns_info', $user_sns_info);
         $this->assign('user_sns_info', $user_sns_info);
         $this->assign('meta_title', "登陆");
         $this->display(T('Addons://SyncLogin@./default/reg'));
     }
 }
Ejemplo n.º 6
0
 /**
  * 登陆后回调地址
  * autor:xjw129xjt
  */
 public function callback()
 {
     $code = I('get.code');
     $type = I('get.type');
     $is_login = is_login();
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => I('get.openid'), 'openkey' => I('get.openkey'));
     }
     $token = $sns->getAccessToken($code, $extend);
     session('SYNCLOGIN_TOKEN', $token);
     session('SYNCLOGIN_TYPE', $type);
     session('SYNCLOGIN_OPENID', $token['openid']);
     session('SYNCLOGIN_ACCESS_TOKEN', $token['access_token']);
     $check = D('sync_login')->where("`type_uid`='" . $token['openid'] . "' AND type='" . $type . "'")->select();
     $addon_config = get_addon_config('SyncLogin');
     if ($is_login) {
         $this->dealIsLogin($is_login);
     } else {
         if ($addon_config['bind'] && !$check) {
             redirect(addons_url('SyncLogin://Base/bind'));
         } else {
             $this->unbind();
         }
     }
 }
Ejemplo n.º 7
0
 public function getUserInfo($token)
 {
     $sina = \ThinkOauth::getInstance('sina', $token);
     $userInfo = S('sina_user_info_' . $sina->openid());
     if (empty($userInfo)) {
         $userInfo = $sina->call('users/show', "uid={$sina->openid()}");
         S('sina_user_info_' . $sina->openid(), $userInfo, 60 * 60);
     }
     return $userInfo;
 }
Ejemplo n.º 8
0
 /**
  * 合并默认参数和额外参数
  * @param array $params  默认参数
  * @param array/string $param 额外参数
  * @return array:
  */
 protected function param($params, $param)
 {
     $params = parent::param($params, $param);
     /* 签名 */
     ksort($params);
     $param = array();
     foreach ($params as $key => $value) {
         $param[] = "{$key}={$value}";
     }
     $sign = implode('', $param) . $this->AppSecret;
     $params['sig'] = md5($sign);
     return $params;
 }
Ejemplo n.º 9
0
 function bang($type = "")
 {
     if (sp_is_user_login()) {
         empty($type) && $this->error('参数错误');
         //加载ThinkOauth类并实例化一个对象
         import("ThinkOauth");
         $sns = \ThinkOauth::getInstance($type);
         //跳转到授权页面
         $_SESSION['oauth_bang'] = 1;
         redirect($sns->getRequestCodeURL());
     } else {
         $this->error("您还没有登录!");
     }
 }
 public function facebook($token)
 {
     $facebook = \ThinkOauth::getInstance('facebook', $token);
     $data = $facebook->call('me');
     //需要查询facebook的接口说明
     //所有data的索引需要查询facebook的接口说明
     if ($data['name'] != '') {
         $userInfo['type'] = 'FACEBOOK';
         $userInfo['name'] = $data['name'];
         $userInfo['nick'] = $data['name'];
         return $userInfo;
     } else {
         throw_exception("获取FACEBOOK用户信息失败.");
     }
 }
Ejemplo n.º 11
0
 public function sina($token)
 {
     $sina = ThinkOauth::getInstance('sina', $token);
     $data = $sina->call('users/show', "uid={$sina->openid()}");
     if (!empty($data['id'])) {
         $userInfo['openuid'] = $data['id'];
         $userInfo['openkey'] = $data['id'];
         $userInfo['type'] = 'SINA';
         $userInfo['name'] = $data['name'];
         $userInfo['nick'] = $data['screen_name'];
         $userInfo['head'] = $data['avatar_large'];
         return $userInfo;
     } else {
         throw_exception("获取新浪微博用户信息失败:{$data['error']}");
     }
 }
Ejemplo n.º 12
0
 public function callback($type = null, $code = null)
 {
     header("Content-type: text/html; charset=utf-8");
     (empty($type) || empty($code)) && $this->error('参数错误');
     import('Org/ThinkSDK/ThinkOauth');
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => $this->_get('openid'), 'openkey' => $this->_get('openkey'));
     }
     $tokenArr = $sns->getAccessToken($code, $extend);
     $openid = $tokenArr['openid'];
     $token = $tokenArr['access_token'];
     setSessionCookie("openid", $openid);
     setSessionCookie("access_token", $token);
     //获取当前登录用户信息
     if ($openid) {
         $field = strtolower($type);
         setSessionCookie("field", $field);
         $userinfo = M("user")->field('id,username')->where("" . $field . "= '" . $openid . "'")->find();
         if ($userinfo) {
             //若是有该账号就登录
             setSessionCookie("userid", $userinfo['id']);
             setSessionCookie("username", $userinfo['username']);
             $this->redirect('Index/user');
             exit;
         } else {
             //用户未登录,跳转到绑定页面
             if ($filed == 'qq') {
                 //针对新版qq互联在绑定页,要显示昵称,否则不通过***
                 $data = $sns->call('user/get_user_info');
                 $nickname = $data['nickname'];
             } else {
                 $userinfo = A('Type', 'Event')->{$type}($tokenArr);
                 $nickname = $userinfo['name'];
             }
             setSessionCookie('nickname', $nickname);
             $this->redirect('Index/bind');
         }
     } else {
         echo "<script>alert('系统出错;请稍后再试!');document.location.href='" . __APP__ . "';</script>";
     }
 }
Ejemplo n.º 13
0
 public function callback()
 {
     $code = I('get.code');
     $type = I('get.type');
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => I('get.openid'), 'openkey' => I('get.openkey'));
     }
     $token = $sns->getAccessToken($code, $extend);
     $user_info = D('Addons://SyncLogin/SyncLogin')->{$type}($token);
     //获取传递回来的用户信息
     $condition = array('openid' => $token['openid'], 'type' => $type, 'status' => 1);
     $user_info_sync_login = D('sync_login')->where($condition)->find();
     // 根据openid等参数查找同步登录表中的用户信息
     if ($user_info_sync_login) {
         //曾经绑定过
         $user_info_user_center = D('UcenterMember')->find($user_info_sync_login['uid']);
         //根据UID查找Ucenter中是否有此用户
         if ($user_info_user_center) {
             $syncdata['access_token'] = $token['access_token'];
             $syncdata['refresh_token'] = $token['refresh_token'];
             D('sync_login')->where(array('uid' => $user_info_user_center['id']))->save($syncdata);
             //更新Token
             $Member = D('Member');
             if ($Member->login($user_info_user_center['id'])) {
                 $this->assign('jumpUrl', U('Home/Index/index'));
                 $this->success('同步登录成功');
             } else {
                 $this->error($Member->getError());
             }
         } else {
             $condition = array('openid' => $token['openid'], 'type' => $type);
             D('sync_login')->where($condition)->delete();
         }
     } else {
         //没绑定过,去注册页面
         $this->assign('user', $user_info);
         $this->assign('token', $token);
         $this->display(T('Addons://SyncLogin@./default/reg'));
     }
 }
Ejemplo n.º 14
0
 public function callback()
 {
     $code = I('get.code');
     $type = I('get.type');
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => I('get.openid'), 'openkey' => I('get.openkey'));
     }
     $token = $sns->getAccessToken($code, $extend);
     $user_info = D('Addons://SyncLogin/SyncLogin')->{$type}($token);
     //获取传递回来的用户信息
     $condition = array('openid' => $token['openid'], 'type' => $type, 'status' => 1);
     $user_info_sync_login = D('sync_login')->where($condition)->find();
     // 根据openid等参数查找同步登录表中的用户信息
     if ($user_info_sync_login) {
         //曾经绑定过
         $user_info_user_center = D('UcenterMember')->find($user_info_sync_login['uid']);
         //根据UID查找Ucenter中是否有此用户
         if ($user_info_user_center) {
             $syncdata['access_token'] = $token['access_token'];
             $syncdata['refresh_token'] = $token['refresh_token'];
             D('sync_login')->where(array('uid' => $user_info_user_center['id']))->save($syncdata);
             //更新Token
             $Member = D('Member');
             if ($Member->login($user_info_user_center['id'])) {
                 $this->assign('jumpUrl', U('Home/Index/index'));
                 $this->success('同步登录成功');
             } else {
                 $this->error($Member->getError());
             }
         } else {
             $condition = array('openid' => $token['openid'], 'type' => $type);
             D('sync_login')->where($condition)->delete();
         }
     } else {
         //没绑定过,去注册
         //$this->assign ( 'user', $user_info );
         //$this->assign ( 'token', $token );
         // $this->display(T('Addons://SyncLogin@./default/reg'));
         $User = new UserApi();
         $username = $user_info['name'] . "_" . $user_info['nick'];
         $password = "******";
         $email = "*****@*****.**";
         $uid = $User->register($username, $password, $email);
         if (0 < $uid) {
             //TODO: 发送验证邮件
             $data['uid'] = $uid;
             $data['openid'] = $token['openid'];
             $data['type'] = $type;
             $data['access_token'] = $token['access_token'];
             M('sync_login')->add($data);
             /* 登录用户 */
             $Member = D('Member');
             if ($Member->login($uid)) {
                 //登录用户
                 //TODO:跳转到登录前页面
                 $this->success('登录成功!', U('Home/Index/index'));
             }
         } else {
             //注册失败,显示错误信息
             //$this->error($this->showRegError($uid));
             //echo $uid.$token['access_token'];
         }
     }
 }
Ejemplo n.º 15
0
 public function wechat($token)
 {
     //import("ORG.ThinkSDK.ThinkOauth");
     $wechat = ThinkOauth::getInstance('wechat', $token);
     $data = $wechat->call('sns/userinfo');
     if ($data['ret'] == 0) {
         $userInfo['type'] = 'WECHAT';
         $userInfo['name'] = $data['nickname'];
         $userInfo['nick'] = $data['nickname'];
         $userInfo['head'] = $data['headimgurl'];
         return $userInfo;
     } else {
         throw_exception("获取微信用户信息失败:{$data['msg']}");
     }
 }
 public function callback($type = null, $code = null)
 {
     (empty($type) || empty($code)) && $this->error('参数错误');
     //加载ThinkOauth类并实例化一个对象
     import("Org.ThinkSDK.ThinkOauth");
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => $this->_get('openid'), 'openkey' => $this->_get('openkey'));
     }
     //请妥善保管这里获取到的Token信息,方便以后API调用
     //调用方法,实例化SDK对象的时候直接作为构造函数的第二个参数传入
     //如: $qq = ThinkOauth::getInstance('qq', $token);
     $token = $sns->getAccessToken($code, $extend);
     //获取当前登录用户信息
     if (is_array($token)) {
         //设置登陆成功
         if ($type == "sina") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "sina");
         } elseif ($type == "qq") {
             $userinfo = $this->getQqUserinfo($token['access_token']);
             $user_info = $this->std_class_object_to_array(json_decode($userinfo));
             //
             //
             //                echo("<h1>恭喜!使用 {$type} 用户登录成功</h1><br>");
             //                echo("授权信息为:<br>");
             //                dump($token);
             //                echo("当前登录用户信息为:<br>");
             //                dump($user_info);
             //                die;
             //
             //                echo "qq登陆接口测试中,咱不能提供服务<br/>";
             //                echo "<pre>";
             //                var_dump($token);
             //                echo "</pre>";
             //                die;
             $data['username'] = "******" . $user_info['nickname'];
             $this->otherLogin($data, "qq");
         } elseif ($type == "renren") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "renren");
         } elseif ($type == "weixin") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "weixin");
         }
         //            //$user_info = A('Type', 'Event')->$type($token);
         //
         //            echo("<h1>恭喜!使用 {$type} 用户登录成功</h1><br>");
         //            echo("授权信息为:<br>");
         //            dump($token);
         //            echo("当前登录用户信息为:<br>");
         //dump($user_info);
     }
 }
Ejemplo n.º 17
0
 public function sohu($token)
 {
     $sohu = \ThinkOauth::getInstance('sohu', $token);
     $data = $sohu->call('i/prv/1/user/get-basic-info');
     if ('success' == $data['message'] && !empty($data['data'])) {
         $userInfo['type'] = 'SOHU';
         $userInfo['name'] = $data['data']['open_id'];
         $userInfo['nick'] = $data['data']['nick'];
         $userInfo['head'] = $data['data']['icon'];
         return $userInfo;
     } else {
         throw_exception("获取搜狐用户信息失败:{$data['message']}");
     }
 }
 public function callback($type = null, $code = null)
 {
     (empty($type) || empty($code)) && $this->error("您访问的页面不存在,到<a href='http://www.renrenlie.com'>首页</a>去!");
     //加载ThinkOauth类并实例化一个对象
     import("Org.ThinkSDK.ThinkOauth");
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => $this->_get('openid'), 'openkey' => $this->_get('openkey'));
     }
     //请妥善保管这里获取到的Token信息,方便以后API调用
     //调用方法,实例化SDK对象的时候直接作为构造函数的第二个参数传入
     //如: $qq = ThinkOauth::getInstance('qq', $token);
     $token = $sns->getAccessToken($code, $extend);
     //获取当前登录用户信息
     if (is_array($token)) {
         //设置登陆成功
         if ($type == "sina") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "sina");
         } elseif ($type == "qq") {
             //                $user_info = $this->getQqUserinfo($token['access_token']);
             //                $data['username'] = "******" . $user_info['nickname'];
             //
             //
             //                $this->otherLogin($data, "qq");
             $this->qqLoginTest($token);
         } elseif ($type == "renren") {
             $data['username'] = "******" . $token['openid'];
             $this->otherLogin($data, "renren");
         } elseif ($type == "weixin") {
             //var_dump($token);die;
             $data['username'] = "******" . $token['openid'];
             $data['unionid'] = $token['unionid'];
             $this->otherLogin($data, "weixin");
         }
     } else {
         header("location:?s=/Home/Index/index");
     }
 }
Ejemplo n.º 19
0
 public static function weixin($token)
 {
     $weixin = \ThinkOauth::getInstance('weixin', $token);
     $data = $weixin->call('sns/userinfo');
     if ($data['ret'] == 0) {
         $userInfo['type'] = 'WEIXIN';
         $userInfo['name'] = $data['nickname'];
         $userInfo['nick'] = $data['nickname'];
         $userInfo['head'] = $data['headimgurl'];
         return $userInfo;
     } else {
         throw_exception("获取微信用户信息失败:{$data['errmsg']}");
     }
 }
 public function callback($type = null, $code = null)
 {
     (empty($type) || empty($code)) && $this->error('参数错误');
     //加载ThinkOauth类并实例化一个对象
     import("Org.ThinkSDK.ThinkOauth");
     $sns = \ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => $this->_get('openid'), 'openkey' => $this->_get('openkey'));
     }
     //请妥善保管这里获取到的Token信息,方便以后API调用
     //调用方法,实例化SDK对象的时候直接作为构造函数的第二个参数传入
     //如: $qq = ThinkOauth::getInstance('qq', $token);
     $token = $sns->getAccessToken($code, $extend);
     //获取当前登录用户信息
     if (is_array($token)) {
         $user_info = A('Type', 'Event')->{$type}($token);
         $this->checkExistingUserInformation($token['openid'], $user_info);
     }
 }