💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# :-: **阿里云最新短信接口** [api说明文档]([https://help.aliyun.com/document\_detail/101414.html?spm=a2c4g.11186623.2.52.5b1815ec1py2VJ](https://help.aliyun.com/document_detail/101414.html?spm=a2c4g.11186623.2.52.5b1815ec1py2VJ)) ![](https://img.kancloud.cn/01/35/01359b290814441f619479eef59f2ee7_415x670.png) 1. 使用composer安装扩展 ``` composer  require  alibabacloud/client ``` 2. 示例 ``` use think\Controller; use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; public function sendSms($phone,$code){ AlibabaCloud::accessKeyClient('AccessKey ID', 'AccessKey Secret') ->regionId('cn-hangzhou') ->asDefaultClient(); try { $result = AlibabaCloud::rpc() ->product('Dysmsapi') // ->scheme('https') // https | http ->version('2017-05-25') ->action('SendSms') ->method('POST') ->host('dysmsapi.aliyuncs.com') ->options([ 'query' => [ 'PhoneNumbers' => $phone, // 发送的电话号码 'SignName' => $signName??'', //签名 可放配置文件 'TemplateCode' => $templateCode??'', // 模板 SMS_xxxxxxx 'TemplateParam' => json_encode(['code'=>$code]), //需要这样的格式 php不能写花括号 就用 json_encode {'code':'123456'} ], ]) ->request(); $res=$result->toArray(); if($res['Code'] == 'OK'){ $data['status'] = 1; $data['info'] = $res['Message']; }else{ $data['status'] = 0; $data['info'] = $res['Message']; } return json($data); } catch (ClientException $e) { $data['status'] = 0; $data['info'] = $e->getErrorMessage(); return json($data); } catch (ServerException $e) { $data['status'] = 0; $data['info'] = $e->getErrorMessage(); return json($data); } } ``` ## **返回结果** ``` { "Message":"OK", "RequestId":"2184201F-BFB3-446B-B1F2-C746B7BF0657", "BizId":"197703245997295588^0", "Code":"OK" } ```