php 阿里云短信

官网沙盒

https://api.aliyun.com/?spm=a2c4g.11186623.2.17.fc9f50a4q57FUw#/?product=Dysmsapi&api=SendSms¶ms=

官方文档,注意验证码要用json格式   json_encode( array('code'=>123456) );

https://help.aliyun.com/document_detail/101414.html?spm=a2c4g.11186623.2.11.4b243e2cdOdbvR

 

在项目中下载ali_sdk  

composer require alibabacloud/sdk
 $params['code'] ); 

        AlibabaCloud::accessKeyClient($this->appid, $this->appkey)
        ->regionId('cn-hangzhou') // replace regionId as you need
        ->asDefaultClient();

        try {
                $result = AlibabaCloud::rpc()
                ->product('Dysmsapi')
              // ->scheme('https') // https | http
                ->version('2017-05-25')
                ->action('SendSms')
                ->method('POST')
                ->options([
                    'query' => [
                        'PhoneNumbers' => $params['mobile'],
                        'SignName' => "数联",
                        'TemplateCode' => "SMS_169185018",
                        'TemplateParam' => json_encode($arr),
                    ],
                ])
                ->request();

            // echo "
";var_dump(     $result->toArray()    );die;
            return true;
            return $result->toArray();
            print_r($result->toArray());
        } catch (ClientException $e) {
            return $e->getErrorMessage() . PHP_EOL;
            echo $e->getErrorMessage() . PHP_EOL;
        } catch (ServerException $e) {
            return $e->getErrorMessage() . PHP_EOL;
            echo $e->getErrorMessage() . PHP_EOL;
        }
    }
}

 

你可能感兴趣的:(php 阿里云短信)