shop-php/crmeb/jobs/SendSmsJob.php

76 lines
2.8 KiB
PHP
Raw Normal View History

2023-05-10 13:38:51 +08:00
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\jobs;
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
2023-06-30 17:27:43 +08:00
use app\common\service\JgPush;
2023-05-10 13:38:51 +08:00
use crmeb\interfaces\JobInterface;
use crmeb\services\SmsService;
use crmeb\services\WechatTemplateMessageService;
2023-06-30 17:27:43 +08:00
use crmeb\utils\DingTalk;
2023-05-10 13:38:51 +08:00
use think\facade\Log;
class SendSmsJob implements JobInterface
{
public function fire($job, $data)
{
$status = app()->make(SystemNoticeConfigRepository::class)->getNoticeStatusByConstKey($data['tempId']);
2023-08-16 10:30:32 +08:00
if (!$status) {
$job->delete();
}
Log::info('app fire数据' . $status);
2023-06-30 17:27:43 +08:00
if ($status['notice_app'] == 1) {
try {
2023-07-01 16:14:09 +08:00
/** @var JgPush $client */
$client = app()->make(JgPush::class);
2023-06-30 17:27:43 +08:00
Log::info('app推送发送数据' . var_export($data, 1));
2023-07-01 16:14:09 +08:00
$client->send($data['tempId'], $data);
2023-06-30 17:27:43 +08:00
} catch (\Exception $e) {
Log::info('app推送消息发送失败' . var_export($data, 1) . $e->getMessage());
DingTalk::exception($e, 'app推送消息发送失败' . var_export($data, 1));
}
}
2023-05-10 13:38:51 +08:00
if ($status['notice_sms'] == 1) {
try {
SmsService::sendMessage($data);
} catch (\Exception $e) {
Log::info('发送短信失败' . var_export($data, 1) . $e->getMessage());
}
}
if ($status['notice_wechat'] == 1) {
try {
app()->make(WechatTemplateMessageService::class)->sendTemplate($data);
} catch (\Exception $e) {
Log::info('模板消息发送失败' . var_export($data, 1) . $e->getMessage());
}
}
if ($status['notice_routine'] == 1) {
try {
Log::info('订阅消息发送数据' . var_export($data, 1));
app()->make(WechatTemplateMessageService::class)->subscribeSendTemplate($data);
} catch (\Exception $e) {
Log::info('订阅消息发送失败' . var_export($data, 1) . $e->getMessage());
}
}
$job->delete();
}
public function failed($data)
{
// TODO: Implement failed() method.
}
}