PHP,阿里云短信,MissingPhoneNumbers
背景
需要在项目中使用阿里云短信SDK下发手机短信。
依赖包:
alibabacloud/dysmsapi
版本:1.7.x
问题
根据阿里云官方文档的示例(原版SDK)去使用,并不能正常调用,报错:MissingPhoneNumbers: PhoneNumbers is mandatory for this action
,实际上是传参了的。
另外一点,regionId
很难找到,不知道如何设置,可以用cn-hangzhou
或者default
。
解决方案
下面是能够正常下发的写法。
AlibabaCloud::accessKeyClient("id","secret")
->regionId('cn-hangzhou')->asDefaultClient();
try{
$request=Dysmsapi::v20170525()->sendSms()
->withPhoneNumbers($smsJob->getPhone())
->withSignName($smsJob->getSignName())
->withTemplateCode($smsJob->getTemplateCode())
->withTemplateParam($smsJob->getTemplateParam());
$result=$request->request();
$this->log($result->toArray());
}catch(ClientException $e){
$this->log("sms fail,client exception,error msg:{$e->getMessage()}");
}catch (ServerException $e){
$this->log("sms fail,server exception,error msg:{$e->getMessage()} errorCode:{$e->getErrorCode()} requestId:{$e->getRequestId()}");
}
本作品采用《CC 协议》,转载必须注明作者和本文链接