Files
zh-chat-server/app/Jobs/SyncUserInfo.php
2022-11-01 11:07:41 +08:00

76 lines
2.0 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\User;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;
class SyncUserInfo implements ShouldQueue
{
use Dispatchable, Queueable, SerializesModels;
protected User $user;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Execute the job.
*
* @return void
* @throws GuzzleException
*/
public function handle()
{
$params = [
'jsonrpc' => '2.0',
'id' => 1,
'method' => 'Chain33.Query',
'params' => [
[
'execer' => 'chat',
'funcName' => 'GetUser',
'payload' => [
'mainAddress' => $this->user->username,
'targetAddress' => $this->user->username,
]
]
],
];
$client = new Client([
'base_uri' => '152.136.224.167:8901'
]);
$result = $client->post('', [
'body' => json_encode($params),
]);
$json = json_decode($result->getBody()->getContents(), true);
$collect = collect($json['result']['fields']);
$this->user->info()->create([
'nickname' => $collect->where('name', 'nickname')->first()['value'] ?? null,
'avatar' => $collect->where('name', 'avatar')->first()['value'] ?? null,
]);
$params = [
'Identifier' => (string) $this->user->id,
'Nick' => $collect->where('name', 'nickname')->first()['value'] ?? '',
'FaceUrl' => $collect->where('name', 'avatar')->first()['value'] ?? '',
];
app('im')->send('im_open_login_svc', 'account_import', $params);
}
}