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


PHP Wechat::getOauthUserinfo方法代码示例

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


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

示例1: wxoauth

 public function wxoauth()
 {
     $scope = 'snsapi_base';
     $code = isset($_GET['code']) ? $_GET['code'] : '';
     $token_time = isset($_SESSION['token_time']) ? $_SESSION['token_time'] : 0;
     if (!$code && isset($_SESSION['open_id']) && isset($_SESSION['user_token']) && $token_time > time() - 3600) {
         if (!$this->wxuser) {
             $this->wxuser = $_SESSION['wxuser'];
         }
         $this->open_id = $_SESSION['open_id'];
         return $this->open_id;
     } else {
         $options = array('token' => $this->options["token"], 'appid' => $this->options["appid"], 'appsecret' => $this->options["appsecret"]);
         $we_obj = new Wechat($options);
         if ($code) {
             $json = $we_obj->getOauthAccessToken();
             if (!$json) {
                 unset($_SESSION['wx_redirect']);
                 die('获取用户授权失败,请重新确认');
             }
             $_SESSION['open_id'] = $this->open_id = $json["openid"];
             $access_token = $json['access_token'];
             $_SESSION['user_token'] = $access_token;
             $_SESSION['token_time'] = time();
             $userinfo = $we_obj->getUserInfo($this->open_id);
             if ($userinfo && !empty($userinfo['nickname'])) {
                 $this->wxuser = array('open_id' => $this->open_id, 'nickname' => $userinfo['nickname'], 'sex' => intval($userinfo['sex']), 'location' => $userinfo['province'] . '-' . $userinfo['city'], 'avatar' => $userinfo['headimgurl']);
             } elseif (strstr($json['scope'], 'snsapi_userinfo') !== false) {
                 $userinfo = $we_obj->getOauthUserinfo($access_token, $this->open_id);
                 if ($userinfo && !empty($userinfo['nickname'])) {
                     $this->wxuser = array('open_id' => $this->open_id, 'nickname' => $userinfo['nickname'], 'sex' => intval($userinfo['sex']), 'location' => $userinfo['province'] . '-' . $userinfo['city'], 'avatar' => $userinfo['headimgurl']);
                 } else {
                     return $this->open_id;
                 }
             }
             if ($this->wxuser) {
                 $_SESSION['wxuser'] = $this->wxuser;
                 $_SESSION['open_id'] = $json["openid"];
                 unset($_SESSION['wx_redirect']);
                 return $this->open_id;
             }
             $scope = 'snsapi_userinfo';
         }
         if ($scope == 'snsapi_base') {
             $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             $_SESSION['wx_redirect'] = $url;
         } else {
             $url = $_SESSION['wx_redirect'];
         }
         if (!$url) {
             unset($_SESSION['wx_redirect']);
             die('获取用户授权失败');
         }
         $oauth_url = $we_obj->getOauthRedirect($url, "wxbase", $scope);
         header('Location: ' . $oauth_url);
     }
 }
开发者ID:pinghu1,项目名称:wechat-php-sdk,代码行数:57,代码来源:auth.php

示例2: array

<?php

header("Content-Type: text/html; charset=UTF-8");
include "wechat.class.php";
$options = array('token' => 'vonvon', 'encodingaeskey' => 'encodingaeskey', 'appid' => 'wx519f23f4a45e8c37', 'appsecret' => 'ea8f0b17b3a0882bf5fda7ed27758482');
$weObj = new Wechat($options);
$data = $weObj->getOauthAccessToken();
//$new = $weObj->getOauthRefreshToken($data['refresh_token']);
$info = $weObj->getOauthUserinfo($data['access_token'], $data['openid']);
switch ($info['sex']) {
    case '1':
        $info['sex'] = '男';
        break;
    case '2':
        $info['sex'] = '女';
        break;
    default:
        $info['sex'] = '未知';
}
require_once "js/jssdk.php";
$jssdk = new JSSDK("wx519f23f4a45e8c37", "ea8f0b17b3a0882bf5fda7ed27758482");
$signPackage = $jssdk->GetSignPackage();
?>
<!DOCTYPE html><html lang="zh-CN" class="ua-wk ua-win ua-win-nt6 ua-win-nt63">
<!-- date: 2015-07-17 -->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=0" />
<title>哆啦A梦:最后的礼物</title>
<link rel="shortcut icon" type="image/x-icon" href="http://lxfm-s.malmam.com/images/lvxingfm_favicon.ico" />
<link rel="icon" type="image/x-icon" href="http://lxfm-s.malmam.com/images/lvxingfm_favicon.ico" />
开发者ID:shengnwen,项目名称:vonvonWX,代码行数:31,代码来源:doraemon.php

示例3: model

 /**
  * 微信OAuth操作
  */
 static function do_oauth()
 {
     // 默认公众号信息
     $wxinfo = model('Base')->model->table('wechat')->field('id, token, appid, appsecret, oauth_redirecturi, type, oauth_status')->where('default_wx = 1 and status = 1')->find();
     if (!empty($wxinfo) && $wxinfo['type'] == 2) {
         $config['token'] = $wxinfo['token'];
         $config['appid'] = $wxinfo['appid'];
         $config['appsecret'] = $wxinfo['appsecret'];
         // 微信通验证
         $weObj = new Wechat($config);
         // 微信浏览器浏览
         if (self::is_wechat_browser() && ($_SESSION['user_id'] === 0 || empty($_SESSION['openid'])) && !empty($wxinfo['oauth_status'])) {
             if ($_GET['sale']) {
                 session('sale_id', I('get.sale'));
             }
             if (!isset($_SESSION['redirect_url'])) {
                 session('redirect_url', __HOST__ . $_SERVER['REQUEST_URI']);
             }
             $url = $weObj->getOauthRedirect($wxinfo['oauth_redirecturi'], 1);
             if (isset($_GET['code']) && !empty($_GET['code'])) {
                 $token = $weObj->getOauthAccessToken();
                 if ($token) {
                     $userinfo = $weObj->getOauthUserinfo($token['access_token'], $token['openid']);
                     self::update_weixin_user($userinfo, $wxinfo['id'], $weObj);
                     if (!empty($_SESSION['redirect_url'])) {
                         $redirect_url = session('redirect_url');
                         header('Location:' . $redirect_url, true, 302);
                         exit;
                     }
                 } else {
                     header('Location:' . $url, true, 302);
                     exit;
                 }
             } else {
                 header('Location:' . $url, true, 302);
                 exit;
             }
         }
     }
 }
开发者ID:noikiy,项目名称:shop-3,代码行数:43,代码来源:WechatController.class.php

示例4: getToken

 function getToken($url)
 {
     //引入微信类库
     APP::load(APP_FILE . 'common/class/wechat.class.php');
     $weObj = new Wechat(APP::$config['wechat']);
     // 注意 URL 一定要动态获取,不能 hardcode.
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
     $uri = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
     $signPackage = $weObj->getJsSign($uri);
     if (!isset($_GET['code'])) {
         header("Location: " . $url);
         exit;
     }
     $data = $weObj->getOauthAccessToken();
     if (!$data) {
         header("Location: " . $url);
         exit;
     }
     $userinfo = $weObj->getOauthUserinfo($data['access_token'], $data['openid']);
     $this->assign('signPackage', $signPackage);
     $_SESSION['openid'] = $data['openid'];
 }
开发者ID:eyblog,项目名称:mvc,代码行数:22,代码来源:cpController.class.php


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