fix(utils.sms): 对空数组进行了验证和拦截

This commit is contained in:
lichen
2022-08-09 15:15:25 +08:00
parent d4c5a5b948
commit 60305d1aa2

View File

@@ -46,7 +46,7 @@ class SmsService
*
* @param string $phone 接收短信的手机号码
* @param string|null $templateCode 短信模板CODE
* @param array $templateParam 短信模板变量对应的实际值
* @param array|null $templateParam 短信模板变量对应的实际值(不支持空数组)
* @param string|null $signName 短信签名名称
*
* @return bool
@@ -55,9 +55,12 @@ class SmsService
public function sendSmsCountryside(
string $phone,
?string $templateCode = null,
array $templateParam = [],
?array $templateParam = null,
?string $signName = null,
): bool {
if (is_array($templateParam) && count($templateParam) <= 0) {
throw new \UnexpectedValueException('不支持空数组,请用 null 代替或不传', CommonErrorCode::FORMATTER_ERROR);
}
$phone_number = strtr($phone, ['#' => '']);
$sendSmsRequest = new SendSmsRequest(