一般在开发中会用到短信业务,目前个人比较好的是阿里云的短信业务
下面来看下它的使用方法、
1.composer require alibabacloud/dysmsapi-20170525
2.引入
use \AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi as Dysmsapi; use \Darabonba\OpenApi\Models\Config as Config; use \AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest as SendSmsRequest;
在PHP方法中添加
; $phone=13800138000; signName='短信签名'; $templateCode=='短信模板编码'; $config = new Config([ // 您的AccessKey ID "accessKeyId" => ccessKey ID,// // 您的AccessKey Secret "accessKeySecret" => accessKeySecret ]); $config->endpoint = "dysmsapi.aliyuncs.com"; $client = new Dysmsapi($config); $sendSmsRequest = new SendSmsRequest([ "phoneNumbers" => trim($phone), "signName" => $signName, "templateCode" => $templateCode, "templateParam" => "{\"code\":\"".$code."\"}" ]); $data = $client->sendSms($sendSmsRequest); if($data->body->code=='OK'){ return json_encode(['status'=>200,'msg'=>'发送短信成功,请在5分钟内使用']); }else{ return json_encode(['status'=>400,'msg'=>'发送短信失败']); }
发表评论