forked from modstart/ModStartBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmsSendJob.php
More file actions
42 lines (35 loc) · 1.39 KB
/
Copy pathSmsSendJob.php
File metadata and controls
42 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Module\Vendor\Job;
use ModStart\Core\Exception\BizException;
use ModStart\Core\Job\BaseJob;
use ModStart\Core\Util\SerializeUtil;
use Module\Vendor\Log\Logger;
use Module\Vendor\Provider\SmsSender\SmsSenderProvider;
class SmsSendJob extends BaseJob
{
public $phone;
public $template;
public $templateData;
public static function create($phone, $template, $templateData)
{
$job = new static();
$job->phone = $phone;
$job->template = $template;
$job->templateData = $templateData;
app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($job);
}
public function handle()
{
$logData = $this->phone . ' - ' . $this->template . ' - ' . SerializeUtil::jsonEncode($this->templateData, JSON_UNESCAPED_UNICODE);
Logger::info('Sms', 'Start', $logData);
$provider = app()->config->get('SmsSenderProvider');
try {
BizException::throwsIfEmpty('短信发送未设置', $provider);
$ret = SmsSenderProvider::get($provider)->send($this->phone, $this->template, $this->templateData);
BizException::throwsIfResponseError($ret);
Logger::info('Sms', 'End', $this->phone . ' - ' . SerializeUtil::jsonEncode($ret, JSON_UNESCAPED_UNICODE));
} catch (BizException $e) {
Logger::error('Sms', 'Error', $this->phone . ' - ' . $e->getMessage());
}
}
}