Files
2026-03-14 16:20:49 +08:00

58 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\service\iot;
class SpeakerService
{
// 基础配置
private $url = 'https://speaker.17laimai.cn/notify.php';
private $token = 'HK1654603135';
private $version = 1;
/**
* 语音播报
* @return mixed
*/
public function sendSpeakerNotify($speakerId)
{
$data = [
'version' => $this->version,
'token' => $this->token,
'id' => $speakerId,
'message' => '您好您预约的时间段还有10分钟即将结束',
];
return $this->curlPost($this->url, $data);
}
private function curlPost($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
// 增加SSL选项如果是HTTPS
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
// 添加错误处理
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
curl_close($ch);
throw new \Exception("CURL请求失败: " . $error_msg);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $result;
}
}