如何使用 PHP 调用外部 Web 服务


How to call external web service using PHP

>我正在使用一项服务通过重定向到服务页面来使用 php 发送短信(例如 http://example.com?receiver=38383&msg=test(

如果我想向一个电话号码发送消息,我可以重定向到此页面,但我想使用 for 循环发送大量消息。我无法重定向到该页面,因为它会停止 PHP 脚本。我尝试了 cURL,但我没有任何结果。你可以帮我吗?

这是 cURL 的代码:

$path = "http://example.com?receiver=38383&msg=test";
$opts = array(CURLOPT_URL => $path,
              CURLOPT_RETURNTRANSFER => true,
              CURLOPT_HEADER => true,
           CURLOPT_FOLLOWLOCATION => true);
$ch = curl_init();
curl_setopt_array($ch, $opts);
$return = curl_exec($ch);
curl_close($ch);
echo $return;
function sendSMS($receiver, $message) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://example.com?receiver" . $receiver . "&msg=" . $message);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}
echo sendSMS (38383, "test");