Skip to content

Commit

Permalink
fix: 修复当 server_token 为长数字时,后台会转化成科学计数法,后端验证失败
Browse files Browse the repository at this point in the history
  • Loading branch information
xboard committed Apr 17, 2024
1 parent f72df9d commit 09fb03a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,31 @@
class Setting extends Model
{
protected $table = 'v2_settings';
protected $guarded = [];
protected $guarded = [];
protected $casts = [
'key' => 'string',
'value' => 'string',
];

public function getValueAttribute($value)
{
if ($value === null) {
// 如果值为 null,你可能想要处理这种情况,例如返回一个默认值
return null; // 或者返回你期望的默认值
return null;
}
if (!is_string($value)) {

if (is_array($value)) {
return $value;
}

if (is_numeric($value) && !preg_match('/[^\d.]/', $value)) {
return $value;
}

$decodedValue = json_decode($value, true);

$decodedValue = json_decode($value, true);
if (json_last_error() === JSON_ERROR_NONE) {
return $decodedValue;
}

// 如果不是有效的 JSON 数据,则保持为字符串
return $value;
}
}

0 comments on commit 09fb03a

Please sign in to comment.