diff --git a/publish/sms.php b/publish/sms.php index b7c1272..528135c 100644 --- a/publish/sms.php +++ b/publish/sms.php @@ -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', ]; diff --git a/src/Drivers/AbstractDriver.php b/src/Drivers/AbstractDriver.php index 9e302df..ab706b9 100644 --- a/src/Drivers/AbstractDriver.php +++ b/src/Drivers/AbstractDriver.php @@ -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. diff --git a/src/Drivers/HogeDriver.php b/src/Drivers/HogeDriver.php index 2fcbf37..c4c1157 100644 --- a/src/Drivers/HogeDriver.php +++ b/src/Drivers/HogeDriver.php @@ -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'] ?? []; + } } \ No newline at end of file diff --git a/src/Drivers/LogDriver.php b/src/Drivers/LogDriver.php index 5e98ead..ce9a7fd 100644 --- a/src/Drivers/LogDriver.php +++ b/src/Drivers/LogDriver.php @@ -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); diff --git a/src/PendingSms.php b/src/PendingSms.php index a2d9b19..947be4d 100644 --- a/src/PendingSms.php +++ b/src/PendingSms.php @@ -35,10 +35,8 @@ class PendingSms */ protected SmsManagerInterface $manger; - /** - * @var SenderInterface - */ - protected SenderInterface $sender; + + protected ?SenderInterface $sender = null; public function __construct(SmsManagerInterface $manger) { diff --git a/src/SmsManager.php b/src/SmsManager.php index 7a209c1..ac251b7 100644 --- a/src/SmsManager.php +++ b/src/SmsManager.php @@ -71,6 +71,7 @@ class SmsManager implements SmsManagerInterface $exception = null; foreach ($senders as $sender) { + try { return $smsable->send($this->get($sender)); } catch (Throwable $throwable) { diff --git a/src/Smsable.php b/src/Smsable.php index b81773f..54ec475 100644 --- a/src/Smsable.php +++ b/src/Smsable.php @@ -26,7 +26,7 @@ abstract class Smsable implements SmsableInterface, CompressInterface, UnCompres /** * @var string[] */ - public array $senders; + public array $senders = []; /** * @var string