You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.9 KiB
59 lines
1.9 KiB
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use RuntimeException;
|
|
|
|
class SmsConfig
|
|
{
|
|
/**
|
|
* Tencent Cloud SendSms uses Cloud API 3.0 authentication. SmsSdkAppId is
|
|
* a business parameter, not an API credential.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public static function realSendingRequiredEnv(): array
|
|
{
|
|
return [
|
|
'sms.tencentcloud.endpoint' => 'TENCENT_SMS_ENDPOINT',
|
|
'sms.tencentcloud.region' => 'TENCENT_SMS_REGION',
|
|
'sms.tencentcloud.secret_id' => 'TENCENTCLOUD_SECRET_ID',
|
|
'sms.tencentcloud.secret_key' => 'TENCENTCLOUD_SECRET_KEY',
|
|
'sms.tencentcloud.sdk_app_id' => 'TENCENT_SMS_SDK_APP_ID',
|
|
'sms.tencentcloud.sign_name' => 'TENCENT_SMS_SIGN_NAME',
|
|
'sms.tencentcloud.template_id' => 'TENCENT_SMS_TEMPLATE_ID',
|
|
];
|
|
}
|
|
|
|
public static function assertReadyForRealSending(): void
|
|
{
|
|
if (! (bool) config('sms.enabled')) {
|
|
return;
|
|
}
|
|
|
|
if ((string) config('sms.driver') !== 'tencentcloud') {
|
|
throw new RuntimeException('SMS_ENABLED=true requires SMS_DRIVER=tencentcloud.');
|
|
}
|
|
|
|
$missing = [];
|
|
foreach (self::realSendingRequiredEnv() as $configKey => $envName) {
|
|
$value = config($configKey);
|
|
if ($value === null || trim((string) $value) === '') {
|
|
$missing[] = $envName;
|
|
}
|
|
}
|
|
|
|
if ((int) config('sms.tencentcloud.template_param_count') !== 2) {
|
|
$missing[] = 'TENCENT_SMS_TEMPLATE_PARAM_COUNT must be 2';
|
|
}
|
|
|
|
if ($missing !== []) {
|
|
throw new RuntimeException(
|
|
'SMS_ENABLED=true but Tencent Cloud SMS configuration is incomplete. '
|
|
.'SendSms uses Cloud API 3.0 and requires CAM credentials. Missing or invalid: '
|
|
.implode(', ', $missing)
|
|
);
|
|
}
|
|
}
|
|
}
|