驱动
This commit is contained in:
parent
aeb3d5a743
commit
1404740fe5
|
@ -35,7 +35,7 @@ return [
|
|||
|
||||
'default' => [
|
||||
'strategy' => OrderStrategy::class,
|
||||
'senders' => ['aliyun', 'tencent_cloud'],
|
||||
'senders' => ['hoge'],
|
||||
],
|
||||
|
||||
'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
|
||||
{
|
||||
/**
|
||||
* @var \Zyimm\Sms\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var \Hyperf\Config\Config
|
||||
*/
|
||||
protected $config;
|
||||
protected Client $client;
|
||||
|
||||
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The driver constructor.
|
||||
|
|
|
@ -10,6 +10,8 @@ class HogeDriver extends AbstractDriver
|
|||
{
|
||||
const SEND_URL = '/api/sms/send';
|
||||
|
||||
const USECASE_URL = '/api/sms/usecase';
|
||||
|
||||
public function send(SmsableInterface $smsable): array
|
||||
{
|
||||
$url = $this->buildUrl(self::SEND_URL);
|
||||
|
@ -60,4 +62,19 @@ class HogeDriver extends AbstractDriver
|
|||
{
|
||||
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;
|
||||
|
||||
use Hyperf\Logger\LoggerFactory;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Zyimm\Sms\Contracts\SmsableInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class LogDriver extends AbstractDriver
|
||||
{
|
||||
/**
|
||||
* The Logger instance.
|
||||
*
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function __construct(ContainerInterface $container, array $config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
|
|
|
@ -35,10 +35,8 @@ class PendingSms
|
|||
*/
|
||||
protected SmsManagerInterface $manger;
|
||||
|
||||
/**
|
||||
* @var SenderInterface
|
||||
*/
|
||||
protected SenderInterface $sender;
|
||||
|
||||
protected ?SenderInterface $sender = null;
|
||||
|
||||
public function __construct(SmsManagerInterface $manger)
|
||||
{
|
||||
|
|
|
@ -71,6 +71,7 @@ class SmsManager implements SmsManagerInterface
|
|||
$exception = null;
|
||||
|
||||
foreach ($senders as $sender) {
|
||||
|
||||
try {
|
||||
return $smsable->send($this->get($sender));
|
||||
} catch (Throwable $throwable) {
|
||||
|
|
|
@ -26,7 +26,7 @@ abstract class Smsable implements SmsableInterface, CompressInterface, UnCompres
|
|||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public array $senders;
|
||||
public array $senders = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
|
|
Loading…
Reference in New Issue
Block a user