演示地址:演示 - 使用 i 收藏 登录
i 收藏 开放接口:为第三方网站提供用户快捷登录
- 无门槛,所有网站可接入
- 不用授权,部署即用
- 多平台支持,PC端、手机移动、微信内置浏览器
域名由 isc.net.cn 更换为 sc.uv.cc
html 代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<title></title>
<!-- jquery -->
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
function get_url_param(k) {
var _list = location.search.substr(1).split('&')
for (var _list2 of _list) {
for (var item of _list2.split('?')) {
var kv = item.split('=')
if(kv[0] == k){
return decodeURIComponent(kv[1])
}
}
}
return ''
}
</script>
<script type="text/javascript">
function win_open(url, w, h) {
// 打开窗口网页
var l = (screen.width - w) / 2,
t = (screen.height - h) / 2
window.open(url, "_blank", "width=" + w + ",height=" + h + ",toolbars=0,resizable=1,left=" + l + ",top=" + t)
}
</script>
</head>
<body>
<div id="login-isc" style="cursor: pointer;">使用 i 收藏登录</div>
</body>
<script type="text/javascript">
// 自动检测
(() => {
if (get_url_param('oauth_token') != '') {
window.opener.login_ok(get_url_param('oauth_token'))
window.close()
}
})()
// 登录成功后子页面的回调
function login_ok(oauth_token) {
$.post("oauth.php", {
oauth_token: oauth_token,
}, function(data){
document.write(data)
})
}
</script>
<script type="text/javascript">
// 前往登录
$("#login-isc").click(function(){
win_open("http://isc.net.cn/login/?oauth_host="+ encodeURIComponent(location.host) +"&back_url=" + encodeURIComponent(location.href), 480, 490)
})
</script>
</html>
php代码:
<?php
$str = file_get_contents('http://isc.net.cn/login/token-oauth/?oauth_token=' . $_POST['oauth_token']);
$arr = json_decode($str, true);
echo "<pre>";
print_r($arr);
if ($arr['msg'] == 'ok') {
@session_start();
$_SESSION['isc-open_id'] = $arr['open_id'];
$_SESSION['isc-user_name'] = $arr['user_name'];
}
提示:
对于同一用户、同一站点(第三方),返回的 open_id 是不变的,user_name 可能为空或改动。请使用 open_id 作为用户的唯一凭证,而不是 user_name。
更多咨询:kf@uv.cc