驱动
This commit is contained in:
parent
aeb3d5a743
commit
1404740fe5
|
@ -35,7 +35,7 @@ return [
|
||||||
|
|
||||||
'default' => [
|
'default' => [
|
||||||
'strategy' => OrderStrategy::class,
|
'strategy' => OrderStrategy::class,
|
||||||
'senders' => ['aliyun', 'tencent_cloud'],
|
'senders' => ['hoge'],
|
||||||
],
|
],
|
||||||
|
|
||||||
'senders' => [
|
'senders' => [
|
||||||
|
@ -199,5 +199,5 @@ return [
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'default_mobile_number_region' => null,
|
'default_mobile_number_region' => 'CN',
|
||||||
];
|
];
|
||||||
|
|
|
@ -16,15 +16,11 @@ use Zyimm\Sms\Contracts\DriverInterface;
|
||||||
|
|
||||||
abstract class AbstractDriver implements DriverInterface
|
abstract class AbstractDriver implements DriverInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Zyimm\Sms\Client
|
|
||||||
*/
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
/**
|
protected Client $client;
|
||||||
* @var \Hyperf\Config\Config
|
|
||||||
*/
|
|
||||||
protected $config;
|
protected Config $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The driver constructor.
|
* The driver constructor.
|
||||||
|
|
|
@ -10,6 +10,8 @@ class HogeDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
const SEND_URL = '/api/sms/send';
|
const SEND_URL = '/api/sms/send';
|
||||||
|
|
||||||
|
const USECASE_URL = '/api/sms/usecase';
|
||||||
|
|
||||||
public function send(SmsableInterface $smsable): array
|
public function send(SmsableInterface $smsable): array
|
||||||
{
|
{
|
||||||
$url = $this->buildUrl(self::SEND_URL);
|
$url = $this->buildUrl(self::SEND_URL);
|
||||||
|
@ -60,4 +62,19 @@ class HogeDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
return $this->config->get('sms_api_url').$path;
|
return $this->config->get('sms_api_url').$path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function serivce()
|
||||||
|
{
|
||||||
|
$url = $this->config->get('sms_api_url').self::USECASE_URL;
|
||||||
|
|
||||||
|
$response = $this->client->get($url, [
|
||||||
|
'custom_appid' => $this->config->get('sms_appid'),
|
||||||
|
'custom_appkey' => $this->config->get('sms_appkey')
|
||||||
|
]);
|
||||||
|
$result = $response->toArray();
|
||||||
|
if ($result['code'] != 200) {
|
||||||
|
throw new DriverErrorException($result['message'] ?? '未知错误', $result['code'], $response);
|
||||||
|
}
|
||||||
|
return $result['data'] ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,18 +11,20 @@ declare(strict_types=1);
|
||||||
namespace Zyimm\Sms\Drivers;
|
namespace Zyimm\Sms\Drivers;
|
||||||
|
|
||||||
use Hyperf\Logger\LoggerFactory;
|
use Hyperf\Logger\LoggerFactory;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Zyimm\Sms\Contracts\SmsableInterface;
|
use Zyimm\Sms\Contracts\SmsableInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
class LogDriver extends AbstractDriver
|
class LogDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
/**
|
protected LoggerInterface $logger;
|
||||||
* The Logger instance.
|
|
||||||
*
|
|
||||||
* @var \Psr\Log\LoggerInterface
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
public function __construct(ContainerInterface $container, array $config)
|
public function __construct(ContainerInterface $container, array $config)
|
||||||
{
|
{
|
||||||
parent::__construct($config);
|
parent::__construct($config);
|
||||||
|
|
|
@ -35,10 +35,8 @@ class PendingSms
|
||||||
*/
|
*/
|
||||||
protected SmsManagerInterface $manger;
|
protected SmsManagerInterface $manger;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var SenderInterface
|
protected ?SenderInterface $sender = null;
|
||||||
*/
|
|
||||||
protected SenderInterface $sender;
|
|
||||||
|
|
||||||
public function __construct(SmsManagerInterface $manger)
|
public function __construct(SmsManagerInterface $manger)
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,6 +71,7 @@ class SmsManager implements SmsManagerInterface
|
||||||
$exception = null;
|
$exception = null;
|
||||||
|
|
||||||
foreach ($senders as $sender) {
|
foreach ($senders as $sender) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $smsable->send($this->get($sender));
|
return $smsable->send($this->get($sender));
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ abstract class Smsable implements SmsableInterface, CompressInterface, UnCompres
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
public array $senders;
|
public array $senders = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user