zoukankan      html  css  js  c++  java
  • 微信 之网页授权登录

    index.php

    <?php
    session_start();
    include_once '../wechat.class.php';
    $options = include_once '../config.php';
    $wechat = new Wechat($options);
    if (!$_SESSION['username']) {
        header("location: login.php");
    }
    if ($_GET['code']) {
        $oauth_info = $wechat->getOauthAccessToken();
        $user_info = $wechat->getOauthUserinfo($oauth_info['access_token'], $oauth_info['openid']);
        $_SESSION['username'] = $user_info['nickname'];
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>网页授权</title>
    </head>
    <body>
    <a href="#"><?php echo $_SESSION['username']?>,授权登录成功</a>
    <a href="logout.php">退出登录</a>
    </body>
    </html>

    login.php

    include_once '../wechat.class.php';
    $options = include_once '../config.php';
    $wechat = new Wechat($options);
    
    $redirect = "http://www.boyuan.com/api/a/weixin/temp/index.php";
    header("location:" . $wechat->getOauthRedirect($redirect));

    config.php

    return $options = array(
        'token' => 'vEeApDmLdwX7UnX7GL', //填写你设定的key
        'encodingaeskey' => 'znyEPja2gZQ71TguwWIXGVhAeaaja5AGdTgncu0b6d3', //填写加密用的EncodingAESKey
        'appid' => 'wxdede5853fa06c39a', //填写高级调用功能的app id
        'appsecret' => 'eb4d5dcc51b9d757337317aa5ddfdcf5', //填写高级调用功能的密钥
        'debug' => true,
        'logcallback' => 'write_log'
    );

    wechat.class.php的获取地址如下

    链接: https://pan.baidu.com/s/14SFri1PyeXbdWUa8DsR0QQ 提取码: h5o0

    效果如图:

  • 相关阅读:
    4.6--4.9
    4.表达式和运算符
    3.9--3.10
    3.8
    泛型(Generic)
    容器
    String,StringBuffer
    数组
    异常,自定义异常,异常重写
    多态,抽象类和抽象方法,接口
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11003133.html
Copyright © 2011-2022 走看看