Exemplo n.º 1
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;
 }
Exemplo n.º 2
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('参数错误');
     //加载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);
         if (!$user_info) {
             //登录失败
             $this->error('第三方登录失败,请重新登录', U('login'), 1);
         } else {
             //登录成功
             /*返回格式
              *
              *  [ret] => 0
                 [msg] => 
                 [is_lost] => 0
                 [nickname] => 护士之家网
                 [gender] => 男
                 [province] => 福建
                 [city] => 龙岩
                 [year] => 1985
                 [figureurl] => http://qzapp.qlogo.cn/qzapp/101260590/1C1D1F0487099BF03B1548D21C98221B/30
                 [figureurl_1] => http://qzapp.qlogo.cn/qzapp/101260590/1C1D1F0487099BF03B1548D21C98221B/50
                 [figureurl_2] => http://qzapp.qlogo.cn/qzapp/101260590/1C1D1F0487099BF03B1548D21C98221B/100
                 [figureurl_qq_1] => http://q.qlogo.cn/qqapp/101260590/1C1D1F0487099BF03B1548D21C98221B/40
                 [figureurl_qq_2] => http://q.qlogo.cn/qqapp/101260590/1C1D1F0487099BF03B1548D21C98221B/100
                 [is_yellow_vip] => 1
                 [vip] => 1
                 [yellow_vip_level] => 7
                 [level] => 7
                 [is_yellow_year_vip] => 0
                 
                 
                 
              */
         }
     }
 }