love_php/app/Jobs/SendIMPushMsg.php

106 lines
3.0 KiB
PHP
Raw Normal View History

2026-04-02 09:20:51 +08:00
<?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\Services\IMService;
class SendIMPushMsg implements ShouldQueue
{
/**
* 异步发送网易推送消息
*/
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 3;
protected $type_id;
protected $type;
protected $content;
protected $from;
protected $to;
protected $image;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($type_id, $type, $content, $from, $to, $image)
{
$this->type_id = $type_id;
$this->type = $type;
$this->content = $content;
$this->from = $from;
$this->to = $to;
$this->image = $image;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->sendAttachMsg($this->type_id, $this->type, $this->content, $this->from, $this->to, $this->image);
}
/**
* 发送推送消息
* @param [type] $type_id 类型id
* @param [type] $type 类型
* @param [type] $content 推送文字
* @param [type] $from 来自用户
* @param [type] $to 接收用户
* @param [type] $image 来自用户头像
* @return [type] 是否成功
*/
public function sendAttachMsg($type_id, $type, $content, $from, $to, $image)
{
$body = "点击查看>>";
//发送评论自定义系统消息
$im_service = new IMService();
$attach = ["myattach"=>$content, $type.'_id'=>$type_id];
$payload = [
"apsField"=>[
"alert"=>[
"title"=>$content,
"body"=> $body,
],
"mutable-content"=>1
],
"hwField"=>[
"click_action"=>[
"type"=>1,
"intent"=>"intent://com.huawei.codelabpush/deeplink?id=".$type_id."&customType=".$type."#Intent;scheme=pushscheme;launchFlags=0x4000000;end",
],
"title"=>$content,
"body"=>$body,
],
"oppoField"=>[
"click_action_type"=>1,
"click_action_activity"=>"com.oppo.codelabpush.intent.action.test",
"action_parameters"=>[
"id"=>$type_id,
"customType"=>"moment",
],
],
"apnsText"=>$body,
"pushTitle"=>$content,
"customType"=>$type,
"content"=>$body,
"media_image"=>$image,
"media_type"=>'image',
"id"=>$type_id,
"type"=>$type,
'passThrough'=>1,
];
$result = $im_service->sendAttachMsg($from,0,$to,json_encode($attach),$content,$payload);
return true;
}
}