登陆网站的常规方式有三种:
基于微信开放平台网站扫码登录的接口,详细链接
https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html
准备AppID和AppSecret,以及授权回调域名。以PHP为例 授权回调域名为 xxxx.com请求地址为:https://xxxx.com/login.php,回调地址为https://xxxx.com/oauth.php
//login.php
<?php
ini_set(‘display_errors‘, ‘On‘);
$state = md5(uniqid(microtime(true),true));
$appid = "微信开放平台AppID";
$redirect_uri = urlencode("https://xxxx.com/oauth.php");
$scope = "snsapi_login";
//拼接参数进行自动跳转
echo "<script>location.href=\"https://open.weixin.qq.com/connect/qrconnect?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=$scope&state=$state#wechat_redirect\";</script>";
//oauth.php
<?php
header("Content-type:text/html;charset=utf-8");
//获取code
$code = $_GET["code"];
//通过接口获取access_token
//构造请求参数
$appid = "微信开放平台AppID";
$appsecret = "微信开放平台AppSecret";
//拼接参数,自动跳转
echo "<script>location.href=\"https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code\";</script>";
请求后会跳转到扫码页面
手机扫码
授权登陆成功
原文:https://www.cnblogs.com/weblm/p/15077573.html