1.调用

$Sms = new Sms;
$result = $Sms->send('手机号',"【短信验证】(聚宝坊)您的验证码是:" .$code."。请不要把验证码泄露给其他人,验证码有效期为5分钟。");

2.代码

<?php
declare(strict_types=1);
namespace app;
class Sms
{
    /**
     * 发送短信
     * @param string $mobile 手机号
     * @param string $content 短信内容
     * @return bool
     */
    public function send(string $mobile, string $content)
    {
        // 发送短信
        // 发送一对多短信接口
        $apiURL = 'http://api.wddz.xyz:8001/sms/api/sendMessageOne';
        // 用户ID
        $userId = '407282';
        // 用户私钥
        $privateKey = 'FwLEYY5XsAHq';
        // 时间戳
        $time = time() * 1000;
        // 请求头
        $header = [
            'userName' => $userId,
            'messageList' =>array(
                array(
                    'phone' => $mobile,
                    'content'   => $content
                )
            ),
                
            
            'timestamp'     => $time,
            'sign'          => md5($userId . $time .md5($privateKey))
        ];
        
        // 请求短信接口
        $data = $this->sendPostRequest($apiURL, json_encode($header));

        return $data;
        // 请求封状
        
    }
    function sendPostRequest($url, $header)
    {
        $handle = curl_init();
        
        $ch = curl_init($url);
        
        
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $header);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         
        $response = curl_exec($ch); // 获取返回值
         
        curl_close($ch); // 关闭cURL资源
        return $response;
    }
}