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 协议》,转载必须注明作者和本文链接
城里的野山参
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
文章
69
粉丝
10
喜欢
30
收藏
39
排名:572
访问:1.4 万
私信
所有博文
社区赞助商