public function getUserInfo($appIndex, $code)
 {
     $AppKey = Platform::$AppArr[$appIndex];
     $wechat = new WeChat($AppKey['AppID'], $AppKey['AppSecret']);
     $access_token = $this->getAccessToken($appIndex);
     $info = $wechat->getUserInfo($code, $access_token);
     return $info;
 }
Esempio n. 2
0
<?php

require_once '../common/set_inc.php';
if (!isset($_SESSION['openid'])) {
    //没有session,没有通过认证
    $weChat = new WeChat(APPID, APPSECRET, BASEPATH);
    if (isset($_GET['code'])) {
        //有code,已经完成跳转
        $openid = $weChat->Oauth_check($_GET['code']);
        if ($openid) {
            $res = $weChat->getUserInfo($openid);
            if ($res['subscribe'] == 1) {
                //已关注
                $_SESSION['openid'] = $openid;
                //记录用户信息
                $username = $res['nickname'];
                $patService->setDownUserName($openid, $username);
            } else {
                //未关注
                jump(ATTENTION_PAGE);
                exit;
            }
        }
    } else {
        //没有跳转,需要跳转去认证页面
        $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
        $weChat->Oauth_base($url);
        exit;
    }
}
if (isset($_SESSION['openid'])) {