如何使用 API 发送自动短信?
How to Send automated SMS using API?
我有这个条件来安排我的短信。 (错误)但我使用的短信是 POST 方法,我需要自动化。并发送短信到当前id的号码。我不知道如何获取当前id的号码并发送消息。这是我的代码:
$duedate = "";
$date_now = date("Y-m-d");
date_default_timezone_set('Asia/Manila');
$date_now = strtotime($date_now);
$duedate = strtotime($duedate);
if ($duedate <= $date_now) {
function itexmo($number, $message, $apicode) {
$url = 'https://www.itexmo.com/php_api/api.php';
$itexmo = array('1' => $number, '2' => $message, '3' => $apicode);
$param = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($itexmo),
),
);
$context = stream_context_create($param);
return file_get_contents($url, false, $context);
}
if ($_POST) {
$number = $number;
$name = $name;
$api = "API";
$text = $name." : ".$number;
if (!empty($_POST['name']) && ($_POST['number']) && ($_POST['msg'])) {
$result = itexmo($number, $text, $api);
if ($result == "") {
echo "iTexMo: No response from server!!!
Please check the METHOD used (CURL or CURL-LESS). If you are using CURL then try CURL-LESS and vice versa.
Please CONTACT US for help. ";
} elseif ($result == 0) {
echo "Message Sent!";
} else {
echo "Error Num ". $result . " was encountered!";
}
}
}
}
使用 PHP cURL 优于 stream_context_create 和 file_get_contents。
看看下面的代码,应该对你有帮助。
function itexmo($number,$message,$apicode)
{
$url = 'https://www.itexmo.com/php_api/api.php';
$postValues = http_build_query(['1' => $number, '2' => $message, '3' => $apicode])
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postValues);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);
return $response;
}
您可以了解更多PHP cURL。
我有这个条件来安排我的短信。 (错误)但我使用的短信是 POST 方法,我需要自动化。并发送短信到当前id的号码。我不知道如何获取当前id的号码并发送消息。这是我的代码:
$duedate = "";
$date_now = date("Y-m-d");
date_default_timezone_set('Asia/Manila');
$date_now = strtotime($date_now);
$duedate = strtotime($duedate);
if ($duedate <= $date_now) {
function itexmo($number, $message, $apicode) {
$url = 'https://www.itexmo.com/php_api/api.php';
$itexmo = array('1' => $number, '2' => $message, '3' => $apicode);
$param = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($itexmo),
),
);
$context = stream_context_create($param);
return file_get_contents($url, false, $context);
}
if ($_POST) {
$number = $number;
$name = $name;
$api = "API";
$text = $name." : ".$number;
if (!empty($_POST['name']) && ($_POST['number']) && ($_POST['msg'])) {
$result = itexmo($number, $text, $api);
if ($result == "") {
echo "iTexMo: No response from server!!!
Please check the METHOD used (CURL or CURL-LESS). If you are using CURL then try CURL-LESS and vice versa.
Please CONTACT US for help. ";
} elseif ($result == 0) {
echo "Message Sent!";
} else {
echo "Error Num ". $result . " was encountered!";
}
}
}
}
使用 PHP cURL 优于 stream_context_create 和 file_get_contents。 看看下面的代码,应该对你有帮助。
function itexmo($number,$message,$apicode)
{
$url = 'https://www.itexmo.com/php_api/api.php';
$postValues = http_build_query(['1' => $number, '2' => $message, '3' => $apicode])
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postValues);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);
return $response;
}
您可以了解更多PHP cURL。