60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
use App\Models\ChatMessage;
|
||
|
|
use App\Events\NoticeServer;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\AssistantUser;
|
||
|
|
use App\Services\IMService;
|
||
|
|
class AssistantMessage implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
public $tries = 1;
|
||
|
|
public $timeout = 120;
|
||
|
|
public $data;
|
||
|
|
public $user_ids;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($data, $user_ids)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
$this->user_ids = $user_ids;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
// dd($data);
|
||
|
|
AssistantUser::insert($this->data);
|
||
|
|
$content = ($this->data)[0]['content'];
|
||
|
|
$body = ['msg'=>$content];
|
||
|
|
foreach ($this->user_ids as $user_id) {
|
||
|
|
$other_user = User::find($user_id);
|
||
|
|
|
||
|
|
if (empty($other_user)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
//发送网易消息
|
||
|
|
//发送IM消息
|
||
|
|
$im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET'));
|
||
|
|
$result = $im_service->sendMsg(1, 0, $user_id,$type=0,$body,$option=array("push"=>false,"roam"=>true,"history"=>true,"sendersync"=>true, "route"=>false),$pushcontent='');
|
||
|
|
broadcast(new NoticeServer($other_user));
|
||
|
|
sleep(1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|