方法一:
使用亿速云短信扩展 https://github.com/yisu-cloud/sms
方法二:
<?php
function sendSms() {
$url = "https://api.yisu.com/sms/sendSms";
$accessId = "*****";
$accessSecret = "*****";
$params = [
"timestamp" => time(),
"nonce" => mt_rand(0, 99999999),
"accessId" => $accessId
];
$params["phone"] = "13800000000";
$params["templateCode"] = 100001;
$params["templateVars"] = json_encode(["code"=>111111, "min"=>10], true);
ksort($params);
$signStr = "";
foreach ( $params as $key => $value ) {
$signStr = $signStr . $key . "=" . $value . "&";
}
$signStr = substr($signStr, 0, -1);
$verifySignature = base64_encode(hash_hmac("sha1", $signStr, $accessSecret, true));
$params["signature"] = $verifySignature;
$data = http_build_query($params);
$options = array(
"http" => array(
"method" => "POST",
"header" => "Content-Type:application/x-www-form-urlencoded",
"content" => $data
));
$context = stream_context_create($options);
$result = file_get_contents($url, FILE_TEXT, $context);
return $result;
}
echo sendSms();
?>