work/extend/sms/Sms.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2019-01-17 11:05:47 +08:00
<?php
namespace sms;
use Overtrue\EasySms\EasySms;
use Overtrue\EasySms\Exceptions\InvalidArgumentException;
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
use think\facade\Log;
/**
* 短信服务
* Class Sms
* @package sms
*/
class Sms extends EasySms
{
public function __construct()
{
parent::__construct(config('sms.'));
}
/**
* 发送单条短信
* @param $to
* @param $message
* @param array $gateways
* @return array|bool
*/
public function vSend($to, $message, array $gateways = [])
{
if (config('sms.debug')) {
return true;
}
2019-01-17 11:05:47 +08:00
try {
$result = $this->send($to, $message, $gateways);
} catch (InvalidArgumentException $e) {
// Log::write($e->getResults(), "sms-exception");
return error(1);
2019-01-17 11:05:47 +08:00
} catch (NoGatewayAvailableException $e) {
// Log::write($e->getResults(), "sms-exception");
return error(1);
2019-01-17 11:05:47 +08:00
}
logRecord($result, 'info', 'sms');
2019-01-17 11:05:47 +08:00
return $result;
}
}