Steam第三方登录
Laravel PHP7.3
前端登录界面
<li class="sc-st">
<a class="animate" href="?steam_login">
<img src="/images/info-icon-steam.png" alt="Steam" title="Login With Steam">
</a>
</li>
@if(isset($steamprofile))
<script type="text/javascript">
window.onload=function(){
var steamprofile = '{!!$steamprofile!!}';
var steamid = '{{$steamid}}';
if(steamid){
$.post('/ajax/SocilaAuthLogin',{
data:{userdata:steamprofile,type:'steamLogin'},
},function(data){
var data=JSON.parse(data);
art.dialog({
title:'{{$LANG['PUBLIC']['TIPS']}}',
icon: data['icon'],
content:data['tips'],
okVal:'ok'
});
window.location.reload();
});
}
}
</script>
@endif
控制器代码
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Session;
use App\Http\Models\Website\TwitterThirdLogin;
use Route;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use App\Http\Models\Website\Basesite;
use Illuminate\Support\Facades\Input;
use Storage;
class HomeController extends Controller
{
public function signin(request $request){
//已登录用户跳转登录和注册页时跳转首页
if(isset($this->data['member']['memberId'])){
return redirect("/");
}
if (isset($_GET['steam_login'])){
//steam第三方
@require_once dirname(__FILE__) . '/../../../public/plugins/steamauth/steamauth.php';
}
if(isset($_SESSION['steamid']))
{
@require_once dirname(__FILE__) . '/../../../public/plugins/steamauth/userInfo.php';
$this->data['steamid']=$steamprofile['steamid'];
$this->data['steamprofile']=json_encode($steamprofile,true);
}
return view('u7buy.signin')
->with($this->data);
}
}
只需要引用steam文件https://github.com/DLXXKJ/steamThridLogin.git
下载到对应目录中例如再steamConfig.php中 填写steam开发这行好的key和回调地址
(steam开发者账号申请https://steamcommunity.com/login/home/)
<?php
//Version 4.0
$steamauth['apikey'] = "XXXXXXXX"; // Your Steam WebAPI-Key found at https://steamcommunity.com/dev/apikey
$steamauth['domainname'] = "XXXXXXXX"; // The main URL of your website displayed in the login page
$steamauth['logoutpage'] = ""; // Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = ""; // Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}
?>