访问API网站后如何重定向到我自己的页面



我想通过我的php页面发送短信。

我的

短信网关提供商给了我的 API 像"http://sms.xyz.com/uname=abc&pass=xyz&phone=1234567890&msg=hello"(在浏览器中访问此 URL 会向电话号码发送短信(

我希望我的脚本只访问此 URL(以便发送短信(并返回我自己的页面(无论结果如何(并打印"消息已发送">

请提出任何方法。

使用 cURL 发送消息并获得响应,header()重定向用户。

<?php
function send($phone, $msg)
{
    $API_URL = "http://sms.xyz.com/";
    $UNAME = "abc";
    $PASS = "xyz";
    $query = array(
        'uname'=>$UNAME,
        'pass'=>$PASS,
        'phone'=>$phone,
        'msg'=>$msg
    );
    $url = $API_URL . "?" . http_build_query($query);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url); // set the url to fetch
    curl_setopt($ch, CURLOPT_HEADER, 0); // set headers (0 = no headers in result)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // type of transfer (1 = to string)
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 4000); // time to wait in miliseconds
    $content = curl_exec($ch); // Make the call
    curl_close($ch);
    echo "Response Message == ".$content;   // Response message
}
// Now hit the function
send('9220022002', 'Hello world!');
// and redirect wherever you want
header("location:http://www.google.com");
// or
header("location:/something/anything");
// or
header("location:index.php");
exit();  // always use exit after using header('Location')

相关内容

最新更新