当前位置: 首页>>代码示例>>PHP>>正文


PHP Connect::getOpenId方法代码示例

本文整理汇总了PHP中Connect::getOpenId方法的典型用法代码示例。如果您正苦于以下问题:PHP Connect::getOpenId方法的具体用法?PHP Connect::getOpenId怎么用?PHP Connect::getOpenId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connect的用法示例。


在下文中一共展示了Connect::getOpenId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: callback

 /**
  * 处理callback
  */
 protected function callback()
 {
     //不在开启的登陆方式内直接返回
     if (!$this->allowConnect($this->auth['type'])) {
         $this->response->redirect(Typecho_Common::url('/login', $this->options->index));
     }
     if (empty($this->auth['code'])) {
         $this->response->redirect($this->options->index);
     }
     $callback_url = Typecho_Common::url('/user/oauth?type=' . $this->auth['type'], $this->options->index);
     $this->auth['openid'] = '';
     require_once 'Connect.php';
     //换取access_token
     $this->auth['token'] = Connect::getToken($this->auth['type'], $callback_url, $this->auth['code']);
     if (empty($this->auth['token'])) {
         $this->response->redirect($this->options->index);
     }
     //获取openid
     $this->auth['openid'] = Connect::getOpenId($this->auth['type']);
     if (empty($this->auth['openid'])) {
         $this->response->redirect($this->options->index);
     }
     //使用openid登录
     $this->autoLogin($this->auth['openid'], $this->auth['type']);
     //获取用户昵称
     $this->auth['nickname'] = Connect::getNickName($this->auth['type'], $this->auth['openid']);
     if (empty($this->auth['nickname'])) {
         $this->auth['nickname'] = '关注者' . substr(str_shuffle($this->auth['openid']), 0, 4);
     }
     Typecho_Cookie::set('__user_auth', serialize($this->auth));
     $this->response->redirect($this->___bindUrl());
 }
开发者ID:dccecc,项目名称:typecho,代码行数:35,代码来源:Oauth.php

示例2: callback

 public function callback()
 {
     if (!isset($_SESSION)) {
         session_start();
         if (isset($_SESSION['__typecho_auth'])) {
             $this->auth = $_SESSION['__typecho_auth'];
         }
     }
     if ($this->request->isPost()) {
         $do = $this->request->get('do');
         if (!in_array($do, array('bind', 'reg'))) {
             $this->widget('Widget_Notice')->set(array('错误数据!'), 'error');
             $this->response->goBack();
         }
         if (!isset($this->auth['openid']) || !isset($this->auth['type'])) {
             $this->response->redirect($this->options->index);
         }
         $func = 'doCallback' . ucfirst($do);
         $this->{$func}();
         unset($_SESSION['__typecho_auth']);
         $this->response->redirect($this->options->index);
     }
     $options = TeConnect_Plugin::options();
     if (empty($this->auth)) {
         $this->auth['type'] = $this->request->get('type', '');
         $this->auth['code'] = $this->request->get('code', '');
         //不在开启的登陆方式内直接返回
         if (!isset($options[$this->auth['type']])) {
             $this->response->redirect($this->options->index);
         }
         if (empty($this->auth['code'])) {
             $this->response->redirect($this->options->index);
         }
         $callback_url = Typecho_Common::url('/oauth_callback?type=' . $this->auth['type'], $this->options->index);
         $this->auth['openid'] = '';
         require_once 'Connect.php';
         //换取access_token
         $this->auth['token'] = Connect::getToken($this->auth['type'], $callback_url, $this->auth['code']);
         if (empty($this->auth['token'])) {
             $this->response->redirect($this->options->index);
         }
         //获取openid
         $this->auth['openid'] = Connect::getOpenId($this->auth['type']);
         if (empty($this->auth['openid'])) {
             $this->response->redirect($this->options->index);
         }
         $this->auth['nickname'] = Connect::getNickName($this->auth['type'], $this->auth['openid']);
     }
     //已经登录,重新绑定
     if ($this->user->hasLogin()) {
         /** 绑定用户 */
         $this->bindUser($this->user->uid, $this->auth['openid'], $this->auth['type']);
         //提示绑定成功,并跳转
         // add 跳转提示
         $this->widget('Widget_Notice')->set(array('成功绑定账号!'));
         $this->response->redirect($this->options->index);
     }
     //已经绑定,直接登录
     $isConnect = $this->findConnectUser($this->auth['openid'], $this->auth['type']);
     if ($isConnect) {
         $this->useUidLogin($isConnect['uid']);
         // add 跳转提示
         $this->widget('Widget_Notice')->set(array('已成功登陆!'));
         $this->response->redirect($this->options->index);
     }
     $custom = $this->options->plugin('TeConnect')->custom;
     if (!$custom && !empty($this->auth['nickname'])) {
         $dataStruct = array('screenName' => $this->auth['nickname'], 'created' => $this->options->gmtTime, 'group' => 'subscriber');
         $uid = $this->regConnectUser($dataStruct);
         if ($uid) {
             $this->widget('Widget_Notice')->set(array('已成功注册并登陆!'));
         } else {
             $this->widget('Widget_Notice')->set(array('注册用户失败!'), 'error');
         }
         $this->response->redirect($this->options->index);
     } else {
         if (!isset($_SESSION['__typecho_auth'])) {
             $_SESSION['__typecho_auth'] = $this->auth;
         }
         //未绑定,显示界面
         $this->render('callback.php');
     }
 }
开发者ID:jiangmuzi,项目名称:TeConnect,代码行数:83,代码来源:Widget.php


注:本文中的Connect::getOpenId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。