init
This commit is contained in:
61
app/Models/User.php
Normal file
61
app/Models/User.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Jobs\SyncUserInfo;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Jason\Api\Api;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Tencent\TLSSigAPIv2;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable, SoftDeletes;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'privacy' => 'boolean',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
self::created(function ($model) {
|
||||
$model->info()->create([
|
||||
'nickname' => '用户'.substr($model->username, -4),
|
||||
]);
|
||||
$params = [
|
||||
'Identifier' => (string) $model->id,
|
||||
'Nick' => '用户'.substr($model->username, -4),
|
||||
'FaceUrl' => '',
|
||||
];
|
||||
app('im')->send('im_open_login_svc', 'account_import', $params);
|
||||
});
|
||||
}
|
||||
|
||||
public function getUserSigAttribute(): string
|
||||
{
|
||||
$api = new TLSSigAPIv2(config('im.sdk_app_id'), config('im.secret_key'));
|
||||
return $api->genUserSig($this->id, 15552000);
|
||||
}
|
||||
|
||||
public function getTokenAttribute(): string
|
||||
{
|
||||
return Api::login($this);
|
||||
}
|
||||
|
||||
public function info(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserInfo::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user