| | |
| | | function sendData(url, data, type, callbackFun) { |
| | | // callbackFun("{}"); |
| | | // return; |
| | | |
| | | var deferred = $.Deferred(); |
| | | if (type != "get") { |
| | | data = JSON.stringify(data); |
| | |
| | | if (url!=IP+"/WeatherForecast/Login") { |
| | | if (!$.cookie('token')) { |
| | | callbackFun("登录人信息已失效"); |
| | | try { |
| | | parent.window.location.href = '/views/Login.html'; |
| | | } |
| | | catch (error) { |
| | | window.location.href = '/views/Login.html'; |
| | | } |
| | | return; |
| | | } |
| | | if (isTokenExpired($.cookie('token'))) { |
| | | try { |
| | | parent.window.location.href = '/views/Login.html'; |
| | | } |
| | | catch (error) { |
| | | window.location.href = '/views/Login.html'; |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | $.ajax({ |
| | |
| | | if (url!=IP+"/WeatherForecast/Login") { |
| | | if (!$.cookie('token')) { |
| | | callbackFun("登录人信息已失效"); |
| | | try { |
| | | parent.window.location.href = '/view/Login.html'; |
| | | } |
| | | catch (error) { |
| | | window.location.href = '/view/Login.html'; |
| | | } |
| | | return; |
| | | } |
| | | if (isTokenExpired($.cookie('token'))) { |
| | | try { |
| | | parent.window.location.href = '/view/Login.html'; |
| | | } |
| | | catch (error) { |
| | | window.location.href = '/view/Login.html'; |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | $.ajax({ |
| | |
| | | |
| | | return newobj |
| | | } |
| | | |
| | | function isTokenExpired(token) { |
| | | const tokenParts = token.split('.'); |
| | | if (tokenParts.length !== 3) { |
| | | return true; // JWT 格式不正确 |
| | | } |
| | | const payloadBase64 = tokenParts[1]; |
| | | const payload = JSON.parse(atob(payloadBase64)); |
| | | |
| | | if (!payload || !payload.exp) { |
| | | return true; // 没有有效载荷或者没有过期时间 |
| | | } |
| | | |
| | | const now = Date.now() / 1000; // 当前时间戳(秒) |
| | | const expiration = payload.exp; |
| | | |
| | | return now >= expiration; |
| | | } |