pc微信扫码登录

服务器端:

<?php
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
include_once(dirname(__FILE__).'/includes/cls_sms.php');

/* 载入语言文件 */
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');

$user_id = $_SESSION['user_id'];
$action  = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';

$affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
$smarty->assign('affiliate', $affiliate);
$back_act='';

$code = $_GET["code"];
$appid = "wx8385370a896e5d69";
$secret = "839740e35dfd1c203b18fbcc45c36711";
if (!empty($code)){
    //通过code获得 access_token + openid
    $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid
        . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code";
    $jsonResult = file_get_contents($url);
    $resultArray = json_decode($jsonResult, true);
    $access_token = $resultArray["access_token"];
    $openid = $resultArray["openid"];

//通过access_token + openid 获得用户所有信息,结果全部存储在$infoArray里
    $infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $openid;
    $infoResult = file_get_contents($infoUrl);
    $infoArray = json_decode($infoResult, true);
    $openid = "SELECT * FROM ecs_users WHERE wxid = '".$infoArray['openid']."'";
    $get_openid = $db->getRow($openid);
    if (empty($get_openid)){
        header("Location:/user.php?act=bangding&openid={$infoArray['openid']}&nickname={$infoArray['nickname']}&sex={$infoArray['sex']}&city={$infoArray['city']}&country={$infoArray['country']}&province={$infoArray['province']}&language={$infoArray['language']}&headimgurl={$infoArray['headimgurl']}");
    }else {
        $_SESSION['user_id'] = $get_openid['user_id'];
        $_SESSION['user_name'] = $get_openid['user_name'];
        update_user_info();
        recalculate_price();
        $ucdata = isset($user->ucdata)? $user->ucdata : '';
        show_message($_LANG['login_success'] . $ucdata ,array($back_act,'user.php'), 'info');
    }
}

显示二维码

$get_code = "SELECT * FROM ecs_shop_config WHERE code = 'wechat_login'";
    $result = $db->getRow($get_code);
    $result['value'] = unserialize($result['value']);
    $snsapi_userInfo_url = "https://open.weixin.qq.com/connect/qrconnect?appid=".$result['value']['appid']."&redirect_uri=".$result['value']['redirect_uri']."&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect";
    $smarty->assign('snsapi_userInfo_url',$snsapi_userInfo_url);

ishow.bind-time.com Copyright © 2020 小肥青王二狗

添加新评论

快乐地过是一天,不快乐地过也是一天,我为什么不快快乐乐地过每一天呢?

岂能尽随人愿,但求无愧我心。

在你内心深处,还有无穷的潜力,有一天当你回首看时,你就会知道这绝对是真的。

活在当下,别在怀念过去或者憧憬未来中浪费掉你现在的生活。

挫折时,要像大树一样,被砍了,还能再长;也要像杂草一样,虽让人践踏,但还能勇敢地活下去。