🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ sdk安装 composer require alibabacloud/client ~~~ ``` 参考地址 https://help.aliyun.com/document\_detail/101414.html?spm=a2c4g.11186623.6.624.f8a719d9HLuWHI https://api.aliyun.com/new?spm=a2c4g.11186623.2.13.505119d9eFdygO#/?product=Dysmsapi&version=2017-05-25&api=AddSmsSign&params={}&tab=DEMO&lang=PHP https://error-center.aliyun.com/status/product/Dysmsapi?spm=a2c1g.8271268.10000.136.6f9bdf25dcDr5H ``` ``` <?php namespace lib; use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; class Sms { public function send_sms($phone,$code){ $accessKeyId=''; $accessSecret=''; AlibabaCloud::accessKeyClient($accessKeyId,$accessSecret)->regionId('cn-hangzhou') ->asDefaultClient(); try { $query=[ 'RegionId' => "cn-hangzhou", 'PhoneNumbers' =>$phone, 'SignName' => "云快卡", 'TemplateCode' => "SMS_170515324", 'TemplateParam'=>json_encode(['code'=>$code]), ]; $result =AlibabaCloud::rpc()->product('Dysmsapi')->version('2017-05-25')->action('SendSms') ->method('POST')->host('dysmsapi.aliyuncs.com')->options(['query' =>$query])->request(); // ->scheme('https') // https | http return $result->toArray(); } catch (ClientException $e) { return $e->getErrorMessage(); } catch (ServerException $e) { return $e->getErrorMessage(); } } } ```