微信开发

微信开发

微信开放平台授权登录

微信开发liangjun 发表了文章 • 0 个评论 • 248 次浏览 • 2018-08-07 20:15 • 来自相关话题

登录页:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
</head>
<body>
<span id="login_container"></span>
<script>
var obj = new WxLogin({
id: "login_container",
appid: "**********",
scope: "snsapi_login",
redirect_uri: encodeURIComponent("http://" + window.location.host + "/login.php"),
state: Math.ceil(Math.random()*1000),
style: "black",
href: ""});
</script>
</body>
</html>
 
login.php
header("Content-type: text/html; charset=utf-8");
require_once('wxopen.class.php');
$weixin = new class_weixin();
if (!isset($_GET["code"])){
$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$jumpurl = $weixin->qrconnect($redirect_url, "snsapi_login", "123");
Header("Location: $jumpurl");
}else{
$oauth2_info = $weixin->oauth2_access_token($_GET["code"]);
$userinfo = $weixin->oauth2_get_user_info($oauth2_info['access_token'], $oauth2_info['openid']);
var_dump($userinfo); 输出 userinfo信息

} 查看全部
登录页:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
</head>
<body>
<span id="login_container"></span>
<script>
var obj = new WxLogin({
id: "login_container",
appid: "**********",
scope: "snsapi_login",
redirect_uri: encodeURIComponent("http://" + window.location.host + "/login.php"),
state: Math.ceil(Math.random()*1000),
style: "black",
href: ""});
</script>
</body>
</html>

 
login.php
header("Content-type: text/html; charset=utf-8");
require_once('wxopen.class.php');
$weixin = new class_weixin();
if (!isset($_GET["code"])){
$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$jumpurl = $weixin->qrconnect($redirect_url, "snsapi_login", "123");
Header("Location: $jumpurl");
}else{
$oauth2_info = $weixin->oauth2_access_token($_GET["code"]);
$userinfo = $weixin->oauth2_get_user_info($oauth2_info['access_token'], $oauth2_info['openid']);
var_dump($userinfo); 输出 userinfo信息

}

微信开放平台授权登录

微信开发liangjun 发表了文章 • 0 个评论 • 248 次浏览 • 2018-08-07 20:15 • 来自相关话题

登录页:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
</head>
<body>
<span id="login_container"></span>
<script>
var obj = new WxLogin({
id: "login_container",
appid: "**********",
scope: "snsapi_login",
redirect_uri: encodeURIComponent("http://" + window.location.host + "/login.php"),
state: Math.ceil(Math.random()*1000),
style: "black",
href: ""});
</script>
</body>
</html>
 
login.php
header("Content-type: text/html; charset=utf-8");
require_once('wxopen.class.php');
$weixin = new class_weixin();
if (!isset($_GET["code"])){
$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$jumpurl = $weixin->qrconnect($redirect_url, "snsapi_login", "123");
Header("Location: $jumpurl");
}else{
$oauth2_info = $weixin->oauth2_access_token($_GET["code"]);
$userinfo = $weixin->oauth2_get_user_info($oauth2_info['access_token'], $oauth2_info['openid']);
var_dump($userinfo); 输出 userinfo信息

} 查看全部
登录页:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
</head>
<body>
<span id="login_container"></span>
<script>
var obj = new WxLogin({
id: "login_container",
appid: "**********",
scope: "snsapi_login",
redirect_uri: encodeURIComponent("http://" + window.location.host + "/login.php"),
state: Math.ceil(Math.random()*1000),
style: "black",
href: ""});
</script>
</body>
</html>

 
login.php
header("Content-type: text/html; charset=utf-8");
require_once('wxopen.class.php');
$weixin = new class_weixin();
if (!isset($_GET["code"])){
$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$jumpurl = $weixin->qrconnect($redirect_url, "snsapi_login", "123");
Header("Location: $jumpurl");
}else{
$oauth2_info = $weixin->oauth2_access_token($_GET["code"]);
$userinfo = $weixin->oauth2_get_user_info($oauth2_info['access_token'], $oauth2_info['openid']);
var_dump($userinfo); 输出 userinfo信息

}