love_php/app/Jobs/ParticipantShareNotice.php
2026-04-02 09:20:51 +08:00

88 lines
2.9 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 EasyWeChat\Kernel\Messages\Text;
use App\Repositories\Eloquent\SmsRepository as Sms;
use Illuminate\Container\Container;
class ParticipantShareNotice implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 1;
protected $participant;
protected $participant_helper;
protected $sms;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($array)
{
$this->participant = $array['participant'];
$this->participant_helper = $array['participant_helper'];
$container = new Container();
$this->sms = new Sms($container);
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$participant = $this->participant;
$participant_helper = $this->participant_helper;
$result = $this->textMessage($participant);
if (!empty($result['errcode']) && $result['errmsg'] != 'ok') {//发送失败
//Todo模板消息
$result = $this->templateMessage($participant, $participant_helper);
if (!empty($result['errcode']) && $result['errmsg'] != 'ok') {//发送失败
#TODO记录
}
}
} catch (Exception $e) {
//TODO通知管理员
$message = $e->getMessage();
$this->sms->sentMessage($mobile, $message);
}
}
public function templateMessage($participant, $participant_helper)
{
$param = [
'url'=>env('APP_URL').'/red/packet/activity/wechat/auth',
'share_user_name'=>$participant['nickname'],
'user_name'=>$participant_helper['nickname'],
'chance'=>$participant['chance'],
'openid'=>$participant['official_openid']
];
$result = \WechatService::shareSuccessNotice($param);
return $result;
}
//客服信息
public function textMessage($participant)
{
$app = app('wechat.official_account');
// $url = env('APP_URL')."/rp/#/redPacketFruit?official_openid=".$participant['official_openid'];
$url = env('APP_URL')."/red/packet/activity/wechat/auth";
$nickname = $participant['nickname']?:'朋友';
$message = $nickname.',恭喜您!获得'.$participant['chance'].'次收集果子机会,<a href="'.$url.'">马上领取GO!</a>
';
$text = new Text($message);
$openId = $participant['official_openid'];
$result = $app->customer_service->message($text)->to($openId)->send();
return $result;
}
}