确短信发送

This commit is contained in:
2025-09-18 17:38:47 +08:00
parent 060fb1ae5c
commit c9589602eb
4 changed files with 276 additions and 52 deletions

View File

@@ -51,3 +51,48 @@ function uniqueMultidimensionalArray($array, $k = 'user_id') {
// 重新索引数组从0开始的连续数字键
return array_values($unique);
}
if(!function_exists('http_post')) {
function http_post($url, $data, $headers = [], $timeout = 30, $contentType = 'application/json')
{
// 初始化cURL
$ch = curl_init();
// 处理请求数据
if ($contentType === 'application/json') {
$data = json_encode($data);
} elseif (is_array($data)) {
$data = http_build_query($data);
}
// 设置请求头
$defaultHeaders = [
"Content-Type: $contentType",
"Content-Length: " . strlen($data)
];
$headers = array_merge($defaultHeaders, $headers);
// 设置cURL选项
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// 执行请求
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// 关闭cURL
curl_close($ch);
// 处理错误
if ($response === false) {
return $error;
}
return $response;
}
}