来源:https://www.fuuuy.cn/archives/897.html
但是兰空图床免费版的token需要使用第三方请求来获取,非常的不方便
所以我就自己在后台程序中加了一个post请求,使用异步请求来获取token
添加代码
直接在 /resources/views/common/api.blade.php 文件里合适的位置添加以下代码
在文件第11行添加就可以
<div>
<p class=”text-lg text-gray-700 font-semibold”>Tonken获取</p>
<script src=”//lib.baomitu.com/jquery/1.12.4/jquery.min.js”></script>
<form id=”token” action=”{{ request()->getSchemeAndHttpHost() }}/api/v1/tokens” method=”POST”>
<div class=”my-2 text-sm”>
<div class=”form-group qqlogin” style=”display: none;”>
<div class=”input-group-addon”>邮箱</div>
<input type=”email” id=”email” name=”email” value=”{{ Auth::user()->email }}”>
</div>
<div style=”display: inline-flex;position: relative;”>
<div class=”px-4 py-3 text-right sm:px-6″ style=”color: #555;background-color: #eee;border: 1px solid #ccc;”>密码</div>
<input type=”password” id=”password” name=”password” placeholder=”输入你的密码”>
<a href=”javascript:;” class=”button px-4 py-3 sm:px-6″ style=”color: #fff;background-color: #337ab7;border-color: #2e6da4;margin-left:10px;”>
<div>点击获取</div>
</a>
</div>
<div class=”list-group”>
<x-code>
<span style=”color:tomato;user-select: none;”>token:</span><span id=”tokenCode”></span>
</x-code>
</div>
</form>
<script>
$(document).ready(function() {
$(“#token .button”).click(function() {
var url = $(“#token”).attr(“action”);
var email = $(“#email”).val();
var password = $(“#password”).val();
$.ajax({
type: ‘post’,
url: url,
data: {
email: email,
password: password
},
success: function(data) {
if (data.status == true) {
$(“#tokenCode”).html(‘Bearer ‘ + data.data.token)
} else {
if (data.message == “password 不能为空。”) {
$(“#tokenCode”).html(“密码不能为空!”)
} else if (data.message == “The email address or password is incorrect.”) {
$(“#tokenCode”).html(“请确认密码是否正确!”)
}
}
},
error: function() {
$(“#tokenCode”).html(“请求过于频繁,请稍后再试!”)
}
});
});
});
</script>
</div>
刷新后台
建议使用强制刷新Ctrl+F5
其实实现原理很简单,就是使用jQuery的Ajax来获取的
Reviews No comments yet
The distribution appears here once people rate
No one has reviewed this site yet
One sentence from you becomes the next visitor's reference. Not sure where to start? Pick one: