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


PHP Wechat::getUserInfo方法代码示例

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


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

 /**
  * 授权回调
  * @param string $code
  * @param string $data
  * @throws CException
  * @throws Exception
  */
 public function actionWechat($code = '', $data = '')
 {
     Yii::import('ext.wechat.*');
     //判断不同授权来源
     //code: 正常微信授权的参数
     //data: 群友代理授权json
     if (!empty($code)) {
         $wehcat = Yii::app()->params['wechat'];
         $wechat = new Wechat($wehcat['appid'], $wehcat['appsecret']);
         $accessToken = $wechat->getAccessToken($code);
         if (!empty($accessToken) && !empty($accessToken['openid'])) {
             $openid = $accessToken['openid'];
             $wechat = new Wechat($wehcat['appid'], $wehcat['appsecret'], $accessToken['access_token']);
             $data = $wechat->getUserInfo($openid);
         }
     } else {
         if (!empty($data)) {
             $data = json_decode(base64_decode($data), 1);
             if (!empty($data['openid'])) {
                 $openid = $data['openid'];
             }
         }
     }
     //都不存在时,创建一个默认帐号
     if (empty($openid)) {
         $openid = 'temp-' . md5(microtime());
         $data = array();
     }
     $user = UserService::instance()->save($openid, $data);
     //登录
     $identity = new UserIdentity($user);
     if ($identity->authenticate()) {
         Yii::app()->user->login($identity, 24 * 3600 * 30);
         $returnUrl = Yii::app()->user->returnUrl;
         $this->redirect(!empty($returnUrl) ? $returnUrl : Yii::app()->homeUrl);
     } else {
         exit('很抱歉,微信授权失败!');
     }
 }
开发者ID:vikaanet,项目名称:v5,代码行数:46,代码来源:OauthController.php

示例3: wechatCallback

 /**
  * 微信登录回调
  */
 public function wechatCallback()
 {
     require_once APP_DIR . "vendors/auth/wechat.php";
     $wechat = new \Wechat();
     $code = $this->input->get('code');
     if (!$code) {
         echo 'code error';
         return;
     }
     //授权之后的操作,默认是登录
     $auth_action = $this->input->cookie('auth_action');
     if (!$auth_action) {
         $auth_action = isset($_REQUEST['auth_action']) ? $_REQUEST['auth_action'] : '';
     }
     if ($auth_action) {
         //清楚此临时cookie
         $this->output->cookie(['auth_action' => ''], 0);
     } else {
         $auth_action = 'login';
     }
     //哪个app的操作
     $app = $this->input->cookie('app');
     if ($app) {
         //清楚此临时cookie
         $this->output->cookie(['app' => ''], 0);
     } else {
         $app = 'okay';
     }
     $data = $wechat->getAccessToken($code);
     if (!$data) {
         echo 'access token error';
         return;
     }
     $token = $data['access_token'];
     $openid = $data['openid'];
     $unionid = $data['unionid'];
     $account = $this->related_account->one($unionid);
     $isopenid = false;
     if (!$account) {
         $account = $this->related_account->one($openid);
         $isopenid = true;
     }
     if ($auth_action == 'login') {
         if ($account) {
             // 转移数据
             $this->transferData($account->uid);
             //如果是openid登录替换成unionid
             if ($isopenid) {
                 $this->related_account->update(['app_uid' => $unionid], ['app_uid' => $openid, 'uid' => $account->uid, 'app_id' => $this->config->logintype['wechat']]);
             }
             //查询用户
             $user = $this->user->one($account->uid);
             //执行同步登录(手机,网页,扩展)
             $logindata = $this->helper->user->getUserLoginInfo($user);
             $token = $this->helper->user->setUserLoginCookie($logindata);
             if ($app == 'okay') {
                 $this->model('passport')->login($account->uid, 'password');
                 //方片登录
             } else {
                 /*$info       = array('uid'     => $user->uid,      'mail'     => $user->mail, 
                                                         'nickname'=> $user->nickname, 'signature'=> $user->signature, 'avatar'=>$user->avatar_url);
                 
                 
                                     //过期时间
                                     $time       = 3600 * 24 * 90;
                                     $endtime    = time() + $time;
                 
                 
                                     //授权令牌
                                     $token      = $this->helper->auth->getToken(md5($token . time() . $user->uid . $endtime));
                                     $this->redis('w')->set($token, $info, $endtime);
                 
                 
                                     //数据包
                                     $data       = array('user'  => $info, 'token'  => $token, 'expire' => $endtime );
                                     $this->output->cookie(['token'=>$token], $endtime, '/', '.funp.in', false, true);*/
                 if ($app == 'wechat_website') {
                     $this->output->redirect(MOBILE_API . 'website.php');
                 }
             }
             $token = isset($token) ? $token : null;
             $this->output->view('passport/wechat', ['uid' => $account->uid]);
         } else {
             $userinfo = $wechat->getUserInfo($token, $openid);
             //判断nickname是否存在
             $userinfo['nickname'] = str_replace(' ', '_', trim($userinfo['nickname']));
             if ($this->user->isNicknameExist($userinfo['nickname'])) {
                 $userinfo['nickname'] = $userinfo['nickname'] . '_' . substr(md5(time()), 0, 2);
             }
             $data = ['with_openid' => 1, 'nickname' => trim($userinfo['nickname']), 'created' => time(), 'modified' => time(), 'login_ip' => ip2long($this->input->ip())];
             $uid = $this->user->insert($data);
             if ($uid) {
                 $this->user_config->insert(['uid' => $uid]);
                 // 添加默认标签
                 $this->tag->addDefaultTags($uid);
                 // 转移数据
                 $this->transferData($account->uid);
//.........这里部分代码省略.........
开发者ID:beyondye,项目名称:ENPHP,代码行数:101,代码来源:passport.php

示例4: switch

$type = $weObj->getRev()->getRevType();
$openid = $weObj->getRev()->getRevFrom();
_log1(json_encode(['type' => $type, 'openid' => $openid]));
switch ($type) {
    case Wechat::MSGTYPE_TEXT:
        $text = $weObj->getRev()->getRevContent();
        $weObj->transfer_customer_service()->reply();
        break;
    case Wechat::MSGTYPE_EVENT:
        $event = $weObj->getRev()->getRevEvent();
        _log1(json_encode(['event' => $event]));
        switch ($event['event']) {
            case Wechat::EVENT_SUBSCRIBE:
                $bind_url = $csc_url_base . '/dynamic/user_isbind_csc.php?openid=' . $openid . '&bcb=user_bind_check_csc&rand=' . rand();
                $weObj->text("您好!欢迎来到万国数据客户服务中心。\n\n" . "若您是万国数据的授权用户,您可以在绑定账号后体验我们为您带来的更多专属服务喔~\n" . "<a href=\"" . $bind_url . "\">点击这里绑定账号</a>\n\n" . "如有疑问,欢迎您直接留言。")->reply();
                $user = $weObj->getUserInfo($openid);
                _log_focus($openid, 'focus', $user);
                break;
            case Wechat::EVENT_UNSUBSCRIBE:
                _log_focus($openid, 'unfocus');
            case Wechat::EVENT_MENU_CLICK:
                $key = $event['key'];
                switch ($key) {
                    case 'wechat_csc':
                        $kf_list = $weObj->getCustomServiceOnlineKFlist();
                        $kf_count = count($kf_list);
                        if ($kf_count <= 0) {
                            $weObj->text('我们的客服都在紧张地忙碌中,暂时无法及时响应,请稍作等待。' . '您也可以致电万国数据400热线:<a href="tel:4000724366">4000-724-366</a>,' . '我们会有电话客服专员专门响应您的请求。')->reply();
                        } else {
                            $weObj->text('目前共有 ' . $kf_count . ' 位客服在线。' . '我们会以最快的速度给予响应')->reply();
                        }
开发者ID:adexbn,项目名称:gds_wechat,代码行数:31,代码来源:api_csc.php

示例5: init

 public function init($type = 'member')
 {
     $agent = $_SERVER['HTTP_USER_AGENT'];
     if (strpos($agent, "icroMessenger") && (!isset($_GET['uid']) && empty($_SESSION["uid"]) || isset($_GET['refresh']))) {
         import('Wechat', APP_PATH . 'Common/Wechat', '.class.php');
         $config = M("Wxconfig")->where(array("id" => "1"))->find();
         $options = array('token' => $config["token"], 'encodingaeskey' => $config["encodingaeskey"], 'appid' => $config["appid"], 'appsecret' => $config["appsecret"], 'partnerid' => $config["partnerid"], 'partnerkey' => $config["partnerkey"], 'paysignkey' => $config["paysignkey"]);
         $weObj = new Wechat($options);
         $info = $weObj->getOauthAccessToken();
         if (!$info) {
             $callback = 'http://' . $_SERVER['SERVER_NAME'] . U("App/Index/{$type}", $_GET);
             $url = $weObj->getOauthRedirect($callback, '', 'snsapi_base');
             header("Location: {$url}");
             exit;
         } else {
             $_SESSION['uid'] = $_POST['uid'] = $_GET['uid'] = $info['openid'];
         }
     }
     if (!empty($_SESSION["uid"]) && empty($_GET['uid'])) {
         $_GET['uid'] = $_SESSION["uid"];
     }
     if ($_GET['uid']) {
         $uid = $_SESSION["uid"] = $_GET['uid'];
         $usersresult = R("Api/Api/getuser", array($uid));
         if (strpos($agent, "icroMessenger") && strlen($uid) > 10) {
             if ($usersresult['wx_info'] == null || $usersresult['wx_info'] == false || $usersresult['wx_info'] == 'false' || $usersresult['wx_info'] == 'null') {
                 $wx_info = $weObj->getUserInfo($uid);
                 if ($wx_info['subscribe'] != 1) {
                     if ($type != 'index_info') {
                         exit('请先关注公众号!');
                     }
                 } else {
                     if (empty($usersresult)) {
                         $user = array();
                         $user["uid"] = $uid;
                         $usersresult['id'] = M("User")->add($user);
                     }
                     $user['id'] = $usersresult['id'];
                     $user['wx_info'] = json_encode($wx_info);
                     $user_id = M("User")->save($user);
                 }
             }
         }
         //更新我的可提现金额
         $where = array();
         $where["level_id"] = $usersresult['id'];
         $where["status"] = 2;
         $where["active_time"] = array('elt', date('Y-m-d H:i:s'));
         $result = M("Order_level")->where($where)->select();
         foreach ($result as $info) {
             $level_id = $info['level_id'];
             $price = $info['price'];
             M("User")->where(array('id' => $level_id))->setInc('price', $price);
             M("Order_level")->where(array('id' => $info['id']))->save(array('status' => 3));
             M("Order")->where(array('orderid' => $info['order_id']))->save(array('order_status' => 3));
         }
         //7天未确认的,自动收获
         $where = array();
         $where["order_status"] = 1;
         $where["pay_status"] = 1;
         $tixianinfo = array();
         $tixianinfo['shouhuo'] = 7;
         $tixianinfo['tixian'] = 7;
         $tixianinfo['jine'] = 50;
         if (file_exists('./Public/Conf/tixianinfo.php')) {
             require './Public/Conf/tixianinfo.php';
             $tixianinfo = json_decode($tixianinfo, true);
         }
         $date = strtotime("-{$tixianinfo['shouhuo']} days");
         $date = date('Y-m-d H:i:s', $date);
         $where["time"] = array('elt', $date);
         $result = M("Order")->where($where)->select();
         foreach ($result as $info) {
             $out_trade_no = $info['orderid'];
             $this->confirm_order_status($out_trade_no);
         }
         //分销保持资格
         $this->fenxiao_zige($usersresult);
     } else {
         $url = 'http://' . $_SERVER['SERVER_NAME'] . U('App/Member/login');
         header("Location: {$url}");
         exit;
     }
 }
开发者ID:zhezhisama,项目名称:zz,代码行数:84,代码来源:IndexAction.class.php

示例6: getAllUserInfo

 function getAllUserInfo()
 {
     echo "helo";
     ini_set('max_execution_time', '0');
     import('ORG.wechat');
     $options = array('appid' => 'wx35a55b1c419603dc', 'appsecret' => 'ce22a59f9459611c9c38d17721659b95');
     $weObj = new Wechat($options);
     $yidong3DB = M('yidong3');
     $yidong4DB = M('yidong4');
     for ($i = 11514; $i <= 27776; $i++) {
         $user = $yidong3DB->where(array('id' => $i))->find();
         $userinfo = $weObj->getUserInfo($user['open_id']);
         p($user['open_id']);
         $daochu['open_id'] = $userinfo['openid'];
         $daochu['unionid'] = $userinfo['unionid'];
         $daochu['nickname'] = $userinfo['nickname'];
         $daochu['subscribe_time'] = $userinfo['subscribe_time'];
         $yidong4DB->data($daochu)->add();
     }
     exit;
 }
开发者ID:DearMe,项目名称:zsfb,代码行数:21,代码来源:TestAction.class.php

示例7: array

                     $w->text($returntips)->reply();
                     //4.如果2的结果是没有,提示:xx请点击下方借车按钮进行借车
                 } else {
                     $content = "当前站点车辆不足";
                     $w->text($content)->reply();
                 }
             } else {
                 $content = "系统中无此站点信息";
                 $w->text($content)->reply();
             }
         } else {
             $w->text($systemError)->reply();
         }
     }
 } else {
     $userinfo = $w->getUserInfo($w->getRevFrom());
     $postUserinfoUrl = $apiUrl . "/postUserinfo." . $apiSuffix;
     $param = array('wechatId' => $w->getRevFrom(), 'wechatName' => $userinfo['nickname'], 'gender' => $userinfo['sex'], 'headImgUrl' => $userinfo['headimgurl'], 'createAt' => $w->getRevCtime());
     $postUserinfo = json_decode(http_post($postUserinfoUrl, $param));
     if ($postUserinfo->status == "0") {
         $getStationUrl = $apiUrl . "/getStation." . $apiSuffix . "?stationId=" . $w->getRevSceneId();
         $stationInfo = json_decode(http_get($getStationUrl));
         if ($stationInfo->status == "0") {
             if ($stationInfo->info->number > 0) {
                 $lendtips = "尊敬的用户" . $userinfo['nickname'] . ",请在3分钟内点击下方的借车按钮进行借车";
                 $w->text($lendtips)->reply();
             } else {
                 $content = "当前站点车辆不足";
                 $w->text($content)->reply();
             }
         } else {
开发者ID:MiaoMiaosha,项目名称:bike,代码行数:31,代码来源:wechat.php

示例8: array

<?php

/**
 * Created by PhpStorm.
 * User: run
 * Date: 2015/7/15
 * Time: 11:36
 */
include "wechat.class.php";
$options = array('token' => 'vonvon', 'encodingaeskey' => 'encodingaeskey', 'appid' => 'wx519f23f4a45e8c37', 'appsecret' => 'ea8f0b17b3a0882bf5fda7ed27758482');
$weObj = new Wechat($options);
$weObj->valid();
//明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败
$openid = $weObj->getRev()->getRevFrom();
$token = $weObj->checkAuth();
$info = $weObj->getUserInfo($openid);
$type = $weObj->getRev()->getRevType();
switch ($type) {
    case Wechat::MSGTYPE_TEXT:
        $content = $weObj->getRev()->getRevContent();
        if (substr($content, 0, 6) == '姓名') {
            $name = substr($content, 6);
            $res = array("0" => array('Title' => $name . ', 你的生辰八字', 'Description' => 'Vonvon作为国际化的SNS社交媒体,从2015年1月起,在全世界已经拥有1亿以上的 用户。现在已在韩国,中国,台湾,泰国,越南,印尼,美国,巴西,西班牙等国家 开放。将来会拓展到更多的国家,并且会创作更多有趣的主题测试。', 'PicUrl' => 'http://cdn-cn-static-dr.vonvon.net/images/cn/recruit_main.jpg', 'Url' => 'http://cn.vonvon.net/'));
            $weObj->news($res)->reply();
        } else {
            $weObj->text("Your nickname is " . $info['nickname'] . "\nYour sex is " . $info['sex'] . "\nYour city is " . $info['city'] . "\nYour province is " . $info['province'] . "\n Your country is " . $info['country'] . "\nYour headimgurl is " . $info['headimgurl'] . "\nYour subscribe_time is " . date("Y-m-d H:i:s", $info['subscribe_time']) . "\nNow is " . date("Y-m-d H:i:s", time()))->reply();
            exit;
        }
        break;
    case Wechat::MSGTYPE_EVENT:
        $event = $weObj->getRev()->getRevEvent();
开发者ID:shengnwen,项目名称:vonvonWX,代码行数:31,代码来源:index.php


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